-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
215 lines (197 loc) · 8.08 KB
/
action.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: 'Deploy BlueOS Extension'
description: 'An Action to build and deploy a BlueOS Extension as a docker image.'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
docker-username:
description: 'Your username for your Docker registry of choice*.
Should be stored in a GitHub Action Secret.
*Currently only Docker Hub is supported.'
required: true
docker-password:
description: 'The password for your Docker registry authentication.
Should be stored in a GitHub Action Secret.'
required: true
github-token:
description: 'Your authentification token for GitHub, for uploading image artifacts to a release.
Should be set to secrets.GITHUB_TOKEN.'
required: true
build-platforms:
description: 'A comma-separated string of the architectures to build for.
Defaults to the ones BlueOS is automatically built for.'
default: 'linux/arm/v7,linux/arm64/v8,linux/amd64'
image-name:
description: 'The base name for the Docker Images and GitHub Artifacts.'
required: true
image-prefix:
description: 'An optional prefix for the Docker Image name.'
default: 'blueos-'
author:
default: 'Author Name'
author-email:
default: '[email protected]'
maintainer:
description: 'The maintaining organisation or developer.'
default: ${{ github.repository_owner }}
maintainer-email:
default: '[email protected]'
dockerfile-location:
description: 'The location of the Dockerfile to be used for the build.'
default: '.'
required: false
skip-checkout:
description: 'Skip the checkout step (e.g. if files are already present).'
default: 'false'
runs:
using: 'composite'
steps:
- name: Checkout
if: ${{ inputs.skip-checkout != 'true' }}
uses: actions/checkout@v3
with:
fetch-depth: 0 #Number of commits to fetch. 0 indicates all history for all branches and tags
- name: Prepare
id: prepare
run: |
[ -z "${{inputs.docker-username}}" ] && echo "Error: Docker username is empty" && exit 1
[ -z "${{inputs.docker-password}}" ] && echo "Error: Docker password is empty" && exit 1
# Deploy image with the name of the branch, if the build is a git tag replace tag with the tag name.
# If the git tag is in SemVer format, append the "latest" tag to the image
DOCKER_IMAGE=${{ inputs.docker-username }}/${{ inputs.image-prefix }}${{ inputs.image-name }}
VERSION=${GITHUB_REF##*/}
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
TAGS="--tag ${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest"
fi
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "buildx_args=\
--build-arg IMAGE_NAME='${{ inputs.image-name }}' \
--build-arg AUTHOR='${{ inputs.author }}' \
--build-arg AUTHOR_EMAIL='${{ inputs.author_email }}' \
--build-arg MAINTAINER='${{ inputs.maintainer }}' \
--build-arg MAINTAINER_EMAIL='${{ inputs.maintainer-email }}' \
--build-arg REPO='${{ github.repository }}' \
--build-arg OWNER='${{ github.repository_owner }}' \
--cache-from 'type=local,src=/tmp/.buildx-cache' \
--cache-to 'type=local,dest=/tmp/.buildx-cache' \
${TAGS} \
--file '${{ inputs.dockerfile-location }}/Dockerfile' ." >> $GITHUB_OUTPUT
shell: bash
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
- name: Cache Docker layers
uses: actions/cache@v3
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ inputs.image-name }}-${{ hashFiles('Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-${{ inputs.image-name }}-${{ hashFiles('Dockerfile') }}
${{ runner.os }}-buildx-${{ inputs.image-name }}
- name: Docker Buildx (build)
run: |
# Pull latest development version of image (from main/master branch) to help with build speed
for platform in $(echo ${{ inputs.platforms }} | tr ',' '\n'); do
docker pull --platform '${{ inputs.build-platforms }}' \
${{ inputs.docker-username }}/${{ inputs.image-prefix }}${{ inputs.image-name }}:${{ github.event.repository.default_branch }} || true
done
docker buildx build \
--output "type=image,push=false" \
--platform '${{ inputs.build-platforms }}' \
${{ steps.prepare.outputs.buildx_args }}
shell: bash
- name: Login to DockerHub
if: success()
uses: docker/login-action@v3
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}
- name: Docker Buildx (push)
if: success()
run: |
docker buildx build \
--output "type=image,push=true" \
--platform '${{ inputs.build-platforms }}' \
${{ steps.prepare.outputs.buildx_args }}
shell: bash
# Sanity check - if inspection fails something has gone very wrong
- name: Inspect image
run: |
docker buildx imagetools \
inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
shell: bash
- name: Create image artifact
if: success()
run: |
PREFIXED_IMAGE=${{ inputs.image-prefix }}${{ inputs.image-name }}
DOCKER_IMAGE=${{ inputs.docker-username }}/${PREFIXED_IMAGE}
GIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA")
docker buildx build \
${{ steps.prepare.outputs.buildx_args }} \
--platform "linux/arm64/v8" \
--tag ${DOCKER_IMAGE}:${GIT_HASH_SHORT} \
--output "type=docker,dest=${PREFIXED_IMAGE}-docker-image-${GIT_HASH_SHORT}-arm64-v8.tar"
shell: bash
- name: Upload artifact arm64-v8
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{ inputs.image-prefix }}${{ inputs.image-name }}-docker-image-arm64-v8
path: '*arm64-v8.tar'
- name: Create image artifact
if: success()
run: |
PREFIXED_IMAGE=${{ inputs.image-prefix }}${{ inputs.image-name }}
DOCKER_IMAGE=${{ inputs.docker-username }}/${PREFIXED_IMAGE}
GIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA")
docker buildx build \
${{ steps.prepare.outputs.buildx_args }} \
--platform "linux/arm/v7" \
--tag ${DOCKER_IMAGE}:${GIT_HASH_SHORT} \
--output "type=docker,dest=${PREFIXED_IMAGE}-docker-image-${GIT_HASH_SHORT}-arm-v7.tar"
shell: bash
- name: Upload artifact arm-v7
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{ inputs.image-prefix }}${{ inputs.image-name }}-docker-image-arm-v7
path: '*arm-v7.tar'
- name: Create image artifact
if: success()
run: |
PREFIXED_IMAGE=${{ inputs.image-prefix }}${{ inputs.image-name }}
DOCKER_IMAGE=${{ inputs.docker-username }}/${PREFIXED_IMAGE}
GIT_HASH_SHORT=$(git rev-parse --short "$GITHUB_SHA")
docker buildx build \
${{ steps.prepare.outputs.buildx_args }} \
--platform "linux/amd64" \
--tag ${DOCKER_IMAGE}:${GIT_HASH_SHORT} \
--output "type=docker,dest=${PREFIXED_IMAGE}-docker-image-${GIT_HASH_SHORT}-amd64.tar"
shell: bash
- name: Upload artifact amd64
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{ inputs.image-prefix }}${{ inputs.image-name }}-docker-image-amd64
path: '*amd64.tar'
- name: Upload docker image for release
uses: svenstaro/upload-release-action@v2
if: startsWith(github.ref, 'refs/tags') && success()
with:
repo_token: ${{ inputs.github-token }}
file: '*.tar'
tag: ${{ github.ref }}
overwrite: true
prerelease: true
file_glob: true