Skip to content

Commit 233c8b2

Browse files
authored
Workflow to build ppc64le binary for ubi (#6005)
1 parent 5ec176c commit 233c8b2

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed
+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: Build UBI ppc64le Dependency
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- build/dependencies/Dockerfile.ubi-ppc64le
9+
workflow_dispatch:
10+
inputs:
11+
nginx_version:
12+
type: string
13+
description: "NGINX Version to build for"
14+
required: false
15+
force:
16+
type: boolean
17+
description: "Force rebuild"
18+
required: false
19+
default: false
20+
21+
env:
22+
IMAGE_NAME: ghcr.io/nginxinc/dependencies/nginx-ubi-ppc64le
23+
24+
concurrency:
25+
group: ${{ github.ref_name }}-ubi-ppc64le-build
26+
cancel-in-progress: true
27+
28+
jobs:
29+
checks:
30+
name: Check versions
31+
runs-on: ubuntu-22.04
32+
permissions:
33+
packages: read
34+
contents: read
35+
strategy:
36+
fail-fast: false
37+
outputs:
38+
nginx_version: ${{ steps.var.outputs.nginx_version }}
39+
njs_version: ${{ steps.var.outputs.njs_version }}
40+
target_exists: ${{ steps.var.outputs.target_image_exists }}
41+
steps:
42+
- name: Checkout Repository
43+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
44+
45+
- name: Login to GitHub Container Registry
46+
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
47+
with:
48+
registry: ghcr.io
49+
username: ${{ github.repository_owner }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
51+
52+
- name: Output Variables
53+
id: var
54+
run: |
55+
if [ -n "${{ inputs.nginx_version }}" ]; then
56+
nginx_v=${{ inputs.nginx_version }}
57+
else
58+
nginx_v=$(grep -m1 'FROM nginx:' <build/dependencies/Dockerfile.ubi-ppc64le | cut -d '@' -f1 | awk -F'[: ]' '{print $3}')
59+
fi
60+
target_image=${{ env.IMAGE_NAME }}:nginx-${nginx_v}
61+
if docker manifest inspect ${target_image}; then
62+
target_image_exists=true
63+
else
64+
target_image_exists=false
65+
fi
66+
docker pull nginx:$nginx_v || exit 1
67+
njs=$(docker run nginx:$nginx_v env | grep NJS_VERSION | cut -d= -f2)
68+
echo "> Outputs -------------------------------"
69+
echo "NJS_VERSION=$njs"
70+
echo "nginx_version=${nginx_v}"
71+
echo "njs_version=${njs}"
72+
echo "target_image_exists=${target_image_exists}"
73+
echo "nginx_version=${nginx_v}" >> $GITHUB_OUTPUT
74+
echo "njs_version=${njs}" >> $GITHUB_OUTPUT
75+
echo "target_image_exists=${target_image_exists}" >> $GITHUB_OUTPUT
76+
77+
build-binaries:
78+
name: Build Binary Container Image
79+
if: ${{ needs.checks.outputs.target_exists != 'true' || inputs.force }}
80+
needs: checks
81+
runs-on: ubuntu-22.04
82+
permissions:
83+
packages: write
84+
contents: read
85+
strategy:
86+
fail-fast: false
87+
steps:
88+
- name: Checkout Repository
89+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
90+
91+
- name: Setup QEMU
92+
uses: docker/setup-qemu-action@5927c834f5b4fdf503fca6f4c7eccda82949e1ee # v3.1.0
93+
with:
94+
platforms: arm64,ppc64le,s390x
95+
96+
- name: Docker Buildx
97+
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
98+
99+
- name: Login to GitHub Container Registry
100+
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0
101+
with:
102+
registry: ghcr.io
103+
username: ${{ github.repository_owner }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Docker meta
107+
id: meta
108+
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
109+
with:
110+
images: |
111+
name=${{ env.IMAGE_NAME }},enable=true
112+
tags: |
113+
type=raw,value=nginx-${{ needs.checks.outputs.nginx_version }},enable=true
114+
env:
115+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
116+
117+
- name: Build and push
118+
uses: docker/build-push-action@1a162644f9a7e87d8f4b053101d1d9a712edc18c # v6.3.0
119+
with:
120+
file: ./build/dependencies/Dockerfile.ubi-ppc64le
121+
context: "."
122+
pull: true
123+
push: true
124+
# build multi-arch so that it can be mounted from any image
125+
# even though only ppc64le will contain binaries
126+
platforms: "linux/amd64,linux/arm64,linux/ppc64le,linux/s390x"
127+
tags: ${{ steps.meta.outputs.tags }}
128+
labels: ${{ steps.meta.outputs.labels }}
129+
annotations: ${{ steps.meta.outputs.annotations }}
130+
cache-from: type=gha,scope=nginx-ubi-ppc64le
131+
cache-to: type=gha,scope=nginx-ubi-ppc64le,mode=max
132+
target: final
133+
sbom: false
134+
provenance: mode=max
135+
build-args: |
136+
NGINX=${{ needs.checks.outputs.nginx_version }}
137+
NJS=${{ needs.checks.outputs.njs_version }}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# syntax=docker/dockerfile:1.8
2+
FROM nginx:1.27.0@sha256:67682bda769fae1ccf5183192b8daf37b64cae99c6c3302650f6f8bf5f0f95df AS nginx
3+
4+
FROM redhat/ubi9:9.4@sha256:081c96d1b1c7cd1855722d01f1ca53360510443737b1eb33284c6c4c330e537c AS rpm-build
5+
ARG NGINX
6+
ARG NJS
7+
ENV NGINX_VERSION ${NGINX}
8+
ENV NJS_VERSION ${NJS}
9+
10+
11+
RUN mkdir -p /nginx/; \
12+
# only build for ppc64le but make multiarch image for mounting
13+
[ $(uname -p) != ppc64le ] && exit 0; \
14+
rpm --import https://nginx.org/keys/nginx_signing.key \
15+
&& printf "%s\n" "[nginx]" "name=nginx src repo" \
16+
"baseurl=https://nginx.org/packages/mainline/centos/9/SRPMS" \
17+
"gpgcheck=1" "enabled=1" "module_hotfixes=true" >> /etc/yum.repos.d/nginx.repo \
18+
&& dnf install rpm-build gcc make dnf-plugins-core which -y \
19+
&& dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
20+
&& nginxPackages=" \
21+
nginx-${NGINX_VERSION} \
22+
nginx-module-xslt-${NGINX_VERSION} \
23+
nginx-module-image-filter-${NGINX_VERSION} \
24+
nginx-module-njs-${NGINX_VERSION}+${NJS_VERSION} \
25+
" \
26+
&& dnf config-manager --set-enabled ubi-9-codeready-builder \
27+
&& dnf download --source ${nginxPackages} \
28+
&& dnf builddep -y --srpm nginx*.rpm \
29+
&& rpmbuild --rebuild --nodebuginfo nginx*.rpm \
30+
&& cp /root/rpmbuild/RPMS/$(arch)/* /nginx/
31+
32+
FROM scratch AS final
33+
COPY --link --from=rpm-build /nginx /

0 commit comments

Comments
 (0)