-
Notifications
You must be signed in to change notification settings - Fork 6
119 lines (111 loc) · 3.89 KB
/
reusable_workflow.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
name: ACT Reusable Workflow to Build and Push Image
on:
workflow_call:
inputs:
image_name:
required: true
type: string
image_tag:
required: true
type: string
quay_img_exp:
required: false
type: string
quay_custom_namespace:
required: false
type: string
github_username:
required: false
type: string
github_namespace:
required: false
type: string
archetype:
required: false
type: string
multi_arch:
required: false
type: boolean
build_platforms:
required: false
type: string
default: linux/amd64, linux/arm64
secrets:
QUAY_NAMESPACE:
required: false
QUAY_USERNAME:
required: false
QUAY_PASSWORD:
required: false
env:
QUAY_TAG_ROOT: quay.io/${{ secrets.QUAY_NAMESPACE }}/${{ inputs.image_name }}
QUAY_IMG_EXP: 0
jobs:
act-build:
name: Build ${{ github.ref_name }} from ${{ github.event_name }}
runs-on: ubuntu-latest
steps:
- name: Set image tags
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
# Set image tags for release builds
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:${GITHUB_REF#refs/*/} ${{ env.QUAY_TAG_ROOT }}:latest"
elif [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
# Set image tags for main branch builds
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:main_latest"
else
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
# Set image tags for pull request builds
bname=${{ github.head_ref }}
else
# Set image tags for any other builds (such as tags)
bname=${GITHUB_REF##*/}
fi
commit_hash=${{ github.sha }}
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:${bname}_${commit_hash:0:7}"
# Builds other than main and releases get automatic expiration
echo "QUAY_IMG_EXP=90d" >> $GITHUB_ENV
fi
echo "IMAGE_TAGS=${IMAGE_TAGS}" | tee -a $GITHUB_ENV
- name: Checkout this project
uses: actions/checkout@v4
- name: arcaflow-container-toolkit-action
uses: arcalot/[email protected]
with:
image_name: ${{ inputs.image_name }}
image_tag: ${{ inputs.image_tag }}
github_username: ${{ inputs.github_username }}
github_password: ${{ secrets.GITHUB_TOKEN }}
github_namespace: ${{ inputs.github_namespace }}
quay_username: ${{ secrets.QUAY_USERNAME }}
quay_password: ${{ secrets.QUAY_PASSWORD }}
quay_namespace: ${{ secrets.QUAY_NAMESPACE }}
quay_custom_namespace: ${{ inputs.quay_custom_namespace }}
quay_img_exp: ${{ inputs.quay_img_exp }}
build_timeout: ${{ inputs.build_timeout }}
archetype: ${{ inputs.archetype }}
req_check_only: ${{ inputs.multi_arch }}
- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Log in to quay.io
uses: redhat-actions/podman-login@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build multi-arch image
id: build-multi-arch
uses: redhat-actions/buildah-build@v2
with:
context: .
platforms: ${{ inputs.build_platforms }}
tags: ${{ env.IMAGE_TAGS }}
containerfiles: ./Dockerfile
labels: quay.expires-after=${{ env.QUAY_IMG_EXP }}
- name: Push image to quay.io
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-multi-arch.outputs.image }}
tags: ${{ steps.build-multi-arch.outputs.tags }}