-
Notifications
You must be signed in to change notification settings - Fork 23
116 lines (98 loc) · 3.97 KB
/
docker-build-upload.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
name: Download a parent image, build a new one, tag it, then upload the image
env:
HADOLINT_VERSION: "2.12.0"
on:
workflow_call:
inputs:
parent-image:
description: Parent image name
required: true
type: string
directory:
description: The directory of the image files
required: true
type: string
image:
description: Image name
required: true
type: string
base-image:
description: The base image to build from if not located on our own repo
required: false
type: string
registry-name:
description: url of the registry <registy-name>
required: true
type: string
buildkit:
description: buildkit version, legacy is 0 and deprecated
required: true
type: number
branch-name:
description: The name of the current branch
required: true
type: string
secrets:
REGISTRY_USERNAME:
description: The username for the container registry
required: true
REGISTRY_PASSWORD:
description: The password for the container registry
required: true
jobs:
build-upload:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- uses: actions/checkout@v4
- name: Echo disk usage before clean up
run: ./.github/scripts/echo_usage.sh
- name: Free up all available disk space before building
run: ./.github/scripts/cleanup_runner.sh
- name: Echo disk usage before build start
run: ./.github/scripts/echo_usage.sh
# Connect to Azure Container registry (ACR)
- uses: azure/docker-login@v1
with:
login-server: ${{ inputs.registry-name }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Pull parent image
id: pull-parent
if: inputs.parent-image != ''
run: make pull/${{ inputs.parent-image }} REPO=${{ inputs.registry-name }}
- name: Set BASE_IMAGE variable
run: |
if [ "${{ inputs.base-image }}" == "" ]; then
echo "BASE_IMAGE=${{ steps.pull-parent.outputs.image_name }}" >> $GITHUB_ENV
else
echo "BASE_IMAGE=${{ inputs.base-image }}" >> $GITHUB_ENV
fi
- name: Set FROM and as in Docerfile
run: |
sed -i '1i FROM ${{ env.BASE_IMAGE}} as ${{ inputs.image }}' ./images/${{ inputs.directory }}/Dockerfile
- name: Run Hadolint
run: |
sudo curl -L https://github.com/hadolint/hadolint/releases/download/v${{ env.HADOLINT_VERSION }}/hadolint-Linux-x86_64 --output hadolint
sudo chmod +x hadolint
./hadolint images/${{ inputs.directory }}/Dockerfile --failure-threshold error
# make build emits full_image_name, image_tag, and image_repo outputs
- name: Build image
id: build-image
run: make build/${{ inputs.image }} REPO=${{ inputs.registry-name }} DIRECTORY=${{ inputs.directory }} BUILDKIT=${{ inputs.buildkit }}
- name: Echo disk usage after build completion
run: ./.github/scripts/echo_usage.sh
- name: Add standard tags (short sha, sha, and branch) and any other post-build activity
if: ${{ inputs.branch-name != 'master' }}
run: make post-build/${{ inputs.image }} REPO=${{ inputs.registry-name }}
- name: Add master and standard tags (v1, latest; short sha, sha, and branch) and any other post-build activity
if: ${{ inputs.branch-name == 'master' }}
run: make post-build/${{ inputs.image }} REPO=${{ inputs.registry-name }} IMAGE_VERSION=v1 IS_LATEST=true
- name: Push image to registry (default pushes all tags)
run: make push/${{ inputs.image }} REPO=${{ inputs.registry-name }}
# Free up space from build process (containerscan action will run out of space if we don't)
- run: ./.github/scripts/cleanup_runner.sh