Skip to content

Commit eec31bb

Browse files
committed
feat: add on-demand build ci
Signed-off-by: Sunyanan Choochotkaew <sunyanan.choochotkaew1@ibm.com>
1 parent aad2ecb commit eec31bb

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

.github/workflows/build_push.yaml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: On-demand build
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: 'branch/tag to checkout'
8+
required: true
9+
default: 'main'
10+
version:
11+
description: 'image version'
12+
required: true
13+
go_version:
14+
description: 'go version'
15+
required: true
16+
sdk_version:
17+
description: 'operator-sdk version'
18+
required: true
19+
20+
env:
21+
GO_VERSION: ${{ github.event.inputs.go_version }}
22+
SDK_VERSION: ${{ github.event.inputs.sdk_version }}
23+
VERSION: ${{ github.event.inputs.version }}
24+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
25+
DAEMON_REGISTRY: ghcr.io/${{ github.repository_owner }}
26+
27+
jobs:
28+
build-push-controller:
29+
runs-on: ubuntu-latest
30+
env:
31+
IMAGE_NAME: ghcr.io/${{ github.repository }}-controller
32+
steps:
33+
- name: Checkout selected branch or tag
34+
uses: actions/checkout@v4
35+
with:
36+
ref: ${{ github.event.inputs.branch }}
37+
38+
- uses: actions/setup-go@v2
39+
with:
40+
go-version: ${{ env.GO_VERSION }}
41+
- name: Tidy
42+
run: |
43+
go mod tidy
44+
make generate fmt vet
45+
- name: Set up Docker
46+
uses: docker/setup-buildx-action@v1
47+
- name: Login to Docker
48+
uses: docker/login-action@v1
49+
with:
50+
registry: ghcr.io
51+
username: ${{ secrets.GH_USERNAME }}
52+
password: ${{ secrets.GHCR_TOKEN }}
53+
- name: Build and push controller
54+
uses: docker/build-push-action@v2
55+
with:
56+
context: .
57+
push: true
58+
tags: |
59+
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
60+
file: ./Dockerfile
61+
build-push-bundle:
62+
runs-on: ubuntu-latest
63+
needs: build-push-controller
64+
env:
65+
BUNDLE_IMAGE_NAME: ghcr.io/${{ github.repository }}-bundle
66+
CHANNELS: beta
67+
steps:
68+
- name: Checkout selected branch
69+
uses: actions/checkout@v4
70+
with:
71+
ref: ${{ github.event.inputs.branch }}
72+
- uses: actions/setup-go@v2
73+
with:
74+
go-version: ${{ env.GO_VERSION }}
75+
- name: set ARCH and OD
76+
run: |
77+
echo "ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)" >> $GITHUB_ENV
78+
echo "OS=$(uname | awk '{print tolower($0)}')" >> $GITHUB_ENV
79+
echo "OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v${{ env.SDK_VERSION }}" >> $GITHUB_ENV
80+
- name: download operator-sdk
81+
run: curl -LO ${{ env.OPERATOR_SDK_DL_URL }}/operator-sdk_${{ env.OS }}_${{ env.ARCH }}
82+
- name: move operator-sdk to binary path
83+
run: chmod +x operator-sdk_${{ env.OS }}_${{ env.ARCH }} && sudo mv operator-sdk_${{ env.OS }}_${{ env.ARCH }} /usr/local/bin/operator-sdk
84+
- name: Tidy
85+
run: |
86+
go mod tidy
87+
- name: Make bundle
88+
run: make bundle
89+
- name: Set up Docker
90+
uses: docker/setup-buildx-action@v1
91+
- name: Login to Docker
92+
uses: docker/login-action@v1
93+
with:
94+
registry: ghcr.io
95+
username: ${{ secrets.GH_USERNAME }}
96+
password: ${{ secrets.GHCR_TOKEN }}
97+
- name: Build and push bundle
98+
uses: docker/build-push-action@v2
99+
with:
100+
context: .
101+
push: true
102+
tags: |
103+
${{ env.BUNDLE_IMAGE_NAME }}:v${{ env.VERSION }}
104+
file: ./bundle.Dockerfile
105+
build-push-daemon:
106+
runs-on: ubuntu-latest
107+
env:
108+
IMAGE_NAME: ghcr.io/${{ github.repository }}-daemon
109+
steps:
110+
- name: Checkout selected branch
111+
uses: actions/checkout@v4
112+
with:
113+
ref: ${{ github.event.inputs.branch }}
114+
- uses: actions/setup-go@v2
115+
with:
116+
go-version: ${{ env.GO_VERSION }}
117+
- name: Set up Docker
118+
uses: docker/setup-buildx-action@v1
119+
- name: Update CNI
120+
run: make update-cni-local
121+
working-directory: daemon
122+
- name: Login to Docker
123+
uses: docker/login-action@v1
124+
with:
125+
registry: ghcr.io
126+
username: ${{ secrets.GH_USERNAME }}
127+
password: ${{ secrets.GHCR_TOKEN }}
128+
- name: Build and push daemon
129+
uses: docker/build-push-action@v2
130+
with:
131+
context: daemon
132+
push: true
133+
tags: |
134+
${{ env.IMAGE_NAME }}:v${{ env.VERSION }}
135+
file: ./daemon/dockerfiles/Dockerfile

0 commit comments

Comments
 (0)