From 0a69cc4ce305c138f73e5e8b641a7414b526e535 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Thu, 14 Nov 2024 10:05:19 +0000 Subject: [PATCH 1/4] build: docker instructions and fixes - replace the outdated `docker-compose` command with `docker compose` in the READMEs. - fix `AS` in Dockerfile. - update the Docker instructions in the READMEs. - make sure that environment variables are set for local development in the `docker-compose.yml` files. --- Dockerfile | 4 ++-- README.md | 27 ++++++++++++++++--------- docker-compose.yml | 2 ++ packages/app-project/README.md | 6 +++--- packages/app-project/docker-compose.yml | 7 +++++++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 198f715014..32f527ef1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine as builder +FROM node:20-alpine AS builder ARG COMMIT_ID ENV COMMIT_ID=$COMMIT_ID @@ -55,7 +55,7 @@ RUN --mount=type=cache,id=fem-builder-yarn,uid=1000,gid=1000,target=/home/node/. RUN echo $COMMIT_ID > /usr/src/packages/app-root/public/commit_id.txt RUN --mount=type=cache,id=fem-builder-yarn,uid=1000,gid=1000,target=/home/node/.yarn YARN_CACHE_FOLDER=/home/node/.yarn yarn workspace @zooniverse/fe-root build -FROM node:20-alpine as runner +FROM node:20-alpine AS runner ARG NODE_ENV=production ENV NODE_ENV=$NODE_ENV diff --git a/README.md b/README.md index e3924f2c9c..39fb95c036 100644 --- a/README.md +++ b/README.md @@ -70,17 +70,24 @@ You can run the code locally in Docker, which avoids needing to install Node or ```sh git clone git@github.com:zooniverse/front-end-monorepo.git cd front-end-monorepo -docker-compose build +docker compose build +# run all services in the background +# app-project at http://localhost:3002/projects/[owner]/[project-name] +# app-root at http://localhost:3003 +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 ``` -`docker-compose up` runs local production builds as follows: - -- project app at http://localhost:3002 -- root app at http://localhost:3003 - -`docker-compose down` stops the running container. - -`docker-compose run --rm shell` runs an interactive shell on the Docker image. +You can supply a service name (from `docker-compose.yml`) to `docker compose` if you only want to run a single service eg. +```sh +# only build the project app +docker compose build fe-project +# only run the project app +docker compose up -d fe-project +``` Development environments for individual packages can be run from the package directories. For example: @@ -89,7 +96,7 @@ cd packages/app-project docker-compose up ``` -to run a development server for the project app. +to run a development server for the project app. See the READMEs for individual packages for detailed instructions. ### With Node and yarn diff --git a/docker-compose.yml b/docker-compose.yml index 29c3165558..b9c50f2051 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,8 @@ services: build: context: ./ target: builder + args: + - APP_ENV=development command: - "/bin/sh" fe-project: diff --git a/packages/app-project/README.md b/packages/app-project/README.md index 6b46e45f2b..ab22ba66f3 100644 --- a/packages/app-project/README.md +++ b/packages/app-project/README.md @@ -19,9 +19,9 @@ Once you have the hosts file configured, you'll be able to use one of those subd ### Docker -- `docker-compose up -d` to run a dev server, in the background, on http://localhost:3000 and the storybook on http://localhost:9001 using `yarn dev` and `yarn storybook` respectively. The `--build` flag can be used to build the container. This builds and runs a local image which matches the Jenkins build except for running behind a proxy. Note: `devcert` is not yet setup for our docker build for local development. -- `docker-compose down` to stop the dev containers. -- `docker-compose run --rm project test` to run the tests. +- `docker compose up -d` to run a dev server, in the background, on https://localhost:3000 and the storybook on http://localhost:9001 using `yarn dev` and `yarn storybook` respectively. The `--build` flag can be used to build the container. This builds and runs a local image which matches the Jenkins build except for running behind a proxy. Note: `devcert` is not yet setup for our docker build for local development. +- `docker compose down` to stop the dev containers. +- `docker compose run --rm project test` to run the tests. ### Node ```sh diff --git a/packages/app-project/docker-compose.yml b/packages/app-project/docker-compose.yml index 4e4926a283..4bd1d551a5 100644 --- a/packages/app-project/docker-compose.yml +++ b/packages/app-project/docker-compose.yml @@ -3,8 +3,15 @@ version: '3.7' services: project: image: front-end-monorepo_dev:latest + environment: + PANOPTES_ENV: staging + APP_ENV: development build: context: ../../ + target: builder + args: + - NEXT_TELEMETRY_DISABLED=1 + - APP_ENV=development entrypoint: - "yarn" - "workspace" From 3ab9772f94010957f990cd412f21bbf5c636b4b1 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Thu, 14 Nov 2024 10:28:26 +0000 Subject: [PATCH 2/4] update the project README --- packages/app-project/README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/app-project/README.md b/packages/app-project/README.md index ab22ba66f3..18085d1cd7 100644 --- a/packages/app-project/README.md +++ b/packages/app-project/README.md @@ -19,9 +19,18 @@ Once you have the hosts file configured, you'll be able to use one of those subd ### Docker -- `docker compose up -d` to run a dev server, in the background, on https://localhost:3000 and the storybook on http://localhost:9001 using `yarn dev` and `yarn storybook` respectively. The `--build` flag can be used to build the container. This builds and runs a local image which matches the Jenkins build except for running behind a proxy. Note: `devcert` is not yet setup for our docker build for local development. -- `docker compose down` to stop the dev containers. -- `docker compose run --rm project test` to run the tests. +```sh +# run a development build using the top-level Dockerfile +docker compose build +# run a dev server on port 3000 (with HTTPS) and a storybook on port 9001. +# eg. https://localhost:3000/projects/nora-dot-eisner/planet-hunters-tess +# http://localhost:9001 +docker compose up -d +# stop the local services when you're finished +docker compose down +# run the tests +docker compose run --rm project test +``` ### Node ```sh From d6594c7a68673b9dbc336dba19c0ca985a4fd4da Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Thu, 14 Nov 2024 13:38:46 +0000 Subject: [PATCH 3/4] Reove obsolete version field --- docker-compose.yml | 2 -- packages/app-project/docker-compose.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b9c50f2051..215299ca0d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: shell: image: front-end-monorepo_dev:latest diff --git a/packages/app-project/docker-compose.yml b/packages/app-project/docker-compose.yml index 4bd1d551a5..1e839ed7d8 100644 --- a/packages/app-project/docker-compose.yml +++ b/packages/app-project/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.7' - services: project: image: front-end-monorepo_dev:latest From 6da098e2a91ad00b77c82d4167fd33a000b26413 Mon Sep 17 00:00:00 2001 From: Delilah <23665803+goplayoutside3@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:09:21 -0600 Subject: [PATCH 4/4] update app-root's readme and docker-compose.yml --- README.md | 3 ++- packages/app-project/README.md | 2 +- packages/app-root/README.md | 14 +++++++++++--- packages/app-root/docker-compose.yml | 9 +++++++-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 39fb95c036..4e67b60073 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,9 @@ You can run the code locally in Docker, which avoids needing to install Node or ```sh git clone git@github.com:zooniverse/front-end-monorepo.git cd front-end-monorepo +# build first docker compose build -# run all services in the background +# run all services in the background (no authentication available) # app-project at http://localhost:3002/projects/[owner]/[project-name] # app-root at http://localhost:3003 docker compose up -d diff --git a/packages/app-project/README.md b/packages/app-project/README.md index 18085d1cd7..0a8d92ed21 100644 --- a/packages/app-project/README.md +++ b/packages/app-project/README.md @@ -22,7 +22,7 @@ Once you have the hosts file configured, you'll be able to use one of those subd ```sh # run a development build using the top-level Dockerfile docker compose build -# run a dev server on port 3000 (with HTTPS) and a storybook on port 9001. +# run a dev server on port 3000 (with HTTPS, but no authentication) and a storybook on port 9001. # eg. https://localhost:3000/projects/nora-dot-eisner/planet-hunters-tess # http://localhost:9001 docker compose up -d diff --git a/packages/app-root/README.md b/packages/app-root/README.md index afc2a5aaac..116ce6cace 100644 --- a/packages/app-root/README.md +++ b/packages/app-root/README.md @@ -18,9 +18,17 @@ To view data from Contentful, you'll need to create a `.env` file containing the ### Docker -- `docker-compose up -d` to run a dev server, in the background, on http://localhost:3000 using `yarn dev`. The `--build` flag can be used to build the container. This builds and runs a local image which matches the GitHub Action build except for running behind a proxy. Note: `devcert` is not yet setup for our docker build for local development. -- `docker-compose down` to stop the dev containers. - +```sh +# run a development build using the top-level Dockerfile +docker compose build +# run a dev server on port 3000 (with HTTPS, but no authentication). +# eg. https://localhost:3000/about +docker compose up -d +# stop the local services when you're finished +docker compose down +# run the tests +docker compose run --rm project test +``` ### Node diff --git a/packages/app-root/docker-compose.yml b/packages/app-root/docker-compose.yml index ebfe521ef6..244319b969 100644 --- a/packages/app-root/docker-compose.yml +++ b/packages/app-root/docker-compose.yml @@ -1,10 +1,15 @@ -version: '3.7' - services: root: image: front-end-monorepo_dev:latest + environment: + PANOPTES_ENV: staging + APP_ENV: development build: context: ../../ + target: builder + args: + - NEXT_TELEMETRY_DISABLED=1 + - APP_ENV=development entrypoint: - "yarn" - "workspace"