Skip to content

Commit d37edf2

Browse files
authored
Merge pull request #1383 from metacpan/haarg/cleanups
Docker build and other cleanups
2 parents 9478cd5 + 74b9d09 commit d37edf2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+390
-1528
lines changed

.circleci/config.yml

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,24 @@ jobs:
1515
resource_class: large
1616
steps:
1717
- run:
18-
name: docker-compose version
19-
command: docker-compose --version
18+
name: docker compose version
19+
command: docker compose version
20+
- checkout
2021
- run:
22+
name: create coverage directory
2123
command: |
22-
git clone https://github.com/metacpan/metacpan-docker.git
23-
cd metacpan-docker
24-
name: metacpan-docker checkout
25-
- checkout:
26-
path: metacpan-docker/src/metacpan-api
24+
mkdir cover_db
25+
chmod o+w cover_db
2726
- run:
27+
name: docker compose build
2828
command: |
29-
pushd metacpan-docker
30-
./bin/metacpan-docker init
31-
name: clone missing repositories
29+
docker compose --profile test build api-test
3230
- run:
33-
command: |
34-
pushd metacpan-docker
35-
docker-compose build --build-arg CPM_ARGS='--with-test' api_test
36-
name: compose build
37-
- run:
38-
command: |
39-
pushd metacpan-docker
40-
./bin/metacpan-docker init
41-
docker-compose --verbose up -d api_test
42-
name: compose up
43-
- run:
44-
command: |
45-
pushd metacpan-docker
46-
docker-compose exec -T api_test cpm install -g Devel::Cover
47-
name: install Devel::Cover
48-
# Since we're running docker-compose -d, we don't actually know if
49-
# Elasticsearch is available at the time this build step begins. We
50-
# probably need to wait for it here, so we'll add our own check.
51-
- run:
52-
command: |
53-
pushd metacpan-docker
54-
./src/metacpan-api/wait-for-es.sh http://localhost:9200 elasticsearch_test
55-
name: wait for ES
56-
- run:
57-
command: |
58-
pushd metacpan-docker
59-
docker-compose exec -T api_test env HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lr --jobs 4 t
6031
name: run tests with coverage
32+
command: |
33+
docker compose --profile test run --env HARNESS_PERL_SWITCHES=-MDevel::Cover -v ./cover_db:/app/cover_db/ api-test bash -c 'prove -lr -j4 t && cover -report json'
6134
# We are relying on environment variables from the host to be available when
6235
# we publish the report, so we publish from the host rather than trying
6336
# to propagate env variables to the container.
64-
- run:
65-
command: |
66-
pushd metacpan-docker
67-
docker-compose exec -T api_test cover -report json
68-
name: create coverage report
6937
- codecov/upload:
70-
file: metacpan-docker/src/metacpan-api/cover_db/cover.json
71-
- run:
72-
command: |
73-
pushd metacpan-docker
74-
docker-compose logs
75-
docker stats --no-stream
76-
docker ps -a | head
77-
name: docker-compose logs
78-
when: on_fail
38+
file: cover_db/cover.json

.github/workflows/build-container.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build container
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- staging
7+
- prod
8+
pull_request:
9+
types: [opened, synchronize, labeled]
10+
branches:
11+
- master
12+
workflow_dispatch:
13+
jobs:
14+
docker-build:
15+
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'build-container')
16+
runs-on: ubuntu-22.04
17+
name: Docker Build and Push
18+
steps:
19+
- name: Generate Auth Token
20+
uses: actions/create-github-app-token@v2
21+
id: app-token
22+
with:
23+
app-id: ${{ secrets.APP_ID }}
24+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
25+
owner: metacpan
26+
- uses: actions/checkout@v4
27+
with:
28+
token: ${{ steps.app-token.outputs.token }}
29+
- uses: metacpan/metacpan-actions/docker-build-push@master
30+
id: build-push
31+
with:
32+
docker_hub_username: ${{ secrets.DOCKER_HUB_USER }}
33+
docker_hub_password: ${{ secrets.DOCKER_HUB_TOKEN }}
34+
ghcr_username: ${{ github.repository_owner }}
35+
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
36+
test-target: test
37+
# - name: Update deployed image
38+
# if: steps.find-tag-names.outputs.latest
39+
# uses: metacpan/metacpan-actions/update-deployed-tag:master
40+
# with:
41+
# token: ${{ steps.app-token.outputs.token }}
42+
# app: api
43+
# environment: prod
44+
# base-tag: ${{ steps.find-tag-names.outputs.latest }}
45+
# tag: ${{ steps.find-tag-names.outputs.sha }}
46+

