Skip to content

Commit bb4ba58

Browse files
aberohamclaude
andcommitted
consolidate CI and production into one multi-stage Dockerfile
Replace the separate .github/Dockerfile with a multi-stage build in dist/docker/Dockerfile: `base` stage has all deps (CI stops here with --target base), `production` stage adds source and entrypoint. Also fix GHCR tag: lowercase $GITHUB_REPOSITORY (NicTool → nictool) since OCI tags must be all lowercase. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6b68332 commit bb4ba58

4 files changed

Lines changed: 32 additions & 89 deletions

File tree

.github/Dockerfile

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/workflows/ci-image.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: [master]
66
paths:
7-
- '.github/Dockerfile'
7+
- 'dist/docker/Dockerfile'
88
- '.github/workflows/ci-image.yml'
99
- 'server/Makefile.PL'
1010
- 'client/Makefile.PL'
@@ -20,6 +20,10 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v6
2222

23+
- name: Compute image tag
24+
id: meta
25+
run: echo "tag=ghcr.io/${GITHUB_REPOSITORY,,}/ci:latest" >> "$GITHUB_OUTPUT"
26+
2327
- uses: docker/setup-buildx-action@v4
2428

2529
- uses: docker/login-action@v3
@@ -31,8 +35,9 @@ jobs:
3135
- uses: docker/build-push-action@v7
3236
with:
3337
context: .
34-
file: .github/Dockerfile
38+
file: dist/docker/Dockerfile
39+
target: base
3540
push: true
36-
tags: ghcr.io/${{ github.repository }}/ci:latest
41+
tags: ${{ steps.meta.outputs.tag }}
3742
cache-from: type=gha
3843
cache-to: type=gha,mode=max

.github/workflows/ci.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
types: [opened, synchronize, reopened]
66
paths:
77
- '.github/workflows/ci.yml'
8-
- '.github/Dockerfile'
98
- '.test/**'
109
- 'client/**'
1110
- 'server/**'
@@ -17,10 +16,19 @@ permissions:
1716
packages: read
1817

1918
jobs:
19+
image-name:
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
ci: ${{ steps.set.outputs.ci }}
23+
steps:
24+
- id: set
25+
run: echo "ci=ghcr.io/${GITHUB_REPOSITORY,,}/ci:latest" >> "$GITHUB_OUTPUT"
26+
2027
test:
28+
needs: image-name
2129
runs-on: ubuntu-24.04
2230
container:
23-
image: ghcr.io/${{ github.repository }}/ci:latest
31+
image: ${{ needs.image-name.outputs.ci }}
2432
credentials:
2533
username: ${{ github.actor }}
2634
password: ${{ secrets.GITHUB_TOKEN }}

dist/docker/Dockerfile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM debian:bookworm
1+
# ---- base: all system + CPAN deps, Apache configured, no app source ----
2+
# CI builds stop here (--target base). Production builds continue below.
3+
FROM debian:bookworm AS base
24

35
ENV DEBIAN_FRONTEND=noninteractive LANG=en_US.UTF-8 LC_ALL=C.UTF-8
46

@@ -16,7 +18,7 @@ RUN apt-get -q update && apt-get install -qy \
1618
libexpat-dev \
1719
gettext \
1820
bind9utils \
19-
mariadb-client \
21+
default-mysql-client \
2022
openssl \
2123
libdbix-simple-perl \
2224
libdbd-mysql-perl \
@@ -49,13 +51,14 @@ RUN apt-get -q update && apt-get install -qy \
4951
&& apt-get clean \
5052
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5153

52-
# Copy only Makefile.PL files first for dependency caching
53-
COPY server/Makefile.PL /usr/local/nictool/server/Makefile.PL
54-
COPY client/Makefile.PL /usr/local/nictool/client/Makefile.PL
54+
# Copy only Makefile.PL files for dependency caching
55+
COPY server/Makefile.PL /tmp/nictool/server/Makefile.PL
56+
COPY client/Makefile.PL /tmp/nictool/client/Makefile.PL
5557

5658
# Install Perl dependencies (cached unless Makefile.PL changes)
57-
RUN cd /usr/local/nictool/server && perl Makefile.PL && cpanm -n . \
58-
&& cd /usr/local/nictool/client && perl Makefile.PL && cpanm -n .
59+
RUN cd /tmp/nictool/server && perl Makefile.PL && cpanm -n . \
60+
&& cd /tmp/nictool/client && perl Makefile.PL && cpanm -n . \
61+
&& rm -rf /tmp/nictool
5962

6063
# Additional Perl modules not in Makefile.PL
6164
RUN cpanm --notest \
@@ -67,12 +70,15 @@ RUN cpanm --notest \
6770
RUN a2dismod mpm_event && a2enmod mpm_prefork && a2enmod ssl \
6871
&& rm -rf /etc/apache2/sites-enabled/* /etc/apache2/sites-available/*
6972

73+
# ---- production: install app source and entrypoint ----
74+
FROM base AS production
75+
7076
# Now copy the full source (only this layer invalidates on code changes)
7177
COPY server/ /usr/local/nictool/server/
7278
COPY client/ /usr/local/nictool/client/
7379
COPY dist/ /usr/local/nictool/dist/
7480

75-
# Install the actual NicTool modules (deps are cached above)
81+
# Install the actual NicTool modules (deps are cached in base)
7682
RUN cd /usr/local/nictool/server && perl Makefile.PL && make install \
7783
&& cd /usr/local/nictool/client && perl Makefile.PL && make install
7884

0 commit comments

Comments
 (0)