7# Constants and defaults
10DOCKER_REPO=fpco/stack-build
19# Print usage information and exit with failure status. First argument is an
24 echo "Usage: $0 [--push] [--dry-run] [--small] lts-X.Y]"
25 echo "See README.md for more information."
30# Print a command, and if --dry-run disabled also run it
33 [[ $DRY = true ]] || "$@"
36# Push an image if --push is enabled (otherwise do nothing)
38 [[ $PUSH = false ]] || dry docker push "$1"
41# Tag an image, and then push it if --push is enabled
43 dry docker tag "$1" "$2"
52while [[ $# -gt 0 ]]; do
64 DOCKER_REPO=fpco/stack-build-small
68 usage "Unknown option: $1"
71 if [[ -n "$LTS_SLUG_ARG" ]]; then
72 usage "Cannot specify multiple snaphots: $1"
80case "$LTS_SLUG_ARG" in
82 usage "Missing argument: snapshot"
85 LTS_SLUG="$LTS_SLUG_ARG"
88 echo "$0: Wrong snapshot format: $LTS_SLUG_ARG" >&2
94# Determine if lts slug is latest
97SNAPSHOTS="$(mktemp "lts-snapshots.json.XXXXXX")"
98trap "rm -f \"$SNAPSHOTS\"" EXIT
99wget -qO- https://www.stackage.org/download/lts-snapshots.json >"$SNAPSHOTS"
101LTS_VERSION="${LTS_SLUG#lts-}"
102LTS_MAJOR="${LTS_VERSION%.*}"
103LTS_MINOR="${LTS_VERSION#*.}"
106# Determine latest LTS version
109if [[ ! -x "$HOME/.local/bin/jq" ]]; then
110 mkdir -p $HOME/.local/bin
111 if [[ "$(uname)" = "Darwin" ]]; then
112 curl -o $HOME/.local/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64
114 curl -o $HOME/.local/bin/jq -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
116 chmod +x $HOME/.local/bin/jq
119LATEST_LTS_SLUG=$($HOME/.local/bin/jq -r ".[\"lts\"]" $SNAPSHOTS)
120LATEST_LTS_VERSION="${LATEST_LTS_SLUG#lts-}"
121LATEST_LTS_MAJOR="${LATEST_LTS_VERSION%.*}"
122LATEST_LTS_MINOR="${LATEST_LTS_VERSION#*.}"
125# Determine latest minor version of the selected major version
128MAJOR_LATEST_LTS_SLUG=$(jq -r ".[\"lts-$LTS_MAJOR\"]" $SNAPSHOTS)
129MAJOR_LATEST_LTS_VERSION="${MAJOR_LATEST_LTS_SLUG#lts-}"
130MAJOR_LATEST_LTS_MAJOR="${MAJOR_LATEST_LTS_VERSION%.*}"
131MAJOR_LATEST_LTS_MINOR="${MAJOR_LATEST_LTS_VERSION#*.}"
134# Find the Dockerfile for the selected snapshot
137if [[ -s "$LTS_SLUG/Dockerfile" ]]; then
139 # If there is an exact match, build and push that image
141 sed "s/\\\$DOCKER_REPO/$(echo $DOCKER_REPO|sed 's/\//\\\//')/g" "$LTS_SLUG/Dockerfile" >"$LTS_SLUG/Dockerfile.sub"
142 dry docker build -t "$DOCKER_REPO:$LTS_SLUG" --build-arg "DOCKER_REPO=$DOCKER_REPO" --build-arg "LTS_SLUG=$LTS_SLUG" --build-arg "VARIANT=$VARIANT" -f "$LTS_SLUG/Dockerfile.sub" "$LTS_SLUG"
143 rm -f "$LTS_SLUG/Dockerfile.sub"
144 push "$DOCKER_REPO:$LTS_SLUG"
147 # If no exact match, find a dockerfile for any earlier minor version of the
148 # selected major version, and just create a new tag from version's image with the selected
149 # minor version (assuming that nothing needs to change), and push it.
151 minor=$(( LTS_MINOR - 1 ))
152 while [[ ! -s "lts-$LTS_MAJOR.$minor/Dockerfile" && $minor -ge 0 ]]; do
153 minor=$(( minor - 1 ))
155 if [[ $minor -lt 0 ]]; then
156 echo "$0: Cannot find any Dockerfile for LTS major version" >&2
159 dry docker pull "$DOCKER_REPO:lts-$LTS_MAJOR.$minor" || true
160 tagpush "$DOCKER_REPO:lts-$LTS_MAJOR.$minor" "$DOCKER_REPO:$LTS_SLUG"
164# Create and push additional tags
167# If we select the latest minor version for the selected major version, then
168# also create and push an 'lts-X' tag.
169if [[ $LTS_MINOR -ge $MAJOR_LATEST_LTS_MINOR ]]; then
170 tagpush "$DOCKER_REPO:$LTS_SLUG" "$DOCKER_REPO:lts-$LTS_MAJOR"
173# If we selected the latest LTS snapshot, also create and push the 'lts' and 'latest' tags.
174if [[ "$LTS_MAJOR" = "$LATEST_LTS_MAJOR" ]] && [[ $LTS_MINOR -ge $LATEST_LTS_MINOR ]]; then
175 tagpush "$DOCKER_REPO:$LTS_SLUG" "$DOCKER_REPO:lts"
176 tagpush "$DOCKER_REPO:$LTS_SLUG" "$DOCKER_REPO:latest"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list