-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-build.sh
executable file
·43 lines (36 loc) · 1.31 KB
/
docker-build.sh
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
#!/bin/bash
# Multi-platform Docker image build.
set -euo pipefail
IMAGE_NAME="genericmoniker/mirror"
CACHE_IMAGE_NAME="genericmoniker/mirror-cache"
# Get the Git commit and branch.
GIT_COMMIT=$(set -e && git rev-parse --short HEAD)
GIT_BRANCH=$(set -e && git rev-parse --abbrev-ref HEAD)
GIT_DEFAULT_BRANCH="main"
# Set two complete image names:
IMAGE_WITH_COMMIT="${IMAGE_NAME}:commit-${GIT_COMMIT}"
IMAGE_WITH_BRANCH="${IMAGE_NAME}:${GIT_BRANCH}"
IMAGE_WITH_DEFAULT_BRANCH="${IMAGE_NAME}:${GIT_DEFAULT_BRANCH}"
CACHE_IMAGE_WITH_BRANCH="${CACHE_IMAGE_NAME}:${GIT_BRANCH}"
# Build the image, giving it two names.
#
# Best practices:
# * Warm up the build cache, per-branch.
# * Don't rely on the `latest` tag.
# * Record the build's version control revision and branch.
#
# Multiplatform build:
# * linux/arm/v7 to run on Raspberry Pi 2
# * linux/arm64 could be added for new Pis
# * linux/amd64 could be added to run on desktop
docker buildx build \
-t "${IMAGE_WITH_COMMIT}" \
-t "${IMAGE_WITH_BRANCH}" \
--label "git-commit=${GIT_COMMIT}" \
--label "git-branch=${GIT_BRANCH}" \
--platform linux/arm/v7 \
--progress plain \
--push \
--cache-from=type=registry,ref="${CACHE_IMAGE_WITH_BRANCH}" \
--cache-to=type=registry,ref="${CACHE_IMAGE_WITH_BRANCH}",mode=max \
.