Skip to content

Commit ce43b86

Browse files
authored
Merge pull request #4067 from AlchemyCMS/bin-start-refresh-flag
chore(dev): make Docker dev rebuilds easier and uid-safe
2 parents ea3d9c2 + cdb5780 commit ce43b86

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ bin/start
5959

6060
This starts a Rails server and pnpm watch task in the dummy application for running a full dev environment.
6161

62+
After changing dependencies (`Gemfile` or `package.json`), rebuild the image and
63+
refresh the baked `node_modules` in one step:
64+
65+
```bash
66+
bin/start --refresh
67+
```
68+
6269
### Starting the Rails console
6370

6471
```bash

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ server, Sass watcher, and JS bundle watcher):
363363
$ bin/start
364364
```
365365

366+
After changing dependencies (`Gemfile` or `package.json`), rebuild the image and
367+
refresh the baked `node_modules` in one step:
368+
369+
```bash
370+
$ bin/start --refresh
371+
```
372+
366373
Or, to run the dummy app locally without Docker:
367374

368375
```bash

bin/setup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def system!(*args)
1212
end
1313

1414
FileUtils.chdir GEM_ROOT do
15+
# Docker Compose reads .env for the uid/gid baked into the image's container
16+
# user, which must match the host to write into the bind mounted workspace on
17+
# Linux. Written per machine and gitignored so any compose invocation matches.
18+
File.write(".env", "USER_ID=#{Process.uid}\nGROUP_ID=#{Process.gid}\n")
19+
1520
system! "gem install bundler --conservative"
1621
system("bundle check") || system!("bundle install")
1722
system("pnpm -v &> /dev/null") || system!("corepack enable")

bin/start

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,17 @@ USER_ID="${USER_ID:-$(id -u)}"
1313
GROUP_ID="${GROUP_ID:-$(id -g)}"
1414
export USER_ID GROUP_ID
1515

16-
exec docker compose up --build "$@"
16+
# node_modules is baked into the image but shadowed by an anonymous volume, so a
17+
# rebuilt image is not picked up until that volume is recreated. `--refresh`
18+
# renews it after changing dependencies; a plain start skips the reseed cost.
19+
renew=""
20+
args=""
21+
for arg in "$@"; do
22+
if [ "$arg" = "--refresh" ]; then
23+
renew="--renew-anon-volumes"
24+
else
25+
args="$args $arg"
26+
fi
27+
done
28+
29+
exec docker compose up --build $renew $args

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ x-app: &app
1313
# volume. node_modules sits under the bind mount, so an anonymous volume
1414
# (`- /workspace/node_modules`) shadows the host directory and surfaces the
1515
# image's copy instead of the host's (which has platform-specific binaries).
16-
# After changing dependencies, rebuild the image; refresh node_modules with
17-
# `docker compose up --build --renew-anon-volumes`.
16+
# After changing dependencies, rebuild the image and refresh node_modules with
17+
# `bin/start --refresh`.
1818
#
1919
# USER_ID/GROUP_ID select the uid/gid of the image's `alchemy` user, which has to
2020
# own the `.:/workspace` bind mount to be able to write into it. `bin/start` sets

0 commit comments

Comments
 (0)