From 0accd64642431ded77cbc291f42d106758b18956 Mon Sep 17 00:00:00 2001 From: Konstantinos Kopanidis Date: Fri, 26 Jan 2024 16:53:21 +0200 Subject: [PATCH] feat: standalone docker image (#919) * feat: standalone docker image * feat: standalone docker image --- .github/workflows/standalone.build.yaml | 39 ++++++++++ .github/workflows/standalone.production.yaml | 46 ++++++++++++ docker/docker-compose.standalone.yml | 79 ++++++++++++++++++++ standalone.Dockerfile | 15 ++++ standalone/ecosystem.config.js | 74 ++++++++++++++++++ 5 files changed, 253 insertions(+) create mode 100644 .github/workflows/standalone.build.yaml create mode 100644 .github/workflows/standalone.production.yaml create mode 100644 docker/docker-compose.standalone.yml create mode 100644 standalone.Dockerfile create mode 100644 standalone/ecosystem.config.js diff --git a/.github/workflows/standalone.build.yaml b/.github/workflows/standalone.build.yaml new file mode 100644 index 000000000..1478d4ca8 --- /dev/null +++ b/.github/workflows/standalone.build.yaml @@ -0,0 +1,39 @@ +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "modules/**" + - "libraries/grpc-sdk/**" + - "libraries/module-tools/**" + - "packages/module-tools/**" + +env: + REGISTRY: ghcr.io + +jobs: + deploy: + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + name: Build Conduit standalone + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build conduit base + run: | + DEV=TRUE make all + - name: Build standalone + run: | + docker build -t ghcr.io/conduitplatform/conduit-standalone:dev -f ./standalone.Dockerfile . + - name: Push image + run: | + docker push ghcr.io/conduitplatform/conduit-standalone:dev diff --git a/.github/workflows/standalone.production.yaml b/.github/workflows/standalone.production.yaml new file mode 100644 index 000000000..6f83d4525 --- /dev/null +++ b/.github/workflows/standalone.production.yaml @@ -0,0 +1,46 @@ +on: + release: + types: + - created + +env: + REGISTRY: ghcr.io + +jobs: + deploy: + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + name: Build Conduit standalone + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Log in to the Dockerhub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Set env + run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF#refs/*/} | sed 's/^v//')" >> $GITHUB_ENV + - name: Build conduit base + run: | + DEV=TRUE make all + - name: Build standalone + run: | + docker build -t ghcr.io/conduitplatform/conduit-standalone:latest -f ./standalone.Dockerfile . + - name: Push image + run: | + docker tag ghcr.io/conduitplatform/conduit-standalone:latest ghcr.io/conduitplatform/conduit-standalone:${{ env.RELEASE_VERSION }} + docker tag ghcr.io/conduitplatform/conduit-standalone:latest conduit-standalone:latest + docker tag ghcr.io/conduitplatform/conduit-standalone:latest conduit-standalone:${{ env.RELEASE_VERSION }} + docker push ghcr.io/conduitplatform/conduit-standalone:latest + docker push ghcr.io/conduitplatform/conduit-standalone:${{ env.RELEASE_VERSION }} + docker push conduit-standalone:latest + docker push conduit-standalone:${{ env.RELEASE_VERSION }} diff --git a/docker/docker-compose.standalone.yml b/docker/docker-compose.standalone.yml new file mode 100644 index 000000000..684b1cb6a --- /dev/null +++ b/docker/docker-compose.standalone.yml @@ -0,0 +1,79 @@ +# ---------------------------------------- Instructions ---------------------------------------- +# This compose file deploys a "standalone" version of conduit with most modules +# packaged in a single image. Loki and Prometheus are not deployed, since +# metrics and logs can be viewed directly from the Docker daemon. +#------------------------------------------------------------------------------------------- + +version: '3.9' +networks: + default: + name: 'conduit' +services: + # Default Services + conduit: + container_name: 'conduit' + image: 'docker.io/conduitplatform/conduit-standalone:${IMAGE_TAG}' + restart: unless-stopped + depends_on: + - redis + - mongodb + ports: + - '${CORE_GRPC_PORT:-55152}:${CORE_GRPC_PORT:-55152}' + - '${CORE_ADMIN_HTTP_PORT:-3030}:3030' + - '${CORE_ADMIN_SOCKET_PORT:-3031}:3031' + environment: + REDIS_HOST: 'conduit-redis' + REDIS_PORT: '${REDIS_PORT:-6379}' + MASTER_KEY: '${CORE_MASTER_KEY:-M4ST3RK3Y}' + ADMIN_HTTP_PORT: '${ADMIN_HTTP_PORT:-3030}' + ADMIN_SOCKET_PORT: '${ADMIN_SOCKET_PORT:-3031}' + __DEFAULT_HOST_URL: '${ADMIN_DEFAULT_HOST_URL:-http://localhost:3030}' + GRPC_KEY: '${GRPC_KEY}' + DB_CONN_URI: '${DB_CONN_URI:-mongodb://conduit:pass@conduit-mongo:27017/conduit?authSource=admin}' + networks: + default: + aliases: + - conduit + extra_hosts: + - host.docker.internal:host-gateway + + ui: + container_name: 'conduit-ui' + image: 'docker.io/conduitplatform/conduit-ui:${UI_IMAGE_TAG}' + restart: unless-stopped + ports: + - '${UI_PORT:-8080}:8080' + environment: + CONDUIT_URL: 'http://conduit:3030' + MASTER_KEY: '${CORE_MASTER_KEY:-M4ST3RK3Y}' + + # Dependencies + redis: + container_name: 'conduit-redis' + image: 'docker.io/library/redis:7.0.2' + restart: unless-stopped + ports: + - '${REDIS_PORT:-6379}:6379' + + mongodb: + container_name: 'conduit-mongo' + image: 'docker.io/library/mongo:4.4.15' + restart: unless-stopped + ports: + - '${DB_PORT:-27017}:27017' + environment: + MONGO_INITDB_DATABASE: 'conduit' + MONGO_INITDB_ROOT_USERNAME: '${DB_USER:-conduit}' + MONGO_INITDB_ROOT_PASSWORD: '${DB_PASS:-pass}' + profiles: ['mongodb'] + networks: + default: + aliases: + - conduit-mongo + volumes: + - mongo:/data/db + +# Persistent Volumes +volumes: + mongo: + external: false diff --git a/standalone.Dockerfile b/standalone.Dockerfile new file mode 100644 index 000000000..d3893ac0f --- /dev/null +++ b/standalone.Dockerfile @@ -0,0 +1,15 @@ +FROM node:iron-alpine + +WORKDIR /app + +COPY --from=conduit-base:latest /app/ /app/ + +RUN apk update && \ + apk add --no-cache --virtual .gyp python3 make g++ && \ + yarn global add pm2 && \ + yarn install --production --pure-lockfile --non-interactive && \ + yarn cache clean && \ + apk del .gyp + + +CMD ["pm2-runtime", "./standalone/ecosystem.config.js"] diff --git a/standalone/ecosystem.config.js b/standalone/ecosystem.config.js new file mode 100644 index 000000000..e4bd83ea7 --- /dev/null +++ b/standalone/ecosystem.config.js @@ -0,0 +1,74 @@ +module.exports = { + apps: [ + { + name: 'core', + script: './packages/core/dist/bin/www.js', + env: { + NODE_ENV: 'production', + }, + }, + { + name: 'database', + script: './modules/database/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55153', + SERVICE_URL: '0.0.0.0:55153', + }, + }, + { + name: 'router', + script: './modules/router/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55167', + SERVICE_URL: '0.0.0.0:55167', + }, + }, + { + name: 'authentication', + script: './modules/authentication/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55154', + SERVICE_URL: '0.0.0.0:55154', + }, + }, + { + name: 'authorization', + script: './modules/authorization/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55177', + SERVICE_URL: '0.0.0.0:55177', + }, + }, + { + name: 'email', + script: './modules/email/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55155', + SERVICE_URL: '0.0.0.0:55155', + }, + }, + { + name: 'storage', + script: './modules/storage/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55158', + SERVICE_URL: '0.0.0.0:55158', + }, + }, + { + name: 'push-notifications', + script: './modules/push-notifications/dist/index.js', + env: { + CONDUIT_SERVER: '0.0.0.0:55152', + GRPC_PORT: '55159', + SERVICE_URL: '0.0.0.0:55159', + }, + }, + ], +};