diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..658a6c9 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,47 @@ +name: Build/Push + +on: + push: + branches: + - main + - master + tags: + - v* + +jobs: + publish: + name: Publish container images + runs-on: ubuntu-latest + steps: + - name: Retrieve code + uses: actions/checkout@v2 + + - name: Gitlab variables + id: vars + run: build/gitlab-vars + + - name: Login to GitHub Packages Docker Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.CR_PAT }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + # Currently required, because buildx doesn't support auto-push from docker + - name: Set up builder + uses: docker/setup-buildx-action@v1 + id: buildx + + - name: Build and push moth image + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + target: moth + file: build/Dockerfile + push: true + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le + tags: | + ghcr.io/nealey/vail:${{ steps.vars.outputs.tag }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..daef853 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Calendar Versioning](https://calver.org/). + +## [2021-07-31] +## Added +- Now builds as a docker image diff --git a/Dockerfile b/build/Dockerfile similarity index 63% rename from Dockerfile rename to build/Dockerfile index 9eb0c13..7cea944 100644 --- a/Dockerfile +++ b/build/Dockerfile @@ -2,7 +2,8 @@ FROM golang:1 AS builder COPY . /src COPY static /target/static -RUN CGO_ENABLED=0 GOOS=linux go install -i -a -ldflags '-extldflags "-static"' /src/... +WORKDIR /src +RUN CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' ./... RUN cp -r /go/bin /target FROM scratch diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..406c01f --- /dev/null +++ b/build/build.sh @@ -0,0 +1,15 @@ +#! /bin/sh + +set -e + +cd $(dirname $0)/.. + +target=vail +VERSION=$(cat CHANGELOG.md | awk -F '[][]' '/^## \[/ {print $2; exit}') +tag=nealey/$target:$VERSION + +echo "==== Building $tag" +docker build \ + --tag $tag \ + -f build/Dockerfile \ + . diff --git a/build/gitlab-vars b/build/gitlab-vars new file mode 100755 index 0000000..582d871 --- /dev/null +++ b/build/gitlab-vars @@ -0,0 +1,25 @@ +#! /bin/sh + +case $1 in + -h|-help|--help) + echo "Usage: $0 TARGET" + echo + echo "Sets CI build variables for gitlab" + exit 1 + ;; +esac + +branch=$(git symbolic-ref -q --short HEAD) +if [ "$branch" = "main" ]; then + branch=latest +fi + +printf "Branch: %s\n" "$branch" +printf "::set-output name=branch::%s\n" "$branch" +printf "::set-output name=tag::%s\n" "$branch" + +# I think it will use whichever comes last +git tag --points-at HEAD | while read tag; do + printf "Tag: %s\n" "$tag" + printf "::set-output name=tag::%s\n" "$tag" +done