From 66d585a16d63631f64421dc3a39c290a6308a060 Mon Sep 17 00:00:00 2001 From: Joe Caputo Date: Thu, 18 Apr 2024 08:59:53 -0400 Subject: [PATCH] fix: updates to Docker images for consistency across Gateway services (#91) * fix: updates to Docker images for consistency across Gateway services - updated CMD to ENTRYPOINT - eliminated build stage from dev.Dockerfile - added '--watch' parameter for use with dev Docker image/docker-compose - Gave dev docker-compose services an image name so that the 2 app services can share a local image * fix: add comments and platform to docker-compose file --- .github/workflows/release.yml | 3 +-- .tool-versions | 2 +- Dockerfile | 11 ++++++----- apps/worker/src/main.ts | 2 +- dev.Dockerfile | 11 +++++++---- docker-compose.dev.yaml | 25 ++++++++++++++++++++----- package.json | 4 +++- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 851b279..4f76527 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -51,7 +51,6 @@ jobs: with: flavor: | latest=auto - prefix=api-,onlatest=true images: | ${{env.DOCKER_HUB_PROFILE}}/${{env.IMAGE_NAME}} tags: | @@ -75,4 +74,4 @@ jobs: platforms: linux/amd64 push: ${{env.TEST_RUN != 'true'}} file: ./Dockerfile - tags: ${{ steps.cp-tags.outputs.tags }} \ No newline at end of file + tags: ${{ steps.cp-tags.outputs.tags }} diff --git a/.tool-versions b/.tool-versions index 8ead549..958fb36 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -nodejs 18.16.0 +nodejs 20.12.2 diff --git a/Dockerfile b/Dockerfile index 9c3373e..f22c054 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use a multi-stage build for efficiency -FROM node:18 AS builder +FROM node:20 AS builder WORKDIR /usr/src/app @@ -13,17 +13,18 @@ COPY . . RUN npm run build # Production stage -FROM node:18 +FROM node:20 WORKDIR /usr/src/app COPY --from=builder /usr/src/app/dist ./dist COPY package*.json ./ - COPY ./lua ./lua + RUN npm install --only=production + EXPOSE 3000 -ENV START_PROCESS="api" +ENV START_PROCESS="api" -CMD ["sh", "-c", "if [ \"$START_PROCESS\" = \"api\" ]; then npm run start:api:prod; else npm run start:worker:prod; fi"] +ENTRYPOINT ["npm", "run", "start:${START_PROCESS}:prod"] diff --git a/apps/worker/src/main.ts b/apps/worker/src/main.ts index a821ecf..a99a8ec 100644 --- a/apps/worker/src/main.ts +++ b/apps/worker/src/main.ts @@ -5,4 +5,4 @@ async function bootstrap() { const app = await NestFactory.createApplicationContext(WorkerModule); app.enableShutdownHooks(); } -bootstrap(); +bootstrap().catch((error) => console.error(error)); diff --git a/dev.Dockerfile b/dev.Dockerfile index 99fcb10..d5204f1 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -1,10 +1,13 @@ -FROM node:18 +FROM node:20 WORKDIR /app -COPY . . -RUN npm install +# COPY . . + +# RUN npm install + EXPOSE 3000 + ENV START_PROCESS="api" -CMD ["sh", "-c", "if [ \"$START_PROCESS\" = \"api\" ]; then npm run start:api; else npm run start:worker; fi"] +ENTRYPOINT npm run start:${START_PROCESS}:watch diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 59231f6..c014cf4 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -11,7 +11,18 @@ services: - content-publishing-service frequency: - image: frequencychain/instant-seal-node:latest + image: dsnp/instant-seal-node-with-deployed-schemas:latest + # We need to specify the platform because it's the only image + # built by Frequency at the moment, and auto-pull won't work otherwise + platform: linux/amd64 + # Uncomment SEALING_MODE and SEALING_INTERVAL if you want to use interval sealing. + # Other options you may want to add depending on your test scenario. + # environment: + # - SEALING_MODE=interval + # - SEALING_INTERVAL=3 + # - CREATE_EMPTY_BLOCKS=true + # Uncomment below if you want to let the chain run and keep all of the historical blocks + # command: --state-pruning=archive ports: - 9944:9944 networks: @@ -31,16 +42,19 @@ services: - ipfs_data:/data/ipfs content-publishing-service-api: + pull_policy: never + image: content-publishing-service build: context: . dockerfile: dev.Dockerfile + tags: + - content-publishing-service:latest ports: - 3000:3000 env_file: - .env.docker.dev environment: - START_PROCESS=api - - REDIS_URL=redis://redis:6379 volumes: - ./:/app depends_on: @@ -51,14 +65,17 @@ services: - content-publishing-service content-publishing-service-worker: + pull_policy: never + image: content-publishing-service build: context: . dockerfile: dev.Dockerfile + tags: + - content-publishing-service:latest env_file: - .env.docker.dev environment: - START_PROCESS=worker - - REDIS_URL=redis://redis:6379 volumes: - ./:/app depends_on: @@ -75,5 +92,3 @@ volumes: networks: content-publishing-service: - - diff --git a/package.json b/package.json index 2652753..04b7583 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,10 @@ "generate-swagger-ui": "redoc-cli bundle swagger.yaml --output=./docs/index.html", "format": "prettier --write \"apps/**/*.ts\" \"libs/**/*.ts\"", "start:api": "nest start api", - "start:api:prod": "node dist/apps/api/main.js", + "start:api:watch": "nest start api --watch", + "start:api:prod": "node dist/apps/api/main.js", "start:worker": "nest start worker", + "start:worker:watch": "nest start worker --watch", "start:worker:prod": "node dist/apps/worker/main.js", "start:api:dev": "set -a ; . .env ; nest start api", "start:worker:dev": "set -a ; . .env ; nest start worker",