-
-
Notifications
You must be signed in to change notification settings - Fork 98
179 lines (162 loc) · 6.13 KB
/
build-image.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
name: Docker image CI/CD
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DOCKER_IMAGE_NAME: jlesage/handbrake
PLATFORMS: linux/amd64
on:
push:
branches:
- '*'
- '!nightly'
tags:
- v[0-9][0-9].[0-9][0-9].[0-9]+
- v[0-9][0-9].[0-9][0-9].[0-9]+-pre.[0-9]+
pull_request:
jobs:
build:
name: Build image
runs-on: ubuntu-20.04
steps:
- name: Free disk space
run: |
# Free disk space.
echo "::group::Before"
df -h /
echo "::endgroup::"
echo "::group::Removing unneeded softwares and files..."
for DIR in /usr/local/lib/android /usr/share/dotnet /opt/ghc
do
if [ -d "$DIR" ]; then
echo "Removing $DIR..."
sudo rm -r "$DIR"
fi
done
echo "::endgroup::"
echo "::group::After"
df -h /
echo "::endgroup::"
- name: Prepare
id: prep
run: |
# Determine the Docker container version.
VERSION=unknown
if [[ $GITHUB_REF =~ refs/tags/* ]]; then
# Git tag pushed: use tag as the version.
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF =~ refs/heads/* ]]; then
# Git commit pushed: use the commit SHA as the version.
VERSION=${GITHUB_SHA::8}
elif [[ $GITHUB_REF =~ refs/pull/* ]]; then
# Pull request: use PR number as the version.
VERSION=pr-${{ github.event.number }}
else
echo "::error::Unexpected GITHUB_REF: $GITHUB_REF"
exit 1
fi
# Determine the version to put in container label.
LABEL_VERSION=${VERSION}
if [[ $GITHUB_REF =~ refs/tags/* ]]; then
# Do not include the starting 'v' of the version.
LABEL_VERSION=${VERSION:1}
fi
# Determine the Docker container tags.
TAGS="${{ env.DOCKER_IMAGE_NAME }}:${VERSION}"
if [[ $GITHUB_REF =~ refs/tags/* ]]; then
TAGS="$TAGS,${{ env.DOCKER_IMAGE_NAME }}:latest"
fi
# Determine the release type.
if [[ $GITHUB_REF =~ refs/tags/* ]]; then
IS_RELEASE=yes
if [[ $GITHUB_REF =~ -pre\.[0-9]+ ]]; then
RELEASE_TYPE="pre"
else
RELEASE_TYPE="standard"
fi
else
IS_RELEASE=no
RELEASE_TYPE="n/a"
fi
# Print results.
echo "::group::Results"
echo "Github reference: $GITHUB_REF"
echo "Release: $IS_RELEASE"
echo "Release type: $RELEASE_TYPE"
echo "Docker container version: $VERSION"
echo "Docker container version label: $LABEL_VERSION"
echo "Docker container tag(s): $TAGS"
echo "::endgroup::"
# Export outputs.
echo "is_release=${IS_RELEASE}" >> $GITHUB_OUTPUT
echo "release_type=${RELEASE_TYPE}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "label_version=${LABEL_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
#echo "build_date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm,arm64,ppc64le,mips64,s390x
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: ${{ steps.prep.outputs.is_release == 'yes' }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
with:
push: ${{ steps.prep.outputs.is_release == 'yes' }}
provenance: false
platforms: ${{ env.PLATFORMS }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
DOCKER_IMAGE_VERSION=${{ steps.prep.outputs.label_version }}
cache-from: type=gha,scope=${{ env.DOCKER_IMAGE_NAME }}
cache-to: type=gha,mode=max,scope=${{ env.DOCKER_IMAGE_NAME }}
- name: Build and push (debug version)
uses: docker/build-push-action@v4
with:
push: ${{ steps.prep.outputs.is_release == 'yes' }}
provenance: false
platforms: ${{ env.PLATFORMS }}
tags: ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.prep.outputs.version }}-debug
build-args: |
DOCKER_IMAGE_VERSION=${{ steps.prep.outputs.label_version }}-debug
HANDBRAKE_DEBUG_MODE=max
cache-from: type=gha,scope=${{ env.DOCKER_IMAGE_NAME }}
cache-to: type=gha,mode=max,scope=${{ env.DOCKER_IMAGE_NAME }}
- name: Inspect
if: ${{ steps.prep.outputs.is_release == 'yes' }}
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.prep.outputs.version }}
- name: Inspect (debug version)
if: ${{ steps.prep.outputs.is_release == 'yes' }}
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.prep.outputs.version }}-debug
- name: Checkout
uses: actions/checkout@v4
if: ${{ steps.prep.outputs.release_type == 'standard' }}
- name: Dockerhub description
if: ${{ steps.prep.outputs.release_type == 'standard' }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ${{ env.DOCKER_IMAGE_NAME }}
readme-filepath: DOCKERHUB.md
notification:
name: Notification
needs: [ build ]
runs-on: ubuntu-20.04
if: ${{ always() && github.event_name != 'pull_request' }}
steps:
- name: Pushover notification
uses: desiderati/github-action-pushover@v1
with:
job-status: ${{ needs.build.result }}
pushover-api-token: ${{ secrets.PUSHOVER_API_TOKEN }}
pushover-user-key: ${{ secrets.PUSHOVER_USER_KEY }}