|
| 1 | +#!/usr/bin/env sh |
| 2 | +set -eu |
| 3 | + |
| 4 | +# Start the script in the top-level repository directory no matter what. |
| 5 | +cd "$( git rev-parse --show-toplevel )" |
| 6 | + |
| 7 | +# XXX: Would it make sense to pull from an existing image if one exists? |
| 8 | +image="alpine-ghc-base" |
| 9 | +container="alpine-ghc-base-builder" |
| 10 | + |
| 11 | +################################################################################ |
| 12 | +# Attempt to create a new image using the container name defined above. |
| 13 | +# |
| 14 | +# If the container already exists, assume that it's been created by a previous |
| 15 | +# run of this script and just use that. |
| 16 | +buildah \ |
| 17 | + --signature-policy=./policy.json \ |
| 18 | + --name "${container}" \ |
| 19 | + from --pull docker.io/library/alpine:3.14 \ |
| 20 | + || true |
| 21 | + |
| 22 | +# Upgrade the currently installed packages. |
| 23 | +# |
| 24 | +# NOTE: This breaks reproducibility. |
| 25 | +buildah run "${container}" \ |
| 26 | + apk upgrade --no-cache |
| 27 | + |
| 28 | +# Install basic dependencies required by 'ghcup', 'stack', and 'cabal-install'. |
| 29 | +buildah run "${container}" \ |
| 30 | + apk add --no-cache \ |
| 31 | + curl \ |
| 32 | + gcc \ |
| 33 | + git \ |
| 34 | + libc-dev \ |
| 35 | + xz |
| 36 | + |
| 37 | +# TODO: Guard this behind some argument that can toggle GMP-based builds. |
| 38 | +echo "Installing 'libgmp'." |
| 39 | +buildah run "${container}" \ |
| 40 | + apk add --no-cache gmp-dev |
| 41 | + |
| 42 | +################################################################################ |
| 43 | +ghcup_version="0.1.9" |
| 44 | +ghcup_expected_checksum="d779ada6156b08da21e40c5bf218ec21d1308d5a9e48f7b9533f56b5d063a41c" |
| 45 | + |
| 46 | +# Fetch `ghcup`. |
| 47 | +buildah run "${container}" \ |
| 48 | + wget \ |
| 49 | + -O "/tmp/ghcup-${ghcup_version}" \ |
| 50 | + "https://downloads.haskell.org/~ghcup/0.1.9/x86_64-linux-ghcup-${ghcup_version}" |
| 51 | + |
| 52 | +# Copy the checksum validation script into the container... |
| 53 | +buildah copy --chmod 111 ${container} \ |
| 54 | + ./0_base/validate_checksum.sh \ |
| 55 | + /tmp/validate_checksum.sh |
| 56 | + |
| 57 | +# ...and verify that the expected and actual actual `ghcup` checksums match. |
| 58 | +buildah run "${container}" \ |
| 59 | + ./tmp/validate_checksum.sh \ |
| 60 | + "/tmp/ghcup-${ghcup_version}" \ |
| 61 | + "${ghcup_expected_checksum}" |
| 62 | + |
| 63 | +# Relocate `ghcup`... |
| 64 | +buildah run "${container}" \ |
| 65 | + mv /tmp/"ghcup-${ghcup_version}" /usr/bin/ghcup |
| 66 | +# ...set it to be executable... |
| 67 | +buildah run "${container}" \ |
| 68 | + chmod +x /usr/bin/ghcup |
| 69 | + |
| 70 | +# ...and clean up after ourselves. |
| 71 | +buildah run "${container}" \ |
| 72 | + rm -rf /tmp/validate_checksum.sh |
| 73 | + |
| 74 | +################################################################################ |
| 75 | +# Write the final `alpine-ghc-base` image from this container. |
| 76 | +buildah \ |
| 77 | + --signature-policy=./policy.json \ |
| 78 | + commit "${container}" "${image}" |
0 commit comments