-
Notifications
You must be signed in to change notification settings - Fork 21
/
build
75 lines (65 loc) · 2.97 KB
/
build
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
#!/bin/bash
# Usage: `./this-script <image name>`
#
# The image name should be of the form 'namespace:tag', e.g.
# 'yourname/yourproject:latest', see also https://docs.docker.com/docker-hub/builds/advanced/.
#
# If $IMAGE_NAME is defined as an environment variable, it takes precedent and the
# command line argument image name will be ignored.
# If neither is given, this script fails.
# In 2021, Docker retired its free automated builds. They now require a Pro plan.
# (We can thank abusive miners for that).
# To cope, and to not have to pay, these images are now built locally and pushed
# manually. Hence, this script now works for both local use as well as DockerHub use
# (should a Pro plan be available).
set -u
# For more info, see:
# https://docs.docker.com/docker-hub/builds/advanced/
# https://web.archive.org/web/20201002130055/https://dev.to/samuelea/automate-your-builds-on-docker-hub-by-writing-a-build-hook-script-13fp
cut_tag_field() { echo "$DOCKER_TAG" | cut --delimiter="-" --fields="$1"; }
# Assign some (dynamic) default values if variables undefined.
# This is compatible with the DockerHub infrastructure where these are defined
# (see https://docs.docker.com/docker-hub/builds/advanced/) but also allows easy
# local execution.
: "${DOCKER_TAG:=latest}" # https://stackoverflow.com/a/28085062
# This will fail if compiling locally where this env var is (probably) not defined,
# and no command line argument is given:
: "${IMAGE_NAME:=$1}" # https://stackoverflow.com/a/28085062
echo "Using Docker tag '$DOCKER_TAG'."
echo "Building with image name '$IMAGE_NAME'."
if [[ "$DOCKER_TAG" == "latest" ]]
then
# Default OS:
BASE_OS="debian"
# `debian:latest` will get latest *stable*, which has between 1.5 to 2 years old,
# well-tested software. While that is suitable for servers etc., this Docker image
# does not need highest stability. More recent features are more important (e.g. for
# pandoc). Debian's `testing` branch sounds cutting-edge but is roughly 6 months old
# software, so should be stable enough here.
# This image's main component, TeXLive, is largely unaffected by this anyway.
OS_VERSION="testing"
# Installation script takes care of finding the appropriate version of TeXLive
# for the 'latest' tag:
TL_VERSION="$DOCKER_TAG"
else
# Otherwise, take versions as manually specified in build process.
#
# This assumes tags in the form: '<baseos>-<version>-texlive-<version>',
# e.g. 'debian-10-texlive-2019'
#
# E.g. 'debian'
BASE_OS=$(cut_tag_field 1)
# Version e.g. '10' for Debian, but can also be 'buster', see:
# https://wiki.debian.org/DebianReleases
# These are the available versions:
# https://hub.docker.com/_/debian?tab=tags
OS_VERSION=$(cut_tag_field 2)
# E.g. '2020':
TL_VERSION=$(cut_tag_field 4)
fi
docker build \
--build-arg BASE_OS="$BASE_OS" \
--build-arg OS_VERSION="$OS_VERSION" \
--build-arg TL_VERSION="$TL_VERSION" \
--tag "$IMAGE_NAME" \
.