-
Notifications
You must be signed in to change notification settings - Fork 22
105 lines (95 loc) · 3.45 KB
/
container-image-build.yml
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
name: build-images action template
permissions: {}
on:
workflow_call:
inputs:
ref:
required: false
description: "Git reference of the workflow's trigger"
type: string
image-name:
required: true
description: "Name of the image to build"
type: string
image-tag:
required: false
description: "Override autogenerated image tag"
type: string
default: ""
dockerfile-directory:
required: false
description: "The directory where the dockerfile locates, as relative to the repo root"
type: string
default: .
pushImage:
required: false
description: "Whether to push the image afterwards"
type: boolean
default: true
secrets:
QUAY_USERNAME:
required: true
QUAY_PASSWORD:
required: true
SLACK_WEBHOOK:
required: true
jobs:
job:
runs-on: ubuntu-latest
if: github.repository_owner == 'metal3-io'
permissions:
contents: read
steps:
- name: Set GITHUB_REF and GITHUB_REFNAME to the inputs' ref, or default to github's ref
id: set_ref
run: |
REF="${{ inputs.ref || github.ref }}"
echo "Using INPUT REF: ${REF}"
REF_NAME="${REF#refs/heads/}"
REF_NAME="${REF_NAME#refs/tags/}"
echo "GITHUB_REF=${REF}" >> "${GITHUB_ENV}"
echo "GITHUB_REFNAME=${REF_NAME}" >> "${GITHUB_ENV}"
echo "Using GITHUB REFNAME: ${REF_NAME}"
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ env.GITHUB_REF }}
- name: Set GITHUB_REFSHA to sha of the ref
id: set_refsha
run: |
REF_SHA=$(git rev-parse HEAD)
echo "GITHUB_REFSHA=${REF_SHA}" >> "${GITHUB_ENV}"
- name: Get current date
id: date
run: echo "current_date=$(date +'%Y-%m-%d')" >> "${GITHUB_OUTPUT}"
- name: Get image tags
id: image_tags
run: |
BASE_TAG=`echo "${{ env.GITHUB_REFNAME }}" | sed 's/\//_/'`
IMAGE_TAGS="${BASE_TAG}, ${BASE_TAG}_${{ steps.date.outputs.current_date }}_${{ env.GITHUB_REFSHA }}"
if [[ -n "${{ inputs.image-tag }}" ]]; then
IMAGE_TAGS="${{ inputs.image-tag }}"
elif [[ "${{ env.GITHUB_REF }}" == "refs/heads/main" ]]; then
IMAGE_TAGS="${IMAGE_TAGS}, latest"
fi
echo "IMAGE_TAGS=${IMAGE_TAGS}" >> "${GITHUB_ENV}"
- name: Build ${{ inputs.image-name }} image
uses: mr-smithers-excellent/docker-build-push@59523c638baec979a74fea99caa9e29d97e5963c # v6.4
with:
image: metal3-io/${{ inputs.image-name }}
tags: ${{ env.IMAGE_TAGS }}
directory: ${{ inputs.dockerfile-directory }}
dockerfile: ${{ inputs.dockerfile-directory }}/Dockerfile
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
pushImage: ${{ inputs.pushImage }}
- name: Slack Notification on Failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990 # 2.3.2
env:
SLACK_TITLE: "GitHub Action Failed in ${{ github.repository }}"
SLACK_COLOR: "#FF0000"
SLACK_MESSAGE: "The GitHub Action workflow failed for ${{ inputs.image-name }} image build."
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: metal3-github-actions-notify
SLACK_USERNAME: metal3-github-actions-notify