Skip to content

Commit

Permalink
chore: docker compose for cli (#52)
Browse files Browse the repository at this point in the history
# What ❔

Docker compose file for CLI. Multi stage Docker file for App package.

## Why ❔

We need a slightly different docker compose configuration for CLI, so it
was added.
Docker file for App was changed to multi stage to make build consistent
across all packages and introduce different stages for dev and prod
envs.

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [X] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
  • Loading branch information
vasyl-ivanchuk authored and pcheremu committed Feb 15, 2024
1 parent da76623 commit 0fbca45
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ jobs:
file: packages/worker/Dockerfile
no-cache: true

- name: Build and push Docker image for App
uses: docker/build-push-action@v4
with:
push: true
tags: |
"matterlabs/block-explorer-app:latest"
"matterlabs/block-explorer-app:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"matterlabs/block-explorer-app:${{ steps.setVersionForFlux.outputs.imageTag }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:latest"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:v${{ needs.createReleaseVersion.outputs.releaseVersion }}"
"us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/block-explorer-app:${{ steps.setVersionForFlux.outputs.imageTag }}"
file: packages/app/Dockerfile
no-cache: true

deployFrontendToStaging:
name: Deploy Block Explorer frontend to staging
runs-on: ubuntu-latest
Expand Down
74 changes: 74 additions & 0 deletions docker-compose-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3.2'

services:
app:
build:
context: .
dockerfile: ./packages/app/Dockerfile
environment:
- VITE_APP_ENVIRONMENT=local
ports:
- '3010:3010'
depends_on:
- api
restart: unless-stopped

worker:
build:
context: .
dockerfile: ./packages/worker/Dockerfile
environment:
- PORT=3001
- LOG_LEVEL=verbose
- NODE_ENV=development
- DATABASE_HOST=postgres
- DATABASE_USER=postgres
- DATABASE_PASSWORD=postgres
- DATABASE_NAME=block-explorer
- BLOCKCHAIN_RPC_URL=http://host.docker.internal:3050
- BATCHES_PROCESSING_POLLING_INTERVAL=1000
ports:
- '3001:3001'
- '9229:9229'
- '9230:9230'
restart: unless-stopped

api:
build:
context: .
dockerfile: ./packages/api/Dockerfile
environment:
- PORT=3020
- METRICS_PORT=3005
- LOG_LEVEL=verbose
- NODE_ENV=development
- DATABASE_URL=postgres://postgres:postgres@postgres:5432/block-explorer
ports:
- '3020:3020'
- '3005:3005'
- '9231:9229'
- '9232:9230'
depends_on:
- worker
restart: unless-stopped

postgres:
image: "postgres:14"
logging:
driver: none
volumes:
- postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=block-explorer

volumes:
postgres:
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build:
context: .
dockerfile: ./packages/app/Dockerfile
target: development-stage
command: npm run --prefix packages/app dev -- --host
ports:
- '3010:3010'
Expand Down
31 changes: 28 additions & 3 deletions packages/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:18.17.1-alpine
ENV NODE_ENV=development
FROM node:18.17.1-alpine AS base-stage
ENV NODE_ENV=production

WORKDIR /usr/src/app
RUN apk add --update python3 make g++ && rm -rf /var/cache/apk/*
Expand All @@ -8,5 +8,30 @@ COPY --chown=node:node .npmrc .npmrc
COPY --chown=node:node lerna.json ./
COPY --chown=node:node package*.json ./
COPY --chown=node:node ./packages/app/package*.json ./packages/app/
RUN npm ci --ignore-scripts && npm cache clean --force
COPY --chown=node:node ./packages/app/. ./packages/app
RUN rm -f .npmrc

FROM base-stage AS development-stage
ENV NODE_ENV=development
COPY --chown=node:node .npmrc .npmrc
RUN npm ci
COPY --chown=node:node ./packages/app/. ./packages/app
RUN rm -f .npmrc

FROM development-stage AS build-stage
RUN npm run build

FROM base-stage AS production-stage
COPY --chown=node:node --from=build-stage /usr/src/app/packages/app/dist ./packages/app/dist
RUN npm i -g http-server

ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

ARG PORT=3010
ENV PORT $PORT

USER node
WORKDIR /usr/src/app/packages/app/dist

CMD http-server -p $PORT

0 comments on commit 0fbca45

Please sign in to comment.