-
Notifications
You must be signed in to change notification settings - Fork 6
131 lines (112 loc) · 4.54 KB
/
Copy pathbuild-container-images.yaml
File metadata and controls
131 lines (112 loc) · 4.54 KB
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
name: Container image building
on:
push:
tags:
- 'v*.*.*'
pull_request:
branches:
- main
jobs:
setup:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
SHA_COMMIT: ${{ steps.vars.outputs.SHA_COMMIT }}
GIT_TAG: ${{ steps.vars.outputs.GIT_TAG }}
BRANCH: ${{ steps.vars.outputs.BRANCH }}
LATEST_TAG: ${{ steps.vars.outputs.LATEST_TAG }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for getting Git Tags
- name: Determine Image Tags
id: vars
run: |
# Checking if the event comes from PR or Branch
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR values
SHA_COMMIT=$(echo ${{ github.event.pull_request.head.sha }})
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
echo "Changes comming from PR: $BRANCH_NAME/$SHA_COMMIT"
else
# Push values
SHA_COMMIT=$(echo ${{ github.sha }})
BRANCH_NAME=${GITHUB_REF##*/}
echo "Changes comming from Push: $BRANCH_NAME/$SHA_COMMIT"
fi
echo "SHA_COMMIT=$SHA_COMMIT" >> $GITHUB_OUTPUT
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
# Getting LATEST_TAG
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
LATEST_TAG="latest"
fi
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
# Getting version tag if available
GIT_TAG=$(git tag --points-at HEAD | head -n 1)
if [[ -n "$GIT_TAG" ]]; then
echo "Detected Git Tag: $GIT_TAG"
else
GIT_TAG="$SHA_COMMIT"
fi
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_OUTPUT
echo "Building Tags:"
echo " * SHA_COMMIT: ${SHA_COMMIT}"
echo " * BRANCH_NAME: ${BRANCH_NAME}"
echo " * GIT TAG: ${GIT_TAG}"
if [[ $LATEST_TAG == "latest" ]]; then
echo " * Including 'latest' tag"
fi
console:
runs-on: ubuntu-latest
needs: setup
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Quay.io
run: |
echo "${{ secrets.QUAY_PASSWORD }}" | podman login quay.io -u "${{ secrets.QUAY_USERNAME }}" --password-stdin
- name: Container image building
run: |
echo "Building ClusterIQ Console (${{ needs.setup.outputs.BRANCH }}/${{ needs.setup.outputs.SHA_COMMIT }})"
podman build \
--platform linux/amd64 \
--build-arg VERSION=${{ needs.setup.outputs.GIT_TAG }} \
--build-arg COMMIT=${{ needs.setup.outputs.SHA_COMMIT }} \
-t quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.SHA_COMMIT }} \
-f ./deployments/containerfiles/Containerfile .
- name: Pushing Hash based image
run: |
podman push quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.SHA_COMMIT }}
- name: Tagging and Pushing Latest Image
if: ${{ needs.setup.outputs.LATEST_TAG != '' && needs.setup.outputs.LATEST_TAG != null }}
run: |
podman tag \
quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.SHA_COMMIT }} \
quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.LATEST_TAG }}
podman push quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.LATEST_TAG }}
- name: Tagging and Puhsing GitTag based image
if: ${{ needs.setup.outputs.GIT_TAG != '' && needs.setup.outputs.GIT_TAG != null }}
run: |
echo "Building Tagged version image: ${{ needs.setup.outputs.GIT_TAG }}"
podman tag \
quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.SHA_COMMIT }} \
quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.GIT_TAG }}
podman push quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.GIT_TAG }}
- name: Logout from Quay.io
run: |
podman logout quay.io
final:
runs-on: ubuntu-latest
needs:
- setup
- console
steps:
- name: Validating
run: |
podman pull quay.io/${{ secrets.QUAY_ORG_NAME }}/cluster-iq-console:${{ needs.setup.outputs.SHA_COMMIT }}