|
@@ -0,0 +1,131 @@
|
|
|
+name: Publish Docker Image
|
|
|
+
|
|
|
+on:
|
|
|
+ schedule:
|
|
|
+ - cron: '20 5 * * *'
|
|
|
+ pull_request:
|
|
|
+ branches:
|
|
|
+ - main
|
|
|
+ paths-ignore:
|
|
|
+ - '.git*'
|
|
|
+ - 'docker-compose.yml'
|
|
|
+ - 'README.*'
|
|
|
+ push:
|
|
|
+ branches:
|
|
|
+ - main
|
|
|
+ paths-ignore:
|
|
|
+ - '.git*'
|
|
|
+ - 'docker-compose.yml'
|
|
|
+ - 'README.*'
|
|
|
+ workflow_dispatch:
|
|
|
+
|
|
|
+env:
|
|
|
+ IMAGE_BASE: library/alpine:latest
|
|
|
+ REPO_NAME: ${{ github.event.repository.name }}
|
|
|
+ REGISTRY_URL: docker.io
|
|
|
+ REGISTRY_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
+ REGISTRY_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
|
+
|
|
|
+jobs:
|
|
|
+
|
|
|
+ variables:
|
|
|
+ runs-on: ubuntu-latest
|
|
|
+ outputs:
|
|
|
+ image_name: ${{ steps.split.outputs.image_name }}
|
|
|
+ steps:
|
|
|
+ - name: Set name of image
|
|
|
+ id: split
|
|
|
+ run: echo "image_name=${REPO_NAME#*-}" >> $GITHUB_OUTPUT
|
|
|
+
|
|
|
+ check:
|
|
|
+ needs: variables
|
|
|
+ runs-on: ubuntu-latest
|
|
|
+ env:
|
|
|
+ IMAGE_NAME: ${{ needs.variables.outputs.image_name }}
|
|
|
+ outputs:
|
|
|
+ image-needs-updating: ${{ steps.check.outputs.needs-updating }}
|
|
|
+ steps:
|
|
|
+ - name: Check if update available
|
|
|
+ id: check
|
|
|
+ uses: lucacome/docker-image-update-checker@v1.2.0
|
|
|
+ with:
|
|
|
+ base-image: ${{ env.IMAGE_BASE }}
|
|
|
+ image: ${{ env.REGISTRY_USERNAME }}/${{ env.IMAGE_NAME }}
|
|
|
+ if: github.event_name == 'schedule'
|
|
|
+
|
|
|
+ build:
|
|
|
+
|
|
|
+ needs: [check, variables]
|
|
|
+
|
|
|
+ env:
|
|
|
+ IMAGE_NAME: ${{ needs.variables.outputs.image_name }}
|
|
|
+
|
|
|
+ if: |
|
|
|
+ github.event_name != 'schedule' ||
|
|
|
+ needs.check.outputs.image-needs-updating == 'true'
|
|
|
+
|
|
|
+ runs-on: ubuntu-latest
|
|
|
+
|
|
|
+ steps:
|
|
|
+ - name: Checkout repository
|
|
|
+ uses: actions/checkout@v3
|
|
|
+
|
|
|
+ - name: Log into registry
|
|
|
+ if: github.event_name != 'pull_request'
|
|
|
+ uses: docker/login-action@v2
|
|
|
+ with:
|
|
|
+ registry: ${{ env.REGISTRY_URL }}
|
|
|
+ username: ${{ env.REGISTRY_USERNAME }}
|
|
|
+ password: ${{ env.REGISTRY_PASSWORD }}
|
|
|
+
|
|
|
+ - name: Extract Docker metadata
|
|
|
+ if: github.event_name != 'pull_request'
|
|
|
+ id: meta
|
|
|
+ uses: docker/metadata-action@v4
|
|
|
+ with:
|
|
|
+ images: |
|
|
|
+ ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USERNAME }}/${{ env.IMAGE_NAME }}
|
|
|
+ flavor: |
|
|
|
+ latest=false
|
|
|
+ labels: |
|
|
|
+ org.opencontainers.image.base.name=docker.io/${{ env.IMAGE_BASE }}
|
|
|
+ tags: |
|
|
|
+ type=sha
|
|
|
+ type=schedule,pattern={{date 'YYYYMMDD'}}
|
|
|
+ type=semver,pattern={{version}}
|
|
|
+ type=semver,pattern={{major}}.{{minor}}
|
|
|
+ type=raw,value=latest,enable={{is_default_branch}}
|
|
|
+
|
|
|
+ - name: Extract Docker PR tag
|
|
|
+ if: github.event_name == 'pull_request'
|
|
|
+ id: meta_pr
|
|
|
+ uses: docker/metadata-action@v4
|
|
|
+ with:
|
|
|
+ images: |
|
|
|
+ ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USERNAME }}/${{ env.IMAGE_NAME }}
|
|
|
+ flavor: |
|
|
|
+ latest=false
|
|
|
+ tags: |
|
|
|
+ type=sha
|
|
|
+ type=ref,event=pr
|
|
|
+
|
|
|
+ - name: Set up QEMU
|
|
|
+ uses: docker/setup-qemu-action@v2
|
|
|
+
|
|
|
+ - name: Set up Docker Buildx
|
|
|
+ id: buildx
|
|
|
+ uses: docker/setup-buildx-action@v2
|
|
|
+
|
|
|
+ - name: Build and push Docker image
|
|
|
+ id: build-and-push
|
|
|
+ uses: docker/build-push-action@v3
|
|
|
+ env:
|
|
|
+ ACTIONS_RUNTIME_TOKEN: ''
|
|
|
+ with:
|
|
|
+ context: .
|
|
|
+ build-args: |
|
|
|
+ BASE_IMAGE=${{ env.IMAGE_BASE }}
|
|
|
+ platforms: linux/386, linux/amd64, linux/arm64
|
|
|
+ push: ${{ github.event_name != 'pull_request' }}
|
|
|
+ tags: ${{ steps.meta.outputs.tags }}
|
|
|
+ labels: ${{ steps.meta.outputs.labels }}
|