Skip to content

Commit

Permalink
wip: Arch, devcontainer + dist, supervisord
Browse files Browse the repository at this point in the history
Co-Authored-By: jonathan-irvin <[email protected]>
  • Loading branch information
jamesread and jonathan-irvin committed Sep 9, 2024
1 parent b233aba commit 260b281
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 28 deletions.
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Postiz Dev Container",
"image": "localhost/postiz-devcontainer",
"features": {},
"customizations": {
"vscode": {
"settings": {},
"extensions": []
}
},
"forwardPorts": ["4200:4200", "3000:3000"],
"mounts": ["source=/apps,destination=/apps/dist/,type=bind,consistency=cached"]
}

6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# We want the docker builds to be clean, and as fast as possible. Don't send
# any half-built stuff in the build context as a pre-caution (also saves copying
# 180k files in node_modules that isn't used!).
node_modules
dist
.nx
61 changes: 35 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
# Foundation image
FROM registry.fedoraproject.org/fedora-minimal:40 AS foundation
# Base image
FROM docker.io/node:20.17-alpine3.19 AS base

RUN microdnf install --nodocs --noplugins --setopt=keepcache=0 --setopt=install_weak_deps=0 -y \
npm \
node \
&& microdnf clean all
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NEXT_TELEMETRY_DISABLED=1

# Builder image
FROM foundation AS builder
RUN apk add --no-cache \
bash=5.2.21-r0 \
supervisor=4.2.5-r4

RUN mkdir /src
WORKDIR /app

COPY . /src
EXPOSE 4200
EXPOSE 3000

WORKDIR /src
RUN mkdir -p /config

RUN npx nx reset
RUN npm run build
COPY .env.example /config/.env

# Output image
FROM foundation AS dist
VOLUME /config

LABEL org.opencontainers.image.source=https://github.com/gitroomhq/postiz-app
LABEL org.opencontainers.image.title="Postiz App"

RUN mkdir -p /config /app
# Builder image
FROM base AS devcontainer

VOLUME /config
COPY nx.json tsconfig.base.json package.json package-lock.json /app/
COPY apps /app/apps/
COPY libraries /app/libraries/

COPY --from=builder /src/dist /app/dist/
COPY --from=builder /src/package.json /app/
COPY --from=builder /src/nx.json /app/
RUN npm ci --no-fund && npm run build

COPY .env.example /config/.env
COPY var/docker-entrypoint.sh /app/entrypoint.sh
COPY var/docker/entrypoint.sh /app/entrypoint.sh
COPY var/docker/supervisord/* /app/supervisord_configs/

EXPOSE 4200
EXPOSE 3000
LABEL org.opencontainers.image.title="Postiz App (DevContainer)"

WORKDIR /app
ENTRYPOINT ["/app/entrypoint.sh"]

# Output image
FROM base AS dist

COPY --from=devcontainer /app/node_modules/ /app/node_modules/
COPY --from=devcontainer /app/dist/ /app/dist/

COPY package.json nx.json /app/
COPY var/docker/entrypoint.sh /app/entrypoint.sh

## Labels at the bottom, because CI will eventially add dates, commit hashes, etc.
LABEL org.opencontainers.image.title="Postiz App (Production)"

ENTRYPOINT ["/app/entrypoint.sh"]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"prisma-generate": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma generate",
"prisma-db-push": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma db push",
"prisma-reset": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma db push --force-reset && npx prisma db push",
"docker-build": "docker rmi localhost/postiz || true && docker build -t localhost/postiz . ",
"docker-create": "docker kill postiz || true && docker rm postiz || true && docker create --name postiz -p 3000:3000 -p 4200:4200 localhost/postiz",
"docker-build": "docker rmi localhost/postiz || true && docker build --target dist -t localhost/postiz -f Dockerfile . && docker build --target devcontainer -t localhost/postiz-devcontainer -f Dockerfile .",
"docker-create": "docker kill postiz || true && docker rm postiz || true && docker create --name postiz -p 3000:3000 -p 4200:4200 localhost/postiz",
"postinstall": "npm run prisma-generate"
},
"private": true,
Expand Down
36 changes: 36 additions & 0 deletions var/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

if [[ "$SKIP_CONFIG_CHECK" -ne "true" ]]; then
if [ ! -f /config/.env ]; then
echo "ERROR: No .env file found in /config/.env"
fi

ln -s /config/env /app/.env
fi

if [[ "$POSTIZ_APPS" -eq "" ]]; then
echo "POSTIZ_APPS is not set, starting everything!"
POSTIZ_APPS="frontend workers cron"
fi

mkdir -p /etc/supervisor.d/

cp /app/supervisord_configs/base.conf /etc/supervisor.d/

if [[ "$POSTIZ_APPS" == *"frontend"* ]]; then
cp /app/supervisord_configs/frontend.conf /etc/supervisor.d/
fi

if [[ $POSTIZ_APPS == *"workers"* ]]; then
cp /app/supervisord_configs/workers.conf /etc/supervisor.d/
fi

if [[ $POSTIZ_APPS == *"cron"* ]]; then
cp /app/supervisord_configs/cron.conf /etc/supervisor.d/
fi

if [[ $POSTIZ_APPS == *"backend"* ]]; then
cp /app/supervisord_configs/backend.conf /etc/supervisor.d/
fi

/usr/bin/supervisord
5 changes: 5 additions & 0 deletions var/docker/supervisord/backend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[program:backend]
directory=/app
command=npm run start:prod
autostart=true
autorestart=false
6 changes: 6 additions & 0 deletions var/docker/supervisord/base.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[supervisord]
nodaemon=true
logfile=/dev/null
logfile_maxbytes=0


5 changes: 5 additions & 0 deletions var/docker/supervisord/cron.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[program:cron]
directory=/app
command=npm run start:prod:cron
autostart=true
autorestart=false
5 changes: 5 additions & 0 deletions var/docker/supervisord/frontend.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[program:frontend]
directory=/app
command=npm run start:prod:frontend
autostart=true
autorestart=false
5 changes: 5 additions & 0 deletions var/docker/supervisord/workers.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[program:workers]
directory=/app
command=npm run start:prod:workers
autostart=true
autorestart=false

0 comments on commit 260b281

Please sign in to comment.