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