Build tagged images #17
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: Build tagged images | |
on: | |
push: | |
tags: | |
- '*' | |
schedule: | |
- cron: 0 0 * * * | |
jobs: | |
matrix: | |
runs-on: ubuntu-latest | |
outputs: | |
tags: ${{ env.tags }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Setup variables | |
id: tags | |
run: echo "tags=$(git tag -l | jq -R . | jq -cs .)" >> $GITHUB_ENV | |
build: | |
runs-on: ubuntu-latest | |
needs: matrix | |
strategy: | |
fail-fast: false | |
matrix: | |
tag: ${{ fromJson(needs.matrix.outputs.tags) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@main | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Get tags | |
run: | | |
vtag="${{ matrix.tag }}" | |
tags="$vtag ${vtag#v}" | |
latest="$(git describe --tags --abbrev=0)" | |
[ "$vtag" = "$latest" ] && tags="$tags latest" | |
repo="${{ secrets.DOCKERHUB_USERNAME }}/quasascale-backend:" | |
repo_tags=$(echo "$tags" | jq -cR --arg repo "$repo" 'split(" ") | map($repo + .)') | |
echo "tags=$repo_tags" >> $GITHUB_ENV | |
- name: Log in to Docker Hub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@master | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@master | |
env: | |
DOCKER_BUILD_RECORD_UPLOAD: false | |
DOCKER_BUILD_SUMMARY: false | |
with: | |
context: . | |
pull: true | |
push: true | |
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/quasascale-backend:cache-${{ matrix.tag }} | |
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/quasascale-backend:cache-${{ matrix.tag }},mode=max | |
tags: ${{ join(fromJSON(env.tags), ', ') }} |