Skip to content

Commit

Permalink
[SC-30890] This image is now purescript-tools, similar to haskell-tools
Browse files Browse the repository at this point in the history
We now build amd64 and arm64 versions of a purescript-tools image. We
use `bookworm` as the Debian version because the `trixie` unstable version
is not currently supported by nodesource.

The spago utility is being built from source, so that we have a version
that works on all of our developer arm64 machines. This utility does not
officially support arm64 so there may still be some issues with it.
  • Loading branch information
onslaughtq committed Aug 7, 2023
1 parent eaeb765 commit a9f528f
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 42 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Push Purescript-Tools image

on:
push:

defaults:
run:
shell: bash

jobs:
build_and_push_image:
strategy:
matrix:
os: [[self-hosted, linux, x64], [self-hosted, linux, arm64]]

runs-on: ${{ matrix.os }}
name: Build and Push Docker Image

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Log in to the Github Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v2

- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v2

- name: Build And Push Image
run: |
./build-image.sh build-and-push-arch-tag
build_and_push_manifest:
name: Build manifest docker image
runs-on: [self-hosted, linux, x64]
needs: [build_and_push_image]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Github Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push manifest
run: |
./build-image.sh push-manifest
26 changes: 16 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
FROM flipstone/stack:v5-2.7.3-arm64 AS builder
FROM ghcr.io/flipstone/haskell-tools:debian-unstable-ghc-9.4.5-2023-07-18-1d8bf61 AS builder

RUN apt-get update && apt-get install -y git curl
COPY install-spago.sh /tmp/install-spago.sh
RUN /tmp/install-spago.sh

ADD build-purs.sh /build-purs.sh
RUN /build-purs.sh
FROM debian:bookworm-slim

ADD build-spago.sh /build-spago.sh
RUN /build-spago.sh
ENV LANG="C.UTF-8" LANGUAGE="C.UTF-8" LC_ALL="C.UTF-8"

FROM arm64v8/debian:bullseye-20211220-slim
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y -qq --no-install-recommends \
ca-certificates curl lsb-release gnupg apt-transport-https git && \
apt-get clean

COPY --from=builder /usr/local/bin/purs /usr/local/bin/purs
COPY --from=builder /root/.local/bin/spago /usr/local/bin/spago
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -qq -y --no-install-recommends nodejs && \
apt-get clean

ENTRYPOINT /usr/local/bin/spago
RUN npm install -g npm@9.8.1
RUN npm install -g purescript@0.15.10 purescript-psa@0.8.2 grunt@1.6.1 esbuild@0.18.17
COPY --from=builder /root/.local/bin/spago /usr/local/bin/spago
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
This repo is used to create a docker image containing arm64 binaries of `purs`
(the purescript compiler) and `spago` (a build tool for purescript).
# Purescript Tools

The tag or branch you want to build must be set in their build scripts.
This repository has a workflow defined that will build and push amd64 and arm64
images to Github Container Registry.

Note that spago's has its own version number separate from purs so if you're
upgrading then you must manually verfiy the version of purs and spago you want
and make sure they work together. Generally you probably want the latest
released version of each.
# How to build this using docker

This repository is typically used for simply providing these binaries inside of
a docker image that can be used inside a project-specific docker image which
needs an arm64 version.
* Use `./build-image.sh push-arch-tag` on your machine to build a local image
for testing. As you make changes locally the images will be tagged with
`-uncommitted` on the end rather than the commit SHA.

Once the build scripts have the appropriate versions in them then you should be
able to produce the needed docker image with `docker build .`
* Update the base tag in `./build-image.sh` as necessary to reflect changes
in the base image or GHC version included in the image.

After that you can tag it or push it to whereever you need.
* On an AMD64 machine:

Typically that will be `flipstone/purescript-arm64:<purs version>`
```
./build-image.sh build-arch-tag
./build-image.sh push-arch-tag
```

e.g.
* On an ARM64 machine:

```
docker build . -t flipstone/purescript-arm64:0.15.4
docker push
./build-image.sh build-arch-tag
./build-image.sh push-arch-tag
```

* On either machine:

```
./build-image.sh push-manifest
```

59 changes: 59 additions & 0 deletions build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

set -e

GIT_CHANGES=$(git status --porcelain | wc -l 2>/dev/null)

case "$GIT_CHANGES" in
0)
COMMIT_SHA=$(git show-ref --hash=7 --verify HEAD)
;;
*)
echo "Uncommitted changes found. Images will be tagged with -uncommitted"
COMMIT_SHA="uncommitted"
;;
esac


RELEASE_DATE=$(date '+%Y-%m-%d')
TAG_ROOT="ghcr.io/flipstone/purescript-tools:debian-bookworm-purescript-0.15.10-$RELEASE_DATE-$COMMIT_SHA"
ARM_TAG="$TAG_ROOT"-arm64
AMD_TAG="$TAG_ROOT"-amd64
ARCH=$(uname -m)

case "$ARCH" in
x86_64)
ARCH_TAG="$AMD_TAG"
;;
aarch64)
ARCH_TAG="$ARM_TAG"
;;
arm64)
ARCH_TAG="$ARM_TAG"
;;
*)
echo "Unrecognized architecture: $ARCH"
exit 1
;;
esac

COMMAND=$1

case $COMMAND in
build-and-push-arch-tag)
echo "Building $ARCH_TAG"
docker buildx build . \
--tag $ARCH_TAG \
--cache-from type=gha,mode=max,ignore-error=true \
--cache-to type=gha,mode=max,ignore-error=true \
--push
;;

push-manifest)
echo "Both $AMD_TAG and $ARM_TAG must be pushed to Github Container Registry BEFORE running this step."
docker buildx imagetools create --tag $TAG_ROOT $AMD_TAG $ARM_TAG
;;
*)
echo "usage: ./build-image.sh build-arch-tag|push-arch-tag|push-manifest"
exit 1
esac;
13 changes: 0 additions & 13 deletions build-purs.sh

This file was deleted.

4 changes: 2 additions & 2 deletions build-spago.sh → install-spago.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
#!/bin/bash

set -e

git clone https://github.com/purescript/spago.git ~/spago

cd ~/spago

git checkout 0.20.9
git checkout 0.21.0

make
make install

0 comments on commit a9f528f

Please sign in to comment.