Skip to content

Switch from GitHub Actions to AWS CodeBuild #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
name: Workflow
on: push
jobs:
docker:
image:
strategy:
matrix:
include:
- { ghc: 9.0.2 }
- { ghc: 9.2.4 }
- { ghc: 9.4.2 }
name: Docker with GHC ${{ matrix.ghc }}
arch:
- amd64
- arm64
ghc:
- 9.0.2
- 9.2.4
- 9.4.2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- id: meta
uses: docker/metadata-action@v4

- uses: aws-actions/configure-aws-credentials@v1
with:
images: ghcr.io/${{ github.repository }}
flavor: latest=false
tags: |
type=sha,format=long,prefix=${{ matrix.ghc }}-
type=raw,value=${{ matrix.ghc }},enable={{ is_default_branch }}
- uses: docker/login-action@v2
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- uses: aws-actions/aws-codebuild-run-build@v1
with:
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
username: ${{ github.actor }}
- uses: docker/build-push-action@v3
project-name: docker-haskell-${{ matrix.arch }}
buildspec-override: aws/image.yaml
env-vars-for-codebuild: GHC_VERSION
env:
GHC_VERSION: ${{ matrix.ghc }}

manifest:
needs: image
strategy:
matrix:
ghc:
- 9.0.2
- 9.2.4
- 9.4.2
runs-on: ubuntu-latest
steps:

- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- uses: aws-actions/aws-codebuild-run-build@v1
with:
build-args: |
GHC_VERSION=${{ matrix.ghc }}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
project-name: docker-haskell-amd64
buildspec-override: aws/manifest.yaml
env-vars-for-codebuild: GHC_VERSION
env:
GHC_VERSION: ${{ matrix.ghc }}
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG DEBIAN_VERSION=11.4
ARG DEBIAN_VERSION=11.5
FROM "debian:$DEBIAN_VERSION-slim"

# Install dependencies.
Expand Down Expand Up @@ -47,7 +47,7 @@ ARG GHCUP_VERSION=0.1.18.0
RUN \
set -o errexit -o xtrace; \
if test -n "$GHCUP_VERSION"; then \
curl --output ~/.ghcup/bin/ghcup "https://downloads.haskell.org/~ghcup/$GHCUP_VERSION/$( uname --machine )-linux-ghcup-$GHCUP_VERSION"; \
curl --output ~/.ghcup/bin/ghcup "https://downloads.haskell.org/ghcup/$GHCUP_VERSION/$( uname --machine )-linux-ghcup-$GHCUP_VERSION"; \
chmod --verbose +x ~/.ghcup/bin/ghcup; \
ghcup --version; \
fi
Expand Down Expand Up @@ -75,7 +75,7 @@ RUN \

# Install Stack.

ARG STACK_VERSION=2.7.5
ARG STACK_VERSION=2.9.1
RUN \
set -o errexit -o xtrace; \
if test -n "$STACK_VERSION"; then \
Expand Down
29 changes: 29 additions & 0 deletions aws/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: 0.2
env:
secrets-manager:
DOCKER_PASSWORD: docker-hub-read-only:DOCKER_PASSWORD
DOCKER_USERNAME: docker-hub-read-only:DOCKER_USERNAME
variables:
AWS_REGION: us-east-1
GHC_VERSION: 9.2.4
phases:
build:
commands:

- echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin

- server=public.ecr.aws/v6m6o3k4

- aws ecr-public get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$server"

- case $( uname -m ) in ( aarch64 ) arch=arm64 ;; ( x86_64 ) arch=amd64 ;; ( * ) exit 1 ;; esac

- echo "$arch"

- tag="$server/haskell:$GHC_VERSION-$CODEBUILD_RESOLVED_SOURCE_VERSION-$arch"

- echo "$tag"

- docker build --build-arg GHC_VERSION="$GHC_VERSION" --tag "$tag" .

- docker push "$tag"
20 changes: 20 additions & 0 deletions aws/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 0.2
env:
variables:
AWS_REGION: us-east-1
GHC_VERSION: 9.2.4
phases:
build:
commands:

- server=public.ecr.aws/v6m6o3k4

- aws ecr-public get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$server"

- tag="$server/haskell:$GHC_VERSION-$CODEBUILD_RESOLVED_SOURCE_VERSION"

- echo "$tag"

- docker manifest create "$tag" "$tag-amd64" "$tag-arm64"

- docker manifest push "$tag"