Skip to content

Commit 87a7d28

Browse files
Update base images to allow an arbitrary user to run it
1 parent d6f3da6 commit 87a7d28

File tree

7 files changed

+51
-29
lines changed

7 files changed

+51
-29
lines changed

.github/workflows/base-images.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ on:
77

88
jobs:
99
base-image-build:
10-
if: ${{ github.repository == 'shipwright-io/build' }}
10+
if: ${{ github.event_name == 'workflow_dispatch' || github.repository == 'shipwright-io/build' }}
1111
runs-on: ubuntu-latest
1212
strategy:
1313
fail-fast: false
1414
matrix:
1515
image:
16+
- base
1617
- git
1718
- image-processing
1819
- waiter
19-
max-parallel: 3
20+
# We cannot run in parallel because the base image must be built first
21+
max-parallel: 1
2022

2123
steps:
2224
- uses: actions/checkout@v3
@@ -36,4 +38,4 @@ jobs:
3638
working-directory: images/${{ matrix.image }}
3739
run: |
3840
NAMESPACE=$(tr '[:upper:]' '[:lower:]' <<<${{ github.repository_owner }})
39-
IMAGE=ghcr.io/${NAMESPACE}/base-${{ matrix.image }} docker buildx bake --push -f ../docker-bake.hcl
41+
IMAGE=ghcr.io/${NAMESPACE}/base-${{ matrix.image }} NAMESPACE="${NAMESPACE}" docker buildx bake --push -f ../docker-bake.hcl

.github/workflows/ci.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ jobs:
3131
runs-on: ubuntu-latest
3232
strategy:
3333
fail-fast: true
34-
max-parallel: 3
34+
max-parallel: 4
3535
matrix:
3636
image:
37-
- git
38-
- image-processing
39-
- waiter
37+
- base
38+
- git
39+
- image-processing
40+
- waiter
4041
steps:
4142
- uses: actions/checkout@v3
4243
- name: Set up QEMU
@@ -48,7 +49,8 @@ jobs:
4849
- name: Build Image
4950
working-directory: images/${{ matrix.image }}
5051
run: |
51-
IMAGE=test-build/base-${{ matrix.image }} docker buildx bake --file ../docker-bake.hcl
52+
NAMESPACE=$(tr '[:upper:]' '[:lower:]' <<<${{ github.repository_owner }})
53+
IMAGE=test-build/base-${{ matrix.image }} NAMESPACE="${NAMESPACE}" docker buildx bake --file ../docker-bake.hcl
5254
5355
integration:
5456
strategy:

images/base/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright The Shipwright Contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
FROM registry.access.redhat.com/ubi9-minimal:latest
5+
6+
RUN \
7+
microdnf --refresh --assumeyes --best --nodocs --noplugins --setopt=install_weak_deps=0 upgrade && \
8+
microdnf clean all && \
9+
rm -rf /var/cache/yum && \
10+
# The following setup is necessary so that this image can run as any user
11+
mkdir -p /shared-home/.docker /shared-home/.ssh && chmod -R 0777 /shared-home && \
12+
# This is the default user that will be used when strategy steps use different runAs configuration.
13+
# This must be in synchronization with our default configuration.
14+
echo "shp:x:1000:1000:shp:/shared-home:/sbin/nologin" >/etc/passwd && \
15+
echo "shp:x:1000" >/etc/group
16+
17+
ENV HOME /shared-home

images/docker-bake.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
variable "IMAGE" {
22
}
33

4+
variable "NAMESPACE" {
5+
}
6+
47
group "default" {
58
targets = ["all"]
69
}
710

811
target "all" {
12+
args = {
13+
BASE = "ghcr.io/${NAMESPACE}/base-base"
14+
}
915
tags = ["${IMAGE}:latest"]
1016
platforms = ["linux/amd64", "linux/arm64", "linux/ppc64le", "linux/s390x"]
1117
}
18+
19+

images/git/Dockerfile

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Copyright The Shipwright Contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
FROM registry.access.redhat.com/ubi9-minimal:latest
4+
5+
ARG BASE
6+
7+
FROM ${BASE}
58

69
RUN \
7-
microdnf --refresh --assumeyes --best --nodocs --noplugins --setopt=install_weak_deps=0 upgrade && \
810
microdnf --assumeyes --nodocs install git git-lfs && \
911
microdnf clean all && \
10-
rm -rf /var/cache/yum && \
11-
echo 'nonroot:x:1000:1000:nonroot:/:/sbin/nologin' > /etc/passwd && \
12-
echo 'nonroot:x:1000:' > /etc/group && \
13-
mkdir /.docker && chown 1000:1000 /.docker && \
14-
mkdir /.ssh && chown 1000:1000 /.ssh
12+
rm -rf /var/cache/yum
1513

1614
USER 1000:1000

images/image-processing/Dockerfile

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
# Copyright The Shipwright Contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
ARG BASE
5+
46
FROM registry.access.redhat.com/ubi9-minimal:latest AS bin-loader
57
RUN \
68
microdnf --assumeyes --nodocs install gzip jq tar && \
79
TAG_NAME="$(curl -s https://api.github.com/repos/aquasecurity/trivy/releases/latest | jq -r '.tag_name')" && \
810
curl -L -s "https://github.com/aquasecurity/trivy/releases/download/${TAG_NAME}/trivy_${TAG_NAME/v/}_$(uname -s)-$(uname -m | sed -e 's/aarch64/ARM64/' -e 's/ppc64le/PPC64LE/' -e 's/x86_64/64bit/').tar.gz" | tar -xzf - -C /usr/local/bin trivy
911

1012

11-
FROM registry.access.redhat.com/ubi9-minimal:latest
13+
FROM ${BASE}
14+
1215
COPY --from=bin-loader /usr/local/bin/trivy /usr/local/bin/trivy
13-
RUN \
14-
microdnf --refresh --assumeyes --best --nodocs --noplugins --setopt=install_weak_deps=0 upgrade && \
15-
microdnf clean all && \
16-
rm -rf /var/cache/yum && \
17-
echo 'nonroot:x:1000:1000:nonroot:/:/sbin/nologin' > /etc/passwd && \
18-
echo 'nonroot:x:1000:' > /etc/group
1916

2017
USER 1000:1000

images/waiter/Dockerfile

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
# Copyright The Shipwright Contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
FROM registry.access.redhat.com/ubi9-minimal:latest
4+
5+
ARG BASE
6+
7+
FROM ${BASE}
58

69
RUN \
7-
microdnf --refresh --assumeyes --best --nodocs --noplugins --setopt=install_weak_deps=0 upgrade && \
810
microdnf --assumeyes --nodocs install tar && \
911
microdnf clean all && \
10-
rm -rf /var/cache/yum && \
11-
echo 'nonroot:x:1000:1000:nonroot:/:/sbin/nologin' > /etc/passwd && \
12-
echo 'nonroot:x:1000:' > /etc/group && \
13-
mkdir /.docker && \
14-
chown 1000:1000 /.docker
12+
rm -rf /var/cache/yum
1513

1614
USER 1000:1000

0 commit comments

Comments
 (0)