Skip to content

Commit 01dd81c

Browse files
committed
chore(repo): add docker smoke tests
1 parent 7c1bbf4 commit 01dd81c

7 files changed

Lines changed: 865 additions & 6 deletions

File tree

.github/workflows/docker-smoke.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Docker build and smoke test for apps
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches: ["preview"]
7+
paths:
8+
- "apps/web/**"
9+
- "apps/space/**"
10+
- "apps/admin/**"
11+
- "apps/live/**"
12+
- "packages/**"
13+
- "turbo.json"
14+
- "pnpm-lock.yaml"
15+
- "pnpm-workspace.yaml"
16+
- ".github/workflows/docker-smoke.yml"
17+
push:
18+
branches: ["preview"]
19+
paths:
20+
- "apps/web/**"
21+
- "apps/space/**"
22+
- "apps/admin/**"
23+
- "apps/live/**"
24+
- "packages/**"
25+
- "turbo.json"
26+
- "pnpm-lock.yaml"
27+
- "pnpm-workspace.yaml"
28+
- ".github/workflows/docker-smoke.yml"
29+
30+
permissions:
31+
contents: read
32+
33+
concurrency:
34+
group: docker-smoke-${{ github.workflow }}-${{ github.ref }}
35+
cancel-in-progress: true
36+
37+
jobs:
38+
determine-matrix:
39+
name: Determine matrix
40+
runs-on: ubuntu-latest
41+
outputs:
42+
matrix: ${{ steps.build-matrix.outputs.matrix }}
43+
has_targets: ${{ steps.build-matrix.outputs.has_targets }}
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Detect changed paths
51+
id: changes
52+
uses: dorny/paths-filter@v3
53+
with:
54+
filters: |
55+
web:
56+
- 'apps/web/**'
57+
space:
58+
- 'apps/space/**'
59+
admin:
60+
- 'apps/admin/**'
61+
live:
62+
- 'apps/live/**'
63+
common:
64+
- 'turbo.json'
65+
- 'pnpm-lock.yaml'
66+
- 'pnpm-workspace.yaml'
67+
- '.github/workflows/docker-smoke.yml'
68+
- 'packages/**'
69+
70+
- name: Build matrix
71+
id: build-matrix
72+
uses: actions/github-script@v7
73+
with:
74+
script: |
75+
const include = [];
76+
const eventName = context.eventName;
77+
const anyCommon = '${{ steps.changes.outputs.common }}' === 'true';
78+
const changed = {
79+
web: '${{ steps.changes.outputs.web }}' === 'true',
80+
space: '${{ steps.changes.outputs.space }}' === 'true',
81+
admin: '${{ steps.changes.outputs.admin }}' === 'true',
82+
live: '${{ steps.changes.outputs.live }}' === 'true',
83+
};
84+
const add = (name, dockerfile, image, container, port, path, env_flags = "") => include.push({ name, dockerfile, image, container, host_port: port, path, env_flags });
85+
const buildAll = anyCommon || eventName === 'push' || eventName === 'workflow_dispatch';
86+
if (buildAll || changed.web) add('web', 'apps/web/Dockerfile.web', 'plane-web:ci-smoke', 'plane-web-ci', 3001, '/');
87+
if (buildAll || changed.space) add('space', 'apps/space/Dockerfile.space', 'plane-space:ci-smoke', 'plane-space-ci', 3002, '/spaces');
88+
if (buildAll || changed.admin) add('admin', 'apps/admin/Dockerfile.admin', 'plane-admin:ci-smoke', 'plane-admin-ci', 3003, '/god-mode');
89+
if (buildAll || changed.live) add('live', 'apps/live/Dockerfile.live', 'plane-live:ci-smoke', 'plane-live-ci', 3004, '/live/health', '-e NODE_ENV=production -e LIVE_BASE_PATH=/live');
90+
const hasTargets = include.length > 0;
91+
if (!hasTargets) {
92+
core.warning('No changes detected for any app. Matrix is empty. Skipping smoke tests.');
93+
}
94+
core.setOutput('matrix', JSON.stringify({ include }));
95+
core.setOutput('has_targets', String(hasTargets));
96+
smoke:
97+
name: Build and smoke test ${{ matrix.name }}
98+
runs-on: ubuntu-latest
99+
needs: determine-matrix
100+
if: ${{ needs.determine-matrix.outputs.has_targets == 'true' }}
101+
timeout-minutes: 25
102+
103+
strategy:
104+
fail-fast: false
105+
matrix: ${{ fromJSON(needs.determine-matrix.outputs.matrix) }}
106+
107+
steps:
108+
- name: Checkout repository
109+
uses: actions/checkout@v4
110+
with:
111+
fetch-depth: 0
112+
113+
- name: Show Docker version
114+
run: |
115+
docker version
116+
docker info
117+
118+
- name: Run scripts/smoke.sh for ${{ matrix.name }}
119+
shell: bash
120+
run: |
121+
set -euo pipefail
122+
svc="${{ matrix.name }}"
123+
case "$svc" in
124+
web)
125+
export WEB_PORT=${{ matrix.host_port }}
126+
export WEB_PATH='${{ matrix.path }}'
127+
;;
128+
admin)
129+
export ADMIN_PORT=${{ matrix.host_port }}
130+
export ADMIN_PATH='${{ matrix.path }}'
131+
export ADMIN_BASE_PATH='/god-mode'
132+
;;
133+
space)
134+
export SPACE_PORT=${{ matrix.host_port }}
135+
export SPACE_PATH='${{ matrix.path }}'
136+
export SPACE_BASE_PATH='/spaces'
137+
;;
138+
live)
139+
export LIVE_PORT=${{ matrix.host_port }}
140+
export LIVE_PATH='${{ matrix.path }}'
141+
export LIVE_BASE_PATH='/live'
142+
;;
143+
esac
144+
export MAX_WAIT=120
145+
export SLEEP_INTERVAL=2
146+
export NODE_ENV=production
147+
set +e
148+
output="$(bash scripts/smoke.sh up --services "$svc")"
149+
status=$?
150+
set -e
151+
echo "$output"
152+
if [ $status -ne 0 ]; then
153+
echo "smoke.sh exited non-zero ($status)"
154+
exit $status
155+
fi
156+
if echo "$output" | grep -qi "failure(s)"; then
157+
echo "::group::Container logs ($svc)"
158+
docker ps -a || true
159+
docker logs "plane-${svc}-smoke" || true
160+
echo "::endgroup::"
161+
exit 1
162+
fi
163+
164+
- name: Cleanup smoke containers (${{ matrix.name }})
165+
if: always()
166+
run: |
167+
bash scripts/smoke.sh down

