Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: bash shell for production docker builds #6469

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ WORKDIR /usr/src/

ADD package.json /usr/src/

ADD yarn.lock /usr/src/

COPY .yarn /usr/src/.yarn

ADD .yarnrc /usr/src/
Expand All @@ -40,6 +38,8 @@ ADD lerna.json /usr/src/

COPY ./packages /usr/src/packages

ADD yarn.lock /usr/src/
Copy link
Contributor Author

@eatyourgreens eatyourgreens Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn.lock changes quite frequently, so should be added to the image after all other files.


RUN chown -R node:node .

USER node
Expand All @@ -64,16 +64,16 @@ RUN mkdir -p /usr/src

WORKDIR /usr/src/

ADD package.json /usr/src/

ADD yarn.lock /usr/src/
COPY --from=builder /usr/src/package.json /usr/src/package.json

COPY .yarn /usr/src/.yarn
COPY --from=builder /usr/src/.yarn /usr/src/.yarn

ADD .yarnrc /usr/src/
COPY --from=builder /usr/src/.yarnrc /usr/src/.yarnrc

COPY --from=builder /usr/src/packages ./packages

COPY --from=builder /usr/src/yarn.lock /usr/src/yarn.lock

Comment on lines +67 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything that the production runner uses should be copied from the builder image.

RUN --mount=type=cache,id=fem-runner-yarn,uid=1000,gid=1000,target=/home/node/.yarn YARN_CACHE_FOLDER=/home/node/.yarn yarn install --production --frozen-lockfile --ignore-scripts --prefer-offline

RUN rm -rf /usr/src/packages/lib-react-components/src
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ docker compose build
docker compose up -d
# shut down the running containers when you're finished
docker compose down
# run this if you need a shell inside the running container
docker compose run --rm shell
# run this if you need a shell inside the dev container
docker compose run --rm dev-shell
# run this for a shell inside the production container
docker compose run --rm prod-shell
```

You can supply a service name (from `docker-compose.yml`) to `docker compose` if you only want to run a single service eg.
Expand Down
21 changes: 17 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
services:
shell:
prod-shell:
image: front-end-monorepo_prod:latest
volumes:
- node_modules-prod:/usr/src/node_modules
build:
context: ./
args:
- NODE_ENV=production
- PANOPTES_ENV=production
- NEXT_TELEMETRY_DISABLED=1
- APP_ENV=development
command:
- "/bin/sh"
dev-shell:
image: front-end-monorepo_dev:latest
volumes:
- node_modules:/usr/src/node_modules
Copy link
Contributor Author

@eatyourgreens eatyourgreens Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this to make it easier to debug the node package installs. Otherwise, you're just looking at the node_modules directory from your local machine. I'm going to avoid changes to existing services here. Just add a new service for the production bash shell, and rename the existing service (and volume.)

- node_modules-dev:/usr/src/node_modules
build:
context: ./
target: builder
Expand Down Expand Up @@ -46,6 +59,6 @@ services:
- PORT=3000
ports:
- "3003:3000"

volumes:
node_modules:
node_modules-dev:
node_modules-prod:
4 changes: 4 additions & 0 deletions packages/app-project/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
- ./pages:/usr/src/packages/app-project/pages
- ./src:/usr/src/packages/app-project/src
- ./stores:/usr/src/packages/app-project/stores
- node_modules-dev:/usr/src/node_modules
storybook:
image: front-end-monorepo_dev:latest
entrypoint:
Expand All @@ -34,3 +35,6 @@ services:
- ./pages:/usr/src/packages/app-project/pages
- ./src:/usr/src/packages/app-project/src
- ./stores:/usr/src/packages/app-project/stores
- node_modules-dev:/usr/src/node_modules
volumes:
node_modules-dev:
2 changes: 1 addition & 1 deletion packages/app-root/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker compose up -d
# stop the local services when you're finished
docker compose down
# run the tests
docker compose run --rm project test
docker compose run --rm root test
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo. The Next.js app service is called root in docker-compose.yml.

```

### Node
Expand Down