Skip to content

Commit f46d74d

Browse files
authored
ODH Image build actions (#4)
1 parent 6cf7ecc commit f46d74d

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# This is a copy of the publish-core-images.yaml and has been customized to
2+
# use the quay login credentials.
3+
# The unused parts of the original have been commented out on purpose.
4+
name: ODH
5+
6+
on:
7+
- push
8+
- pull_request
9+
10+
jobs:
11+
build-and-publish-operator:
12+
name: Build and (or) Publish Image
13+
runs-on: ubuntu-latest
14+
env:
15+
GOPATH: ${{ github.workspace }}/go
16+
REPO_NAME: ${{ vars.QUAY_REPO_NAME || 'opendatahub' }}
17+
steps:
18+
- name: Environment dump
19+
shell: bash
20+
run: |
21+
echo "GOPATH = ${GOPATH}"
22+
echo "REPO_NAME = ${REPO_NAME}"
23+
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version-file: go.mod
31+
32+
- name: Run go mod
33+
shell: bash
34+
run: |
35+
go mod download
36+
37+
# Build operators inside the gh runner vm directly and then copy the go binaries to docker images using the Dockerfile.buildx
38+
- name: Build linux/amd64 operator binary
39+
env:
40+
CGO_ENABLED: 1
41+
GOOS: linux
42+
GOARCH: amd64
43+
shell: bash
44+
run: |
45+
go build -tags strictfipsruntime -a -o manager-$GOARCH cmd/training-operator.v1/main.go
46+
47+
- name: Build linux/arm64 operator binary
48+
env:
49+
CC: aarch64-linux-gnu-gcc
50+
CGO_ENABLED: 1
51+
GOOS: linux
52+
GOARCH: arm64
53+
shell: bash
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
57+
go build -tags strictfipsruntime -a -o manager-$GOARCH cmd/training-operator.v1/main.go
58+
59+
- name: Add docker tags
60+
id: meta
61+
uses: docker/metadata-action@v5
62+
with:
63+
images: quay.io/${{ env.REPO_NAME }}/training-operator
64+
tags: |
65+
type=raw,latest
66+
type=ref,event=pr
67+
type=sha,prefix=v1-odh-
68+
69+
- name: Build image
70+
id: build-image
71+
uses: redhat-actions/buildah-build@v2
72+
with:
73+
image: quay.io/${{ env.REPO_NAME }}/training-operator
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
platforms: linux/amd64,linux/arm64
77+
containerfiles: |
78+
build/images/training-operator/Dockerfile.multiarch
79+
extra-args: |
80+
--pull
81+
82+
# Check if image is build
83+
- name: Check images created
84+
shell: bash
85+
run: buildah images | grep 'quay.io/${{ env.REPO_NAME }}/training-operator'
86+
87+
- name: Check image manifest
88+
shell: bash
89+
run: |
90+
buildah manifest inspect ${{ steps.build-image.outputs.image }}:latest
91+
92+
93+
- name: Check image metadata
94+
shell: bash
95+
run: |
96+
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
97+
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
98+
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
99+
buildah inspect ${{ steps.build-image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'
100+
101+
- name: Login to Quay.io
102+
id: podman-login-quay
103+
# Trigger step only for specific branch (master, v.*-branch) or tag (v.*).
104+
if: (github.ref == 'refs/heads/dev' || (startsWith(github.ref, 'refs/heads/v') && endsWith(github.ref, '-branch')) || startsWith(github.ref, 'refs/tags/v'))
105+
shell: bash
106+
run: |
107+
podman login --username ${{ secrets.QUAY_USERNAME }} --password ${{ secrets.QUAY_TOKEN }} quay.io
108+
109+
- name: Push to Quay.io
110+
if: always() && steps.podman-login-quay.outcome == 'success'
111+
id: push-to-quay
112+
uses: redhat-actions/push-to-registry@v2
113+
with:
114+
image: ${{ steps.build-image.outputs.image }}
115+
tags: ${{ steps.build-image.outputs.tags }}
116+
117+
- name: Print image url
118+
if: steps.push-to-quay.outcome == 'success'
119+
shell: bash
120+
run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}"
121+
122+
- name: Logout from Quay.io
123+
if: always() && steps.podman-login-quay.outcome == 'success'
124+
run: |
125+
podman logout quay.io
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.9
2+
ARG TARGETARCH
3+
WORKDIR /
4+
COPY ./manager-${TARGETARCH} ./manager
5+
USER 65532:65532
6+
7+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)