-
-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathnew-ubuntu-base-image-requested.yml
More file actions
139 lines (133 loc) · 5.58 KB
/
Copy pathnew-ubuntu-base-image-requested.yml
File metadata and controls
139 lines (133 loc) · 5.58 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
132
133
134
135
136
137
138
139
name: New Ubuntu Base Version ⛭
on:
repository_dispatch:
types:
- new_base_images_requested
- new_ubuntu_base_image_requested
# Further reading:
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch
# https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-a-repository-dispatch-event
# https://developer.github.com/webhooks/event-payloads/#repository_dispatch
jobs:
build:
name: "🛠 Build unityci/base"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Checkout latest release tag
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $LATEST_TAG
#################
# Variables #
#################
- name: Show hook input
run: |
echo "Event ${{ github.event.action }}"
echo "jobId: ${{ github.event.client_payload.jobId }}"
echo "repoVersion (full): ${{ github.event.client_payload.repoVersionFull }}"
echo "repoVersion (only minor and major): ${{ github.event.client_payload.repoVersionMinor }}"
echo "repoVersion (only major): ${{ github.event.client_payload.repoVersionMajor }}"
- name: Report new build
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: started
# Build info
imageType: base
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
#############
# Setup #
#############
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if image does not already exist
id: check-image
run: |
# DockerHub V2 API (V1 was decommissioned, returns 410 Gone)
function docker_tag_exists() {
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null
}
if docker_tag_exists unityci/base ubuntu-${{ github.event.client_payload.repoVersionFull }} ; then
echo "Image already exists. Exiting."
echo "image_exists=true" >> $GITHUB_OUTPUT
exit 1
fi
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-base-${{ github.sha }}
restore-keys: |
${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-base
${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-
##################
# Base image #
##################
- name: Build and publish
uses: docker/build-push-action@v5
id: build_ubuntu_base_image
with:
file: ./images/ubuntu/base/Dockerfile
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
push: true
tags: |
unityci/base:ubuntu-${{ github.event.client_payload.repoVersionFull }}
unityci/base:${{ github.event.client_payload.repoVersionFull }}
unityci/base:ubuntu-${{ github.event.client_payload.repoVersionMinor }}
unityci/base:${{ github.event.client_payload.repoVersionMinor }}
unityci/base:ubuntu-${{ github.event.client_payload.repoVersionMajor }}
unityci/base:${{ github.event.client_payload.repoVersionMajor }}
unityci/base:ubuntu-latest
unityci/base:latest
- name: Inspect
run: |
docker buildx imagetools inspect unityci/base:ubuntu-${{ github.event.client_payload.repoVersionFull }}
- name: Image digest
run: echo ${{ steps.build_ubuntu_base_image.outputs.digest }}
#################
# reporting #
#################
- name: Report publication
if: ${{ success() }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: published
# Build info
imageType: base
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
# Publication info
imageRepo: unityci
imageName: base
friendlyTag: ${{ github.event.client_payload.repoVersionMinor }}
specificTag: ubuntu-${{ github.event.client_payload.repoVersionFull }}
digest: ${{ steps.build_ubuntu_base_image.outputs.digest }}
- name: Report failure
if: ${{ (failure() || cancelled()) && steps.check-image.outputs.image_exists != 'true' }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: failed
# Build info
imageType: base
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
# Failure info
reason: ${{ job.status }} - ${{ steps.build_ubuntu_base_image.outputs.metadata }}