Skip to content

Commit 95cb7d6

Browse files
committed
feat: ensure that .gitignored files are correctly gitignored
1 parent 2c8d28b commit 95cb7d6

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

.gitignore.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Local, per-developer devcontainer files — seeded from samples by
2+
# bin/host-bootstrap.sh on container create, so they don't need to be committed.
3+
.env
4+
docker-compose.local.yml

bin/host-bootstrap.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Host-side devcontainer bootstrap, run from initializeCommand BEFORE the
4+
# container is created. Seeds the per-project files the compose stack needs
5+
# from the submodule's samples on first run.
6+
#
7+
# This lives in a script (rather than as parallel initializeCommand keys)
8+
# because the samples live inside the submodule: the copies must run AFTER the
9+
# submodule is checked out. initializeCommand inits the submodule first, then
10+
# invokes this, keeping the ordering deterministic instead of racing.
11+
12+
set -e
13+
14+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
15+
SUBMODULE_DIR="$(dirname "$SCRIPT_DIR")" # .devcontainer/magento2-devcontainer
16+
DEVCONTAINER_DIR="$(dirname "$SUBMODULE_DIR")" # .devcontainer
17+
18+
# .env and docker-compose.local.yml are gitignored / per-project, and
19+
# docker-compose.local.yml is referenced by dockerComposeFile — so the
20+
# container won't build without them. Seed from samples if missing.
21+
[ -f "$DEVCONTAINER_DIR/.env" ] \
22+
|| cp "$SUBMODULE_DIR/.env.sample" "$DEVCONTAINER_DIR/.env"
23+
[ -f "$DEVCONTAINER_DIR/docker-compose.local.yml" ] \
24+
|| cp "$SUBMODULE_DIR/docker-compose.local.yml.sample" "$DEVCONTAINER_DIR/docker-compose.local.yml"

bin/init.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ cp "$DEVCONTAINER_FOLDER/docker-compose.shared.yml.sample" "$TARGET_DIR/docker-c
113113
cp "$DEVCONTAINER_FOLDER/docker-compose.local.yml.sample" "$TARGET_DIR/docker-compose.local.yml"
114114
echo "services: {}" > "$TARGET_DIR/docker-compose.yml"
115115

116+
## Copy the .gitignore so the per-developer local files (.env,
117+
## docker-compose.local.yml) that host-bootstrap.sh re-seeds aren't committed.
118+
cp "$DEVCONTAINER_FOLDER/.gitignore.sample" "$TARGET_DIR/.gitignore"
119+
116120
## Copy over devcontainer and set the name and compose key.
117121
## Every compose key is <distribution>/<version> so a single alternation
118122
## covers magento, mage-os, and mage-os-minimal. Uses `#` as the s-delimiter

devcontainer.json.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
8000,
1313
8025
1414
],
15-
"initializeCommand": "[ -f .devcontainer/magento2-devcontainer/.gitignore ] || (git submodule update --init --recursive)",
15+
"initializeCommand": "[ -f .devcontainer/magento2-devcontainer/.gitignore ] || git submodule update --init --recursive; .devcontainer/magento2-devcontainer/bin/host-bootstrap.sh",
1616
"postStartCommand": ".devcontainer/magento2-devcontainer/bin/forward-ports.sh",
1717
"portsAttributes": {
1818
"8000": {

0 commit comments

Comments
 (0)