1+ name : Build container
2+
3+ on :
4+ push :
5+ branches :
6+ - ' main'
7+ - ' [0-9]+.[1-9][0-9]*.x'
8+ pull_request :
9+ branches :
10+ - ' main'
11+ - ' [0-9]+.[1-9][0-9]*.x'
12+ paths-ignore :
13+ - " **.md"
14+ workflow_dispatch :
15+
16+ env :
17+ GO_VERSION : " ~1.20"
18+ IMAGE_NAME : " valid8or-plugin-aws"
19+ defaults :
20+ run :
21+ shell : bash
22+
23+ jobs :
24+ prepare_ci_run :
25+ name : Prepare CI Run
26+ runs-on : ubuntu-22.04
27+ outputs :
28+ GIT_SHA : ${{ steps.extract_branch.outputs.GIT_SHA }}
29+ BRANCH : ${{ steps.extract_branch.outputs.BRANCH }}
30+ BRANCH_SLUG : ${{ steps.extract_branch.outputs.BRANCH_SLUG }}
31+ DATETIME : ${{ steps.get_datetime.outputs.DATETIME }}
32+ BUILD_TIME : ${{ steps.get_datetime.outputs.BUILD_TIME }}
33+ NON_FORKED_AND_NON_ROBOT_RUN : ${{ steps.get_run_type.outputs.NON_FORKED_AND_NON_ROBOT_RUN }}
34+
35+ steps :
36+ - name : Check out code
37+ uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
38+
39+ - name : Extract branch name
40+ id : extract_branch
41+ uses : keptn/gh-action-extract-branch-name@main
42+
43+ - name : Get current date and time
44+ id : get_datetime
45+ run : |
46+ DATETIME=$(date +'%Y%m%d%H%M')
47+ BUILD_TIME=$(date -u "+%F_%T")
48+ echo "DATETIME=$DATETIME" >> "$GITHUB_OUTPUT"
49+ echo "BUILD_TIME=$BUILD_TIME" >> "$GITHUB_OUTPUT"
50+
51+ - name : Get workflow run type
52+ id : get_run_type
53+ run : |
54+ NON_FORKED_AND_NON_ROBOT_RUN=${{ ( github.actor != 'renovate[bot]' && github.actor != 'dependabot[bot]' ) && ( github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository ) }}
55+ echo "github.actor != 'renovate[bot]' = ${{ github.actor != 'renovate[bot]' }}"
56+ echo "github.actor != 'dependabot[bot]' = ${{ github.actor != 'dependabot[bot]' }}"
57+ echo "github.event_name == 'push' = ${{ github.event_name == 'push' }}"
58+ echo "github.event.pull_request.head.repo.full_name == github.repository = ${{ github.event.pull_request.head.repo.full_name == github.repository }}"
59+ echo "NON_FORKED_AND_NON_ROBOT_RUN = $NON_FORKED_AND_NON_ROBOT_RUN"
60+ echo "NON_FORKED_AND_NON_ROBOT_RUN=$NON_FORKED_AND_NON_ROBOT_RUN" >> "$GITHUB_OUTPUT"
61+
62+ build_image :
63+ name : Build Container Image
64+ needs : prepare_ci_run
65+ runs-on : ubuntu-22.04
66+ env :
67+ BRANCH : ${{ needs.prepare_ci_run.outputs.BRANCH }}
68+ DATETIME : ${{ needs.prepare_ci_run.outputs.DATETIME }}
69+ BUILD_TIME : ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
70+ GIT_SHA : ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
71+ RELEASE_REGISTRY : " localhost:5000/valid8or-plugin-aws"
72+ steps :
73+ - name : Check out code
74+ uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
75+
76+ - name : Set up Docker Buildx
77+ id : buildx
78+ uses : docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2
79+
80+ - name : Build Docker Image
81+ uses : docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
82+ with :
83+ context : .
84+ platforms : linux/amd64
85+ file : ./Dockerfile
86+ target : production
87+ tags : |
88+ ${{ env.RELEASE_REGISTRY }}/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }}
89+ build-args : |
90+ GIT_HASH=${{ env.GIT_SHA }}
91+ RELEASE_VERSION=dev-${{ env.DATETIME }}
92+ BUILD_TIME=${{ env.BUILD_TIME }}
93+ builder : ${{ steps.buildx.outputs.name }}
94+ push : false
95+ cache-from : type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
96+ cache-to : type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
97+ outputs : type=docker,dest=/tmp/${{ env.IMAGE_NAME }}-image.tar
98+
99+ - name : Upload image as artifact
100+ uses : actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3
101+ with :
102+ name : ${{ env.IMAGE_NAME }}-image.tar
103+ path : /tmp/${{ env.IMAGE_NAME }}-image.tar
104+
105+ upload_images :
106+ name : Upload images to quay registry
107+ needs : [ prepare_ci_run, build_image ]
108+ if : github.event_name == 'push' && needs.prepare_ci_run.outputs.NON_FORKED_AND_NON_ROBOT_RUN == 'true' # only run on push to main/maintenance branches
109+ runs-on : ubuntu-22.04
110+ env :
111+ DATETIME : ${{ needs.prepare_ci_run.outputs.DATETIME }}
112+ BUILD_TIME : ${{ needs.prepare_ci_run.outputs.BUILD_TIME }}
113+ GIT_SHA : ${{ needs.prepare_ci_run.outputs.GIT_SHA }}
114+ permissions :
115+ packages : write # Needed for pushing images to the registry
116+ contents : read # Needed for checking out the repository
117+ steps :
118+ - name : Check out code
119+ uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
120+
121+ - name : Login to GitHub Container Registry
122+ uses : docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
123+ with :
124+ registry : " quay.io"
125+ username : tgillson
126+ password : ${{ secrets.QUAY_TOKEN }}
127+
128+ - name : Set up Docker Buildx
129+ id : buildx
130+ uses : docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2
131+
132+ - name : Build Docker Image
133+ uses : docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
134+ with :
135+ context : .
136+ file : ./Dockerfile
137+ platforms : linux/amd64,linux/arm64
138+ target : production
139+ tags : |
140+ quay.io/spectrocloud-labs/${{ env.IMAGE_NAME }}:dev-${{ env.DATETIME }}
141+ build-args : |
142+ GIT_HASH=${{ env.GIT_SHA }}
143+ RELEASE_VERSION=dev-${{ env.DATETIME }}
144+ BUILD_TIME=${{ env.BUILD_TIME }}
145+ builder : ${{ steps.buildx.outputs.name }}
146+ push : true
147+ cache-from : type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
148+ cache-to : type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_NAME }}
0 commit comments