.github/workflows/build-deployment-container.yml

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

.github/workflows/build-production-container.yml

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

.github/workflows/code-formatting.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: Code Formatting
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
merge_group:
8+
pull_request:
9+
branches:
10+
- '*'
11+
workflow_dispatch:
12+
13+
jobs:
14+
code-formatting:
15+
runs-on: ubuntu-24.04
16+
name: Code Formatting
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
- name: Fetch base ref
22+
if: ${{ github.event.pull_request }}
23+
run: git fetch origin ${{ github.base_ref }}:upstream
24+
- name: Install Carton
25+
uses: perl-actions/install-with-cpm@v1
26+
with:
27+
install: Carton
28+
- name: Install CPAN deps
29+
uses: perl-actions/install-with-cpm@v1
30+
with:
31+
cpanfile: 'cpanfile'
32+
args: >
33+
--resolver=snapshot
34+
--without-runtime
35+
--without-test
36+
--without-build
37+
--with-develop
38+
- name: Install precious
39+
run: ./bin/install-precious /usr/local/bin
40+
env:
41+
GITHUB_TOKEN: ${{ github.token }}
42+
- run: perltidy --version
43+
- name: Select files
44+
id: select-files
45+
run: |
46+
if [[ -n "${{ github.event.pull_request.number }}" ]]; then
47+
echo 'precious-args=--git-diff-from upstream' >> "$GITHUB_OUTPUT"
48+
else
49+
echo 'precious-args=--all' >> "$GITHUB_OUTPUT"
50+
fi
51+
- name: Lint files
52+
run: precious lint ${{ steps.select-files.outputs.precious-args }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
/perltidy.LOG
1111
/pm_to_blib
1212
/var
13+
/bin/omegasort
14+
/bin/precious
15+
/bin/ubi
1316
/etc/metacpan_local.pl
1417
/t/var/darkpan/
1518
/t/var/log/

Dockerfile

Lines changed: 97 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,101 @@
1-
# hadolint ignore=DL3007
2-
FROM metacpan/metacpan-base:latest
3-
4-
COPY cpanfile cpanfile.snapshot /metacpan-api/
5-
WORKDIR /metacpan-api
6-
7-
# CPM installations of dependencies does not install or run tests. This is
8-
# because the modules themselves have been tested, and the metacpan use of the
9-
# modules is tested by the test suite. Removing the tests, reduces the overall
10-
# size of the images.
11-
RUN mkdir /CPAN \
12-
&& apt-get update \
13-
&& apt-get satisfy -y --no-install-recommends 'rsync (>= 3.2.3)' 'jq (>= 1.6)' \
14-
&& apt-get clean \
15-
&& rm -rf /var/lib/apt/lists/* \
16-
&& cpm install --global \
17-
&& git config --global --add safe.directory /metacpan-api \
18-
&& rm -fr /root/.cpanm /root/.perl-cpm /var/cache/apt/lists/* /tmp/*
1+
ARG SLIM_BUILD
2+
ARG MAYBE_BASE_BUILD=${SLIM_BUILD:+server-base-slim}
3+
ARG BASE_BUILD=${MAYBE_BASE_BUILD:-server-base}
4+
5+
################### Web Server Base
6+
FROM metacpan/metacpan-base:main-20250531-090128 AS server-base
7+
FROM metacpan/metacpan-base:main-20250531-090129-slim AS server-base-slim
8+
9+
################### CPAN Prereqs
10+
FROM server-base AS build-cpan-prereqs
11+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
12+
13+
WORKDIR /app/
14+
15+
COPY cpanfile cpanfile.snapshot ./
16+
RUN \
17+
--mount=type=cache,target=/root/.perl-cpm,sharing=private \
18+
<<EOT
19+
cpm install --show-build-log-on-failure --resolver=snapshot
20+
EOT
21+
22+
################### Web Server
23+
# false positive
24+
# hadolint ignore=DL3006
25+
FROM ${BASE_BUILD} AS server
26+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
27+
28+
WORKDIR /app/
29+
30+
COPY app.psgi log4perl* metacpan_server.* metacpan_server_local.* ./
31+
COPY es es
32+
COPY bin bin
33+
COPY lib lib
34+
COPY root root
35+
36+
COPY --from=build-cpan-prereqs /app/local local
37+
38+
ENV PERL5LIB="/app/local/lib/perl5"
39+
ENV PATH="/app/local/bin:${PATH}"
40+
ENV METACPAN_SERVER_HOME=/app
1941

2042
VOLUME /CPAN
2143

22-
EXPOSE 5000
44+
USER metacpan
45+
46+
CMD [ \
47+
"/uwsgi.sh", \
48+
"--http-socket", ":8000" \
49+
]
50+
51+
EXPOSE 8000
52+
53+
HEALTHCHECK --start-period=3s CMD [ "curl", "--fail", "http://localhost:8000/healthcheck" ]
54+
55+
################### Development Server
56+
FROM server AS develop
57+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
58+
59+
ENV COLUMNS=120
60+
ENV PLACK_ENV=development
61+
62+
USER root
63+
64+
COPY cpanfile cpanfile.snapshot ./
65+
66+
RUN \
67+
--mount=type=cache,target=/root/.perl-cpm \
68+
<<EOT
69+
cpm install --show-build-log-on-failure --resolver=snapshot --with-develop
70+
chown -R metacpan:users ./
71+
EOT
72+
73+
USER metacpan
74+
75+
################### Test Runner
76+
FROM develop AS test
77+
SHELL [ "/bin/bash", "-euo", "pipefail", "-c" ]
78+
79+
ENV PLACK_ENV=
80+
81+
USER root
82+
83+
RUN \
84+
--mount=type=cache,target=/root/.perl-cpm \
85+
<<EOT
86+
cpm install --show-build-log-on-failure --resolver=snapshot --with-test
87+
EOT
88+
89+
COPY .perlcriticrc .perltidyrc perlimports.toml precious.toml .editorconfig metacpan_server_testing.* ./
90+
COPY t t
91+
COPY test-data test-data
92+
93+
RUN chown metacpan t/var
94+
95+
USER metacpan
96+
CMD [ "prove", "-l", "-r", "-j", "2", "t" ]
97+
98+
################### Production Server
99+
FROM server AS production
23100

24-
CMD [ "/wait-for-it.sh", "${PGDB}", "--", "${API_SERVER}", "./bin/api.pl" ]
101+
USER metacpan

bin/install-precious

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
# This is for installing precious and other 3rd party libs needed for linting
4+
# in CI
5+
6+
set -euo pipefail
7+
8+
if [ -z "${1:-}" ]; then
9+
echo "usage: ./bin/install-precious /path/to/bin/dir"
10+
exit 1
11+
fi
12+
13+
TARGET=$1
14+
export TARGET
15+
16+
TARGET=$1
17+
export TARGET
18+
19+
curl --silent --location \
20+
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
21+
sh
22+
23+
ubi --project houseabsolute/omegasort --in "$TARGET"
24+
ubi --project houseabsolute/precious --in "$TARGET"

0 commit comments

Comments
 (0)