|
| 1 | +# Stage Docker images through GitHub Actions (GHA) to GitHub Container Registry (GHCR). |
| 2 | +# |
| 3 | +# https://github.com/docker/build-push-action/blob/master/docs/advanced/tags-labels.md |
| 4 | +# https://github.com/crazy-max/ghaction-docker-meta |
| 5 | +# https://github.com/docker/build-push-action |
| 6 | + |
| 7 | +name: Build and release container images |
| 8 | + |
| 9 | +on: |
| 10 | + schedule: |
| 11 | + - cron: '0 10 * * *' # everyday at 10am |
| 12 | + push: |
| 13 | + tags: |
| 14 | + - '*.*.*' |
| 15 | + workflow_dispatch: |
| 16 | + pull_request: |
| 17 | + branches: [ main ] |
| 18 | + |
| 19 | +env: |
| 20 | + GHCR_IMAGE_NAME: ghcr.io/panodata/grafana-wtf |
| 21 | + |
| 22 | +jobs: |
| 23 | + docker: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - |
| 27 | + name: Checkout |
| 28 | + uses: actions/checkout@v2 |
| 29 | + - |
| 30 | + name: Docker meta |
| 31 | + id: meta |
| 32 | + uses: docker/metadata-action@v3 |
| 33 | + with: |
| 34 | + # List of Docker images to use as base name for tags |
| 35 | + images: | |
| 36 | + ${{ env.GHCR_IMAGE_NAME }} |
| 37 | + # Generate Docker tags based on the following events/attributes |
| 38 | + tags: | |
| 39 | + type=schedule,pattern=nightly |
| 40 | + type=ref,event=pr |
| 41 | + type=semver,pattern={{version}} |
| 42 | + type=semver,pattern={{major}}.{{minor}} |
| 43 | + - |
| 44 | + name: Inspect meta |
| 45 | + run: | |
| 46 | + echo "Tags: ${{ steps.meta.outputs.tags }}" |
| 47 | + echo "Labels: ${{ steps.meta.outputs.labels }}" |
| 48 | + - |
| 49 | + name: Set up QEMU |
| 50 | + uses: docker/setup-qemu-action@v1 |
| 51 | + - |
| 52 | + name: Set up Docker Buildx |
| 53 | + id: buildx |
| 54 | + uses: docker/setup-buildx-action@v1 |
| 55 | + - |
| 56 | + name: Cache Docker layers |
| 57 | + uses: actions/cache@v2 |
| 58 | + with: |
| 59 | + path: /tmp/.buildx-cache |
| 60 | + key: ${{ runner.os }}-buildx-${{ github.sha }} |
| 61 | + restore-keys: | |
| 62 | + ${{ runner.os }}-buildx- |
| 63 | + - |
| 64 | + name: Inspect builder |
| 65 | + run: | |
| 66 | + echo "Name: ${{ steps.buildx.outputs.name }}" |
| 67 | + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
| 68 | + echo "Status: ${{ steps.buildx.outputs.status }}" |
| 69 | + echo "Flags: ${{ steps.buildx.outputs.flags }}" |
| 70 | + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
| 71 | + - |
| 72 | + name: Login to GHCR |
| 73 | + # Prevent uploading images for pull requests. |
| 74 | + # if: github.event_name != 'pull_request' |
| 75 | + uses: docker/login-action@v1 |
| 76 | + with: |
| 77 | + registry: ghcr.io |
| 78 | + username: ${{ github.repository_owner }} |
| 79 | + password: ${{ github.token }} |
| 80 | + - |
| 81 | + name: Build and push |
| 82 | + uses: docker/build-push-action@v2 |
| 83 | + with: |
| 84 | + context: . |
| 85 | + file: Dockerfile |
| 86 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 87 | + tags: ${{ steps.meta.outputs.tags }} |
| 88 | + labels: ${{ steps.meta.outputs.labels }} |
| 89 | + # Prevent uploading images for pull requests. |
| 90 | + # push: ${{ github.event_name != 'pull_request' }} |
| 91 | + push: true |
| 92 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 93 | + cache-to: type=local,dest=/tmp/.buildx-cache-new |
| 94 | + |
| 95 | + - |
| 96 | + name: Move cache |
| 97 | + run: | |
| 98 | + rm -rf /tmp/.buildx-cache |
| 99 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments