-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from jamesread/dockerfile
feat: add dockerfile for production and developer use
- Loading branch information
Showing
13 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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 | ||
.devcontainer | ||
.git | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
name: "Build Tag" | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
build-tag: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Login to ghcr | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ github.token }} | ||
|
||
- name: docker build | ||
run: /var/run/docker-build.sh | ||
|
||
- name: docker tag | ||
run: | | ||
docker tag localhost/postiz ghcr.io/githubhq/postiz-app:${{ GITHUB_REF_NAME }} | ||
docker push ghcr.io/githubhq/postiz-app:${{ GITHUB_REF_NAME }} | ||
docker tag localhost/postiz-devcontainer ghcr.io/githubhq/postiz-app:${{ GITHUB_REF_NAME }} | ||
docker push ghcr.io/githubhq/postiz-devcontainer:${{ GITHUB_REF_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# This Dockerfile is used for producing 3 container images. | ||
# | ||
# base - which is thrown away, that contains node and the basic infrastructure. | ||
# devcontainer - which is used for development, and contains the source code and the node_modules. | ||
# dist - which is used for production, and contains the built source code and the node_modules. | ||
|
||
ARG NODE_VERSION="20.17" | ||
|
||
# Base image | ||
FROM docker.io/node:${NODE_VERSION}-alpine3.19 AS base | ||
|
||
## Just reduce unccessary noise in the logs. | ||
ENV NPM_CONFIG_UPDATE_NOTIFIER=false | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
RUN apk add --no-cache \ | ||
bash=5.2.21-r0 \ | ||
supervisor=4.2.5-r4 \ | ||
make \ | ||
build-base | ||
|
||
WORKDIR /app | ||
|
||
EXPOSE 4200 | ||
EXPOSE 3000 | ||
|
||
COPY var/docker/entrypoint.sh /app/entrypoint.sh | ||
COPY var/docker/supervisord.conf /etc/supervisord.conf | ||
COPY var/docker/supervisord /app/supervisord_available_configs/ | ||
COPY .env.example /config/.env | ||
|
||
VOLUME /config | ||
|
||
LABEL org.opencontainers.image.source=https://github.com/gitroomhq/postiz-app | ||
|
||
ENTRYPOINT ["/app/entrypoint.sh"] | ||
|
||
# Builder image | ||
FROM base AS devcontainer | ||
|
||
COPY nx.json tsconfig.base.json package.json package-lock.json /app/ | ||
COPY apps /app/apps/ | ||
COPY libraries /app/libraries/ | ||
|
||
RUN npm ci --no-fund && npx nx run-many --target=build --projects=frontend,backend,workers,cron | ||
|
||
LABEL org.opencontainers.image.title="Postiz App (DevContainer)" | ||
|
||
# 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/ | ||
|
||
## Labels at the bottom, because CI will eventually add dates, commit hashes, etc. | ||
LABEL org.opencontainers.image.title="Postiz App (Production)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
docker rmi localhost/postiz || true | ||
docker build --target dist -t localhost/postiz -f Dockerfile . | ||
docker build --target devcontainer -t localhost/postiz-devcontainer -f Dockerfile . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
docker kill postiz || true | ||
docker rm postiz || true | ||
docker create --name postiz -p 3000:3000 -p 4200:4200 localhost/postiz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
if [[ "$SKIP_CONFIG_CHECK" != "true" ]]; then | ||
echo "symlinking /config/.env into /app/.env" | ||
|
||
if [ ! -f /config/.env ]; then | ||
echo "ERROR: No .env file found in /config/.env" | ||
fi | ||
|
||
ln -sf /config/.env /app/.env | ||
fi | ||
|
||
if [[ "$POSTIZ_APPS" -eq "" ]]; then | ||
echo "POSTIZ_APPS is not set, starting everything!" | ||
POSTIZ_APPS="frontend workers cron backend" | ||
fi | ||
|
||
mkdir -p /etc/supervisor.d/ | ||
|
||
if [[ "$POSTIZ_APPS" == *"frontend"* ]]; then | ||
ln -sf /app/supervisord_available_configs/frontend.conf /etc/supervisor.d/ | ||
fi | ||
|
||
if [[ $POSTIZ_APPS == *"workers"* ]]; then | ||
ln -sf /app/supervisord_available_configs/workers.conf /etc/supervisor.d/ | ||
fi | ||
|
||
if [[ $POSTIZ_APPS == *"cron"* ]]; then | ||
ln -sf /app/supervisord_available_configs/cron.conf /etc/supervisor.d/ | ||
fi | ||
|
||
if [[ $POSTIZ_APPS == *"backend"* ]]; then | ||
ln -sf /app/supervisord_available_configs/backend.conf /etc/supervisor.d/ | ||
fi | ||
|
||
/usr/bin/supervisord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[supervisord] | ||
nodaemon=true | ||
logfile=/dev/null | ||
logfile_maxbytes=0 | ||
|
||
[unix_http_server] | ||
file=/run/supervisord.sock | ||
|
||
[include] | ||
files = /etc/supervisor.d/*.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[program:backend] | ||
directory=/app | ||
command=npm run start:prod | ||
autostart=true | ||
autorestart=false | ||
redirect_stderr=true | ||
stdout_logfile=/dev/fd/1 | ||
stdout_logfile_maxbytes=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[program:cron] | ||
directory=/app | ||
command=npm run start:prod:cron | ||
autostart=true | ||
autorestart=false | ||
redirect_stderr=true | ||
stdout_logfile=/dev/fd/1 | ||
stdout_logfile_maxbytes=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[program:frontend] | ||
directory=/app | ||
command=npm run start:prod:frontend | ||
autostart=true | ||
autorestart=false | ||
redirect_stderr=true | ||
stdout_logfile=/dev/fd/1 | ||
stdout_logfile_maxbytes=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[program:workers] | ||
directory=/app | ||
command=npm run start:prod:workers | ||
autostart=true | ||
autorestart=false | ||
redirect_stderr=true | ||
stdout_logfile=/dev/fd/1 | ||
stdout_logfile_maxbytes=0 |