-
Notifications
You must be signed in to change notification settings - Fork 43
143 lines (138 loc) · 6.39 KB
/
workflow-docker-schedule.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
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
140
141
142
143
name: workflow-docker-schedule
on:
schedule:
# run at midnight on day 7 of every other month
- cron: "0 0 7 */2 *"
push:
tags:
- '*'
jobs:
gcr-dockerhub-build-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU for multi-arch support
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Login to Quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Login to GitLab
uses: docker/login-action@v3
with:
registry: registry.gitlab.com
username: ${{ secrets.GITLAB_USERNAME }}
password: ${{ secrets.GITLAB_TOKEN }}
- name: Sync GitHub README.md with Docker Hub
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }} # NOTE: This MUST be the password NOT the token
repository: ${{ github.repository }}
short-description: ${{ github.event.repository.description }}
- name: DEBUG Show Runners environment
shell: bash
run: |
export
- name: Identify GitHub Release tag name
# if action triggered by schedule then generate tag name from date with '01 appended'
# elif action triggered by creation of release then use tag name specified by user
# elif action triggered manually then use tag name specified by user
# else unknown trigger
shell: bash
run: |
if [[ "${GITHUB_EVENT_NAME}" == "schedule" ]]; then
tag=$(date +%Y%m%d01)
echo "[debug] Generated tag name is '${tag}'"
echo "tag=$tag" >> "${GITHUB_OUTPUT}"
elif [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
tag="${GITHUB_REF_NAME}" && echo "tag=${tag//+/-}" >> "${GITHUB_OUTPUT}"
echo "[debug] Generated tag name is '${tag}'"
echo "tag=$tag" >> "${GITHUB_OUTPUT}"
elif [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
tag="${{ github.event.inputs.tags }}" && echo "tag=${tag//+/-}" >> "${GITHUB_OUTPUT}"
echo "[debug] Generated tag name is '${tag}'"
echo "tag=$tag" >> "${GITHUB_OUTPUT}"
else
echo "[error] Unable to determine event name"
exit 1
fi
id: identify_github_release_tag_name
- name: Generate temporary tag name
shell: bash
run: |
test_tag=$(date +%Y%m%d%H%M%S)
echo "[debug] Generated test tag name is '${test_tag}'"
echo "test_tag=$test_tag" >> $GITHUB_OUTPUT
id: generate_temporary_tag_name
- name: Generate app name
shell: bash
run: |
app_name=$(echo "${GITHUB_REPOSITORY}" | grep -P -o -m 1 '(?<=/arch-).*')
echo "[debug] Generated app name is '${app_name}'"
echo "app_name=$app_name" >> $GITHUB_OUTPUT
id: generate_app_name
- name: Build amd64 image and export to Docker for testing
uses: Wandalen/wretry.action@v3
with:
action: docker/build-push-action@v6
with: |
context: .
load: true
platforms: linux/amd64
tags: ghcr.io/${{ github.repository }}:${{ steps.generate_temporary_tag_name.outputs.test_tag }}
build-args: |
RELEASETAG=${{ steps.identify_github_release_tag_name.outputs.tag }}
attempt_limit: 3
attempt_delay: 600000
- name: Run tests using previously built image
shell: bash
run: |
git_clone_scripts_dest="/tmp/scripts"
git_clone_scripts_repo="https://github.com/binhex/scripts.git"
git clone "${git_clone_scripts_repo}" "${git_clone_scripts_dest}"
"${git_clone_scripts_dest}/shell/arch/docker/testrunner.sh" --app-name ${{ steps.generate_app_name.outputs.app_name }} --image-name "ghcr.io/${{ github.repository }}:${{ steps.generate_temporary_tag_name.outputs.test_tag }}"
# note this will re-use the internal cached amd64 image from the previous build
- name: Build multi-arch Docker image, tag and push to registries
uses: Wandalen/wretry.action@v3
with:
action: docker/build-push-action@v6
with: |
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ github.repository }}:latest, ${{ github.repository }}:${{ steps.identify_github_release_tag_name.outputs.tag }}, quay.io/${{ github.repository }}:latest, quay.io/${{ github.repository }}:${{ steps.identify_github_release_tag_name.outputs.tag }}, ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:${{ steps.identify_github_release_tag_name.outputs.tag }}, registry.gitlab.com/${{ github.repository }}:latest, registry.gitlab.com/${{ github.repository }}:${{ steps.identify_github_release_tag_name.outputs.tag }}
build-args: |
RELEASETAG=${{ steps.identify_github_release_tag_name.outputs.tag }}
attempt_limit: 3
attempt_delay: 600000
- name: Trigger build of int images
uses: Wandalen/wretry.action@v3
with:
command: |
# login to github
echo "${{ secrets.TDB_PAT }}" | gh auth login --with-token
# construct array of repos to trigger builds for
declare -a int_repos_array=("arch-int-vpn" "arch-int-gui" "arch-devel")
# process repos and create release (triggers action to build)
for int_repo in "${int_repos_array[@]}"; do
# create release using gh cli
# note --target is not specified as it maybe 'main' or 'master'
gh release create "${{ steps.identify_github_release_tag_name.outputs.tag }}" --repo "binhex/${int_repo}" --notes "API/URL triggered release"
done