Docker Build #311
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "1 3 * * *" | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: docker.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: buldezir/pocketbase | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
outputs: | |
status: ${{ steps.early.outcome }} | |
steps: | |
- name: Get last release | |
run: | | |
PB_VER=$(curl -s https://api.github.com/repos/pocketbase/pocketbase/releases/latest | jq -r '.tag_name' | sed s/v//) | |
echo "PB_VERSION=$PB_VER" >> $GITHUB_ENV | |
- name: Check dockerhub release | |
id: early | |
continue-on-error: true | |
run: "! curl -s -I --fail https://hub.docker.com/v2/namespaces/buldezir/repositories/pocketbase/tags/$PB_VERSION" | |
build: | |
runs-on: ubuntu-latest | |
needs: check | |
if: needs.check.outputs.status == 'success' | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Get last release | |
run: | | |
PB_VER=$(curl -s https://api.github.com/repos/pocketbase/pocketbase/releases/latest | jq -r '.tag_name' | sed s/v//) | |
echo "PB_VERSION=$PB_VER" >> $GITHUB_ENV | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v2 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
build-args: | | |
PB_VERSION=${{ env.PB_VERSION }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.PB_VERSION }} |