Skip to content

Commit

Permalink
Embedded docker (#246)
Browse files Browse the repository at this point in the history
* add caddy config

* update github build

* fx caddy runner
  • Loading branch information
younes200 authored Dec 4, 2023
1 parent cca2dd8 commit 315dbbb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 100 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ jobs:
APP=frontend
START_COMMAND=start
API_URL=/trpc
- name: Build full
uses: docker/build-push-action@v3
with:
file: Dockerfile.full
context: .
push: true
tags: ghcr.io/${{ github.repository }}/full:${{ github.event.inputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
COMMIT=${{ steps.vars.outputs.sha_short }}
API_URL=/trpc
5 changes: 5 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:80 {
reverse_proxy /trpc/* localhost:2021
reverse_proxy /admin/* localhost:9000
reverse_proxy /* localhost:3000
}
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM node:20-alpine AS custom-node

RUN apk add -f --update --no-cache --virtual .gyp nano bash libc6-compat python3 make g++ \
&& yarn global add turbo \
&& apk del .gyp
RUN apk add -f --update --no-cache --virtual .gyp nano bash libc6-compat python3 make g++ caddy \
&& yarn global add turbo pm2 \
&& apk del .gyp


FROM custom-node AS pruned
Expand All @@ -21,8 +21,8 @@ COPY --from=pruned /app/out/json/ .
COPY --from=pruned /app/out/yarn.lock /app/yarn.lock

RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn

FROM custom-node as builder
WORKDIR /app
Expand All @@ -42,8 +42,8 @@ COPY tsconfig.json tsconfig.json
RUN turbo run build --no-cache --filter=${APP}

RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn --frozen-lockfile
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn --frozen-lockfile

#############################################
FROM node:20-alpine AS runner
Expand Down
56 changes: 56 additions & 0 deletions Dockerfile.full
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM node:20-alpine AS custom-node

RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories

RUN apk add -f --update --no-cache --virtual .gyp nano bash libc6-compat python3 make g++ caddy \
&& yarn global add turbo \
&& apk del .gyp


FROM custom-node AS pruned
WORKDIR /app

COPY . .

RUN turbo prune --scope=admin --scope=frontend --scope=backend --docker

FROM custom-node AS installer
WORKDIR /app

COPY --from=pruned /app/out/json/ .
COPY --from=pruned /app/out/yarn.lock /app/yarn.lock

RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn

FROM custom-node as builder
WORKDIR /app
ARG API_URL
ARG COMMIT

ENV COMMIT=${COMMIT}
ENV API_URL=${API_URL}

COPY --from=installer --link /app .

COPY --from=pruned /app/out/full/ .
COPY turbo.json turbo.json
COPY tsconfig.json tsconfig.json

RUN turbo run build --no-cache

RUN \
--mount=type=cache,target=/usr/local/share/.cache/yarn/v6,sharing=private \
yarn --frozen-lockfile

#############################################
FROM custom-node AS runner
WORKDIR /app

COPY Caddyfile /etc/caddy/Caddyfile
COPY pm2.js /app/pm2.js

COPY --from=builder /app .

CMD ["sh", "-c", "caddy run --config /etc/caddy/Caddyfile & pm2-runtime start pm2.js"]
57 changes: 0 additions & 57 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,63 +47,6 @@ services:
networks:
- local

dbbackups:
image: kartoza/pg-backup:13.0
volumes:
- ./.backups:/backups
environment:
- DUMPPREFIX=PG
- POSTGRES_HOST=postgres
- POSTGRES_USER=POSTGRES_USER
- POSTGRES_PASS=root
- POSTGRES_PORT=5432
- DBLIST=celluloid
- ARCHIVE_FILENAME=latest
- TARGET_ARCHIVE=/backups/latest.celluloid.dmp
- TARGET_DB=celluloid
#- CRON_SCHEDULE="*/5 * * * *"
#- DB_DUMP_ENCRYPTION=true
restart: on-failure
depends_on:
postgres:
condition: service_healthy
networks:
- local


# keycloak:
# image: quay.io/phasetwo/phasetwo-keycloak:22
# # volumes:
# # - ./keycloak/realm-export.json:/opt/keycloak/data/import/realm-export.json
# command:
# - "start-dev --spi-email-template-provider=freemarker-plus-mustache --spi-email-template-freemarker-plus-mustache-enabled=true"
# # - "start-dev --import-realm"
# # - "start-dev --import-realm -Dkeycloak.profile.feature.upload_scripts=enabled"
# environment:
# KC_DB: postgres
# KC_DB_URL_HOST: postgres
# KC_DB_URL_PORT: 5432
# KC_DB_URL_DATABASE: celluloid
# KC_DB_SCHEMA: keycloak
# KC_HTTP_ENABLED: true
# KC_HOSTNAME_STRICT: false
# KC_HOSTNAME_STRICT_HTTPS: false
# KC_DB_PASSWORD: ${POSTGRES_PASSWORD}
# KC_DB_USERNAME: ${POSTGRES_USER}
# KEYCLOAK_ADMIN: ${KEYCLOAK_ADMIN}
# KEYCLOAK_ADMIN_PASSWORD: ${KEYCLOAK_PASSWORD}
# KEYCLOAK_LOGLEVEL: DEBUG
# KC_FEATURES: account3
# KC_HEALTH_ENABLED: true
# KC_METRICS_ENABLED: true
# WILDFLY_LOGLEVEL: DEBUG
# networks:
# - local
# ports:
# - 8080:8080
# depends_on:
# - postgres

redis:
image: redis:6-alpine
restart: unless-stopped
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"admin": "dotenv -- yarn workspace admin",
"backend": "dotenv -- yarn workspace backend",
"prisma": "dotenv -- yarn workspace @celluloid/prisma",
"docker-build": "DOCKER_BUILDKIT=1 docker build --build-arg APP=backend --build-arg START_COMMAND=start -t celluloid-backend:latest --cache-from=celluloid-backend:latest . "
"docker-build": "DOCKER_BUILDKIT=1 docker build --build-arg APP=backend --build-arg START_COMMAND=start -t celluloid-backend:latest --cache-from=celluloid-backend:latest . ",
"docker-build-full": "DOCKER_BUILDKIT=1 docker build -t celluloid-full:latest -f Dockerfile.full ."
},
"devDependencies": {
"@commitlint/cli": "^17.7.2",
Expand Down
19 changes: 19 additions & 0 deletions pm2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
apps: [
{
name: "frontend",
script: "yarn workspace frontend start",
watch: false,
},
{
name: "admin",
script: "yarn workspace admin start",
watch: false,
},
{
name: "backend",
script: "yarn workspace backend start",
watch: false,
},
],
};
46 changes: 11 additions & 35 deletions stack.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
version: "3.8"
name: celluloid-test-stack

x-defaults: &defaults
init: true
tty: true

volumes:
app_db_data:

services:
postgres:
<<: *defaults
image: postgres:13
ports:
- "5432:5432"
volumes:
- app_db_data:/var/lib/postgresql/data
- ./scripts/pg-init-scripts.sh:/docker-entrypoint-initdb.d/init.sh
environment:
POSTGRES_PASSWORD: postgres_password
POSTGRES_MULTIPLE_DATABASES: celluloid, keycloak
healthcheck:
test: "PGPASSWORD=${POSTGRES_PASSWORD} pg_isready -h 127.0.0.1 -U ${POSTGRES_USER} -d celluloid"

frontend:
<<: *defaults
depends_on:
- backend
ports:
- "3000:3000"
command: yarn workspace frontend start
environment:
PORT: 3000
build:
args:
NODE_ENV: production
APP: frontend
START_COMMAND: start
API_URL: http://127.0.0.1:2021
context: .
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: celluloid

backend:
<<: *defaults
celluloid:
depends_on:
- postgres
ports:
- "2021:2021"
command: ["sh", "-c", "yarn prisma migrate deploy yarn backend start"]
- "8080:80"
environment:
PORT: 2021
DATABASE_URL: postgres://postgres:root@localhost:5432/celluloid
COOKIE_SECRET: changethistosecretcookie
COOKIE_DOMAIN: 127.0.0.1
COOKIE_SECURE: false
STORAGE_URL: http://localhost:9000
STORAGE_BUCKET: celluloid
STORAGE_ACCESS_KEY: root
STORAGE_SECRET_KEY: StrongPass2022
# image: celluloid-full:latest
build:
args:
APP: backend
START_COMMAND: start
context: .
dockerfile: ./Dockerfile.full

0 comments on commit 315dbbb

Please sign in to comment.