Skip to content

Commit 12a9f01

Browse files
committed
Use a multi-stage build to create the Flatpak Indexer container image
Instead of building a differ image and then copying files around in a build script (which causes much complexity in CI), we can use a multi-stage Containerfile to build and test everything in one place.
1 parent a0424cb commit 12a9f01

File tree

7 files changed

+56
-42
lines changed

7 files changed

+56
-42
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Containerfile
2+
differ
3+
dist
4+
out
5+
tls-secrets
6+
.venv
7+
work
8+
**/__pycache__
9+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/.test-data
33
/dist
44
/out/*
5+
/uv.lock
56
/tls-secrets/*
67
/work/*
78
/flatpak_indexer/certs/RH-IT-Root-CA.crt

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "differ/tar-diff"]
2-
path = differ/tar-diff
1+
[submodule "tar-diff"]
2+
path = tar-diff
33
url = https://github.com/containers/tar-diff

Containerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
FROM registry.access.redhat.com/ubi9/go-toolset as tar-diff-builder
2+
3+
USER root
4+
ADD tar-diff /tmp/src
5+
RUN chown -R 1001:0 /tmp/src
6+
7+
USER 1001
8+
9+
# We need to pass -buildvcs=false because we only copy part of the git checkout
10+
RUN cd /tmp/src && go build -buildvcs=false -o /opt/app-root/bin/tar-diff ./cmd/tar-diff
11+
12+
FROM registry.access.redhat.com/ubi9/python-312 as builder
13+
14+
ARG FLATPAK_INDEXER_UPDATE_TEST_DATA=false
15+
ENV FLATPAK_INDEXER_UPDATE_TEST_DATA=${FLATPAK_INDEXER_UPDATE_TEST_DATA}
16+
17+
# Add application sources to a directory that the assemble script expects them
18+
# and set permissions so that the container runs without root access
19+
USER 0
20+
ADD . /tmp/src
21+
RUN /usr/bin/fix-permissions /tmp/src
22+
USER 1001
23+
24+
# Install the application's dependencies from PyPI
25+
RUN /bin/sh /tmp/src/.s2i/bin/assemble
26+
27+
FROM registry.access.redhat.com/ubi9/python-312-minimal
28+
29+
USER 0
30+
RUN microdnf -y install time && microdnf clean all
31+
USER 1001
32+
33+
# Copy the tar-diff binary from the tar-diff-builder image
34+
COPY --from=tar-diff-builder /opt/app-root/bin/tar-diff /opt/app-root/bin/
35+
36+
# Copy app sources together with the whole virtual environment from the builder image
37+
COPY --from=builder /opt/app-root /opt/app-root
38+
39+
# Run tests
40+
RUN $APP_ROOT/src/tools/test.sh
41+
42+
# Set the default command for the resulting image
43+
CMD /usr/libexec/s2i/run

differ/Dockerfile

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

tools/build-indexer.sh

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,4 @@ set -ex
44

55
origin=$(cd $(dirname $0)/.. && pwd)
66

7-
tmp_container=
8-
work=$(mktemp -d)
9-
cleanup() {
10-
:
11-
# rm -rf $work
12-
[ -n "$tmp_container" ] && podman rm $tmp_container
13-
}
14-
trap cleanup EXIT
15-
16-
set -x
17-
18-
podman build $origin/differ -t flatpak-indexer-tar-diff
19-
20-
s2i build --copy --as-dockerfile=$work/Dockerfile $origin registry.access.redhat.com/ubi8/python-39 flatpak-indexer
21-
22-
tmp_container=$(podman create flatpak-indexer-tar-diff)
23-
mkdir -p -m 0755 $work/upload/src/bin
24-
podman cp $tmp_container:/opt/app-root/tar-diff $work/upload/src/bin/tar-diff
25-
podman cp $tmp_container:/usr/bin/time $work/upload/src/bin/time
26-
27-
tmp_tag="flatpak-indexer:$(date +%Y%m%d-%H%M%S)"
28-
podman build $work -t $tmp_tag
29-
if podman run --network=none --rm $tmp_tag tools/test.sh ; then
30-
podman tag $tmp_tag flatpak-indexer:latest
31-
podman rmi $tmp_tag
32-
else
33-
podman rmi $tmp_tag
34-
exit 1
35-
fi
7+
podman build -t flatpak-indexer:latest $origin

0 commit comments

Comments
 (0)