From a30cf1d621ffd1710b5b640f7f5ad48cb877ae09 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 29 May 2024 01:51:02 -0700 Subject: [PATCH] Update Dockerfile and release stages --- .github/workflows/release.yml | 43 +++++++++++++++++++++++++++++++---- Dockerfile | 4 +++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3ca9994..7e2baf8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,22 +8,57 @@ on: permissions: contents: write +env: + IMAGE_NAME: rwp + jobs: release: runs-on: [self-hosted, arm64] steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 with: fetch-depth: 0 - run: git fetch --force --tags - - uses: actions/setup-go@v5 + - name: Set up Go + uses: actions/setup-go@v5 with: go-version: '>=1.22.0' - - uses: goreleaser/goreleaser-action@v5 + - name: Build release + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest args: release --clean env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + container: + runs-on: [self-hosted, arm64] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build and push Docker image + run: docker buildx build --platform=linux/amd64,linux/arm64,linux/arm/v7 . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + # This changes all uppercase characters to lowercase. + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # This strips the git ref prefix from the version. + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # This strips the "v" prefix from the tag name. + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # This uses the Docker `latest` tag convention. + [ "$VERSION" == "main" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/Dockerfile b/Dockerfile index fa01927..a4fa2ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,7 +20,9 @@ COPY . ./ # RUN git lfs pull && ls -alh publications # Run goreleaser -RUN GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --single-target --id rwp --skip=validate --snapshot --output ./rwp +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + GOOS=$TARGETOS GOARCH=$TARGETARCH goreleaser build --single-target --id rwp --skip=validate --snapshot --output ./rwp # Run tests # FROM builder AS tester