Skip to content

Commit 9c2dfe9

Browse files
committed
Add payload image
1 parent f598741 commit 9c2dfe9

File tree

7 files changed

+196
-0
lines changed

7 files changed

+196
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Build & Publish Payload Base
3+
4+
on: # yamllint disable-line rule:truthy
5+
schedule:
6+
- cron: "0 0 1,15 * *" # Every 2 weeks
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- .github/workflows/build-and-publish-payload-base.yml
12+
- .github/workflows/internal-build-and-publish.yml
13+
- 'common/**'
14+
- 'payload-base/**'
15+
workflow_dispatch:
16+
17+
jobs:
18+
build-and-publish:
19+
uses: ./.github/workflows/internal-build-and-publish.yml
20+
strategy:
21+
matrix:
22+
info:
23+
- version: lts
24+
node: lts
25+
with:
26+
image: payload-base
27+
version: ${{ matrix.info.version }}
28+
build-args: |
29+
NODE_VERSION=${{ matrix.info.node }}

payload-base/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# --- Stage 1: Base ---
3+
#
4+
5+
ARG NODE_VERSION=lts
6+
FROM node:${NODE_VERSION}-alpine AS base
7+
8+
# Install packages
9+
# hadolint ignore=DL3018
10+
RUN apk add --no-cache \
11+
nginx \
12+
supervisor
13+
14+
# Copy configuration files
15+
# - nginx
16+
COPY common/config/nginx/ /etc/nginx/
17+
COPY payload-base/config/nginx/http.d/ /etc/nginx/http.d/
18+
# - supervisor
19+
COPY common/config/supervisor/supervisord.conf /etc/supervisor/
20+
COPY common/config/supervisor/conf.d/nginx.conf /etc/supervisor/conf.d/
21+
COPY payload-base/config/supervisor/conf.d/ /etc/supervisor/conf.d/
22+
# - init
23+
COPY common/scripts/ payload-base/scripts/ /scripts/
24+
25+
# Clean Up
26+
WORKDIR /app/www
27+
RUN chown -R nobody:nobody \
28+
/app/www \
29+
/etc/nginx/site-mods-enabled.d \
30+
/run \
31+
/var/lib/nginx \
32+
/var/log/nginx \
33+
&& addgroup nobody tty
34+
EXPOSE 8080
35+
36+
# Start supervisord by default
37+
ENTRYPOINT ["/scripts/docker-entrypoint.sh"]
38+
CMD ["serve"]
39+
40+
#
41+
# --- Variant: Default ---
42+
#
43+
44+
FROM base AS final
45+
46+
USER nobody

payload-base/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Base Payload Docker
2+
3+
🐳 Generic docker image for Payload Applications.
4+
5+
Available images:
6+
- `lts`: normal version.
7+
8+
## Commands
9+
10+
Docker will default to the `serve` command.
11+
12+
- `serve`: starts all services, such as `nginx`.
13+
- `node`: helper to execute node commands.
14+
- fallback: execute the provided command.
15+
16+
## Info
17+
18+
Serves content on port `8080`.
19+
20+
## Configuration
21+
22+
Check the [general readme](../README.md) for configuring common settings.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
server {
2+
listen 8080 default_server;
3+
listen [::]:8080 default_server;
4+
server_name _;
5+
6+
# Root path
7+
set $root /app/www/public;
8+
if (!-d /app/www/public) {
9+
set $root /app/www;
10+
}
11+
root $root;
12+
13+
# Apply cors
14+
include /etc/nginx/snippets/headers/cors.conf;
15+
16+
# Serve files (and nice URLs)
17+
location / {
18+
try_files $uri $uri/index.html $uri.html @backend;
19+
}
20+
21+
# Serve Node
22+
location @backend {
23+
include /etc/nginx/snippets/proxy/config.conf;
24+
include /etc/nginx/snippets/proxy/avoid-double-headers.conf;
25+
proxy_pass http://127.0.0.1:3000;
26+
}
27+
28+
# Load site mods
29+
include /etc/nginx/site-mods-enabled.d/*.conf;
30+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[program:payload]
2+
command=sh -c "node ./server.js || kill -s SIGQUIT $PPID"
3+
directory=%(ENV_CURRENT_WORKING_DIRECTORY)s
4+
5+
stdout_logfile=/dev/stdout
6+
stdout_logfile_maxbytes=0
7+
stderr_logfile=/dev/stderr
8+
stderr_logfile_maxbytes=0
9+
10+
autorestart=false
11+
startretries=0
12+
stopasgroup=true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
## Bootstrap
6+
7+
for script in /scripts/startup/*.sh; do
8+
$script
9+
done
10+
11+
## Commands ##
12+
13+
# Helper to serve all services
14+
if [ "$1" = 'serve' ]; then
15+
export CURRENT_WORKING_DIRECTORY=$(pwd)
16+
export HOSTNAME=0.0.0.0 PORT=3000
17+
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
18+
19+
# Helper to run workers
20+
elif [ "$1" = 'worker' ]; then
21+
shift 1;
22+
export IS_JOB=TRUE
23+
exec /usr/local/bin/node ./server.js "$@"
24+
25+
# Helper to run node commands
26+
elif [ "$1" = 'node' ]; then
27+
shift 1;
28+
exec /usr/local/bin/node "$@"
29+
30+
# Fallback: just execute given command
31+
else
32+
exec "$@"
33+
fi
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env sh
2+
3+
set -euo pipefail
4+
5+
# Move static files, so we can serve `/_next/static/…`
6+
if [ -d "/app/www/.next/static" ]; then
7+
if [ -d "/app/www/public" ]; then
8+
# Nginx root will be /app/www/public if it exists
9+
mv /app/www/.next /app/www/public/_next
10+
11+
# LEGACY: ensure `npm start` still works
12+
if [ -d "./.next" ]; then
13+
ln -s /app/www/public/_next/static ./.next/static
14+
fi
15+
else
16+
# Otherwise it'll just be /app/www
17+
mv /app/www/.next /app/www/_next
18+
19+
# LEGACY: add alias for `npm start`
20+
if [ -d "./.next" ]; then
21+
ln -s /app/www/_next/static ./.next/static
22+
fi
23+
fi
24+
fi

0 commit comments

Comments
 (0)