apps/admin/Dockerfile.admin

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ WORKDIR /app
6868

6969
# Don't run production as root
7070
RUN addgroup --system --gid 1001 nodejs
71-
RUN adduser --system --uid 1001 nextjs
72-
USER nextjs
71+
RUN adduser --system --uid 1001 -G nodejs nextjs
72+
USER 1001:1001
7373

7474
# Automatically leverage output traces to reduce image size
7575
# https://nextjs.org/docs/advanced-features/output-file-tracing
@@ -97,7 +97,10 @@ ENV NEXT_PUBLIC_WEB_BASE_URL=$NEXT_PUBLIC_WEB_BASE_URL
9797

9898
ENV NEXT_TELEMETRY_DISABLED=1
9999
ENV TURBO_TELEMETRY_DISABLED=1
100+
ENV NODE_ENV=production
100101

101102
EXPOSE 3000
102103

104+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=5 \
105+
CMD wget -qO- http://localhost:3000/god-mode > /dev/null || exit 1
103106
CMD ["node", "apps/admin/server.js"]

apps/live/Dockerfile.live

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store pnpm install --offline -
4444
ENV TURBO_TELEMETRY_DISABLED=1
4545

4646
RUN pnpm turbo run build --filter=live
47+
RUN pnpm prune --prod
4748

4849
# *****************************************************************************
4950
# STAGE 3: Run the project
@@ -52,13 +53,21 @@ RUN pnpm turbo run build --filter=live
5253
FROM base AS runner
5354
WORKDIR /app
5455

56+
# Don't run production as root
57+
RUN addgroup --system --gid 1001 nodejs
58+
RUN adduser --system --uid 1001 -G nodejs nextjs
59+
USER 1001:1001
60+
5561
COPY --from=installer /app/packages ./packages
5662
COPY --from=installer /app/apps/live/dist ./apps/live/dist
5763
COPY --from=installer /app/apps/live/node_modules ./apps/live/node_modules
5864
COPY --from=installer /app/node_modules ./node_modules
5965

6066
ENV TURBO_TELEMETRY_DISABLED=1
67+
ENV NODE_ENV=production
6168

6269
EXPOSE 3000
6370

71+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=5 \
72+
CMD wget -qO- http://localhost:3000/live/health > /dev/null || exit 1
6473
CMD ["node", "apps/live/dist/server.js"]

apps/space/Dockerfile.space

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ WORKDIR /app
6868

6969
# Don't run production as root
7070
RUN addgroup --system --gid 1001 nodejs
71-
RUN adduser --system --uid 1001 nextjs
72-
USER nextjs
71+
RUN adduser --system --uid 1001 -G nodejs nextjs
72+
USER 1001:1001
7373

7474
# Automatically leverage output traces to reduce image size
7575
# https://nextjs.org/docs/advanced-features/output-file-tracing
@@ -97,7 +97,10 @@ ENV NEXT_PUBLIC_WEB_BASE_URL=$NEXT_PUBLIC_WEB_BASE_URL
9797

9898
ENV NEXT_TELEMETRY_DISABLED=1
9999
ENV TURBO_TELEMETRY_DISABLED=1
100+
ENV NODE_ENV=production
100101

101102
EXPOSE 3000
102103

104+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=5 \
105+
CMD wget -qO- http://localhost:3000/spaces > /dev/null || exit 1
103106
CMD ["node", "apps/space/server.js"]

apps/web/Dockerfile.web

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ WORKDIR /app
7878

7979
# Don't run production as root
8080
RUN addgroup --system --gid 1001 nodejs
81-
RUN adduser --system --uid 1001 nextjs
82-
USER nextjs
81+
RUN adduser --system --uid 1001 -G nodejs nextjs
82+
USER 1001:1001
8383

8484

8585
# Automatically leverage output traces to reduce image size
@@ -114,7 +114,10 @@ ENV NEXT_PUBLIC_WEB_BASE_URL=$NEXT_PUBLIC_WEB_BASE_URL
114114

115115
ENV NEXT_TELEMETRY_DISABLED=1
116116
ENV TURBO_TELEMETRY_DISABLED=1
117+
ENV NODE_ENV=production
117118

118119
EXPOSE 3000
119120

121+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=5 \
122+
CMD wget -qO- http://localhost:3000/ > /dev/null || exit 1
120123
CMD ["node", "apps/web/server.js"]

0 commit comments

Comments
 (0)