Skip to content

Commit

Permalink
Merge pull request #9 from metacpan/haarg/slim-builds
Browse files Browse the repository at this point in the history
slim builds
  • Loading branch information
oalders authored Apr 25, 2024
2 parents 33aeac5 + 7d97f7b commit b461976
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-deployment-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ jobs:
push: true
tags: metacpan/metacpan-base:$GITHUB_SHA
platforms: linux/amd64,linux/arm64
- name: Build and push slim
uses: docker/build-push-action@v5
with:
push: true
build-arg:
- SLIM_BUILD=1
tags: metacpan/metacpan-base:$GITHUB_SHA-slim
platforms: linux/amd64,linux/arm64
10 changes: 9 additions & 1 deletion .github/workflows/build-production-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ jobs:
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push
- name: Build and push latest
uses: docker/build-push-action@v5
with:
push: true
tags: metacpan/metacpan-base:latest
platforms: linux/amd64,linux/arm64
- name: Build and push latest-slim
uses: docker/build-push-action@v5
with:
push: true
build-arg:
- SLIM_BUILD=1
tags: metacpan/metacpan-base:latest-slim
platforms: linux/amd64,linux/arm64
46 changes: 32 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
ARG PERL_VERSION=5.36
ARG SLIM_BUILD

FROM perl:${PERL_VERSION} AS build-uwsgi
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]

WORKDIR /
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt/lists,sharing=private \
<<EOT /bin/bash -euo pipefail
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
<<EOT
rm -f /etc/apt/apt.conf.d/docker-clean
apt-get update
apt-get install -y build-essential libcap-dev libpcre3-dev uwsgi-core uwsgi-src

apt-get satisfy -y --no-install-recommends \
'build-essential (>= 12.9)' \
'libcap-dev (>= 1:2.66)' \
'libpcre3-dev (>= 2:8.39)' \
'uwsgi-core (>= 2.0.21)' \
'uwsgi-src (>= 2.0.21)'

/usr/bin/uwsgi --build-plugin "/usr/src/uwsgi/plugins/psgi"
EOT

FROM perl:${PERL_VERSION} AS build-perl
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]

WORKDIR /metacpan
COPY cpanfile cpanfile.snapshot /metacpan/

# cpm needs Carton::Snapshot to read cpanfile.snapshot
# Carton::Snapshot has no version, but it's packaged with Carton, which does
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=private \
--mount=type=cache,target=/var/lib/apt/lists,sharing=private \
<<EOT /bin/bash -euo pipefail
cpm install -g Carton::Snapshot
cpm install -g
--mount=type=cache,target=/root/.cpm,sharing=locked \
<<EOT
cpm install -g --show-build-log-on-failure \
Carton~'>= 1.0.35'
cpm install -g --show-build-log-on-failure
EOT

FROM perl:${PERL_VERSION}
FROM perl:${PERL_VERSION}${SLIM_BUILD:+-slim}
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]

RUN --mount=type=cache,target=/var/cache/apt,sharing=private \
<<EOT /bin/bash -euo pipefail
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt/lists,sharing=locked \
<<EOT
useradd -m metacpan -g users

rm -f /etc/apt/apt.conf.d/docker-clean
apt-get update
apt-get install -y uwsgi-core
apt-get satisfy -y --no-install-recommends \
'uwsgi-core (>= 2.0.21)'
EOT

COPY --from=build-uwsgi psgi_plugin.so /usr/lib/uwsgi/plugins/psgi_plugin.so
COPY --from=build-uwsgi /psgi_plugin.so /usr/lib/uwsgi/plugins/psgi_plugin.so
COPY --from=build-perl /usr/local/lib/perl5 /usr/local/lib/perl5
COPY --from=build-perl /usr/local/bin /usr/local/bin
COPY wait-for-it.sh /

0 comments on commit b461976

Please sign in to comment.