Skip to content

Merge torrust/torrust-tracker#412: More Release Preparation #31

Merge torrust/torrust-tracker#412: More Release Preparation

Merge torrust/torrust-tracker#412: More Release Preparation #31

Workflow file for this run

name: Container
on:
push:
branches:
- "develop"
- "main"
- "releases/**/*"
pull_request:
branches:
- "develop"
- "main"
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test (Docker)
runs-on: ubuntu-latest
strategy:
matrix:
target: [debug, release]
steps:
- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v2
- id: build
name: Build
uses: docker/build-push-action@v4
with:
file: ./Containerfile
push: false
load: true
target: ${{ matrix.target }}
tags: torrust-tracker:local
cache-from: type=gha
cache-to: type=gha
- id: inspect
name: Inspect
run: docker image inspect torrust-tracker:local
- id: checkout
name: Checkout Repository
uses: actions/checkout@v4
- id: compose
name: Compose
run: docker compose build
context:
name: Context
needs: test
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
version: ${{ steps.check.outputs.version }}
steps:
- id: check
name: Check Context
run: |
if [[ "${{ github.repository }}" == "torrust/torrust-tracker" ]]; then
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.ref }}" =~ ^(refs\/heads\/releases\/)(v)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]; then
version=$(echo "${{ github.ref }}" | sed -n -E 's/^(refs\/heads\/releases\/)//p')
echo "version=$version" >> $GITHUB_OUTPUT
echo "type=release" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
fi
fi
fi
secrets:
name: Secrets
needs: context
environment: dockerhub-torrust
if: needs.context.outputs.continue == 'true'
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
steps:
- id: check
name: Check
env:
DOCKER_HUB_ACCESS_TOKEN: "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"
if: "${{ env.DOCKER_HUB_ACCESS_TOKEN != '' }}"
run: echo "continue=true" >> $GITHUB_OUTPUT
publish:
name: Publish
environment: dockerhub-torrust
needs: secrets
if: needs.secrets.outputs.continue == 'true'
runs-on: ubuntu-latest
steps:
- id: meta_development
if: needs.context.check.type == 'development'
name: Docker Meta (development)
uses: docker/metadata-action@v4
with:
images: |
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=ref,event=branch
- id: meta_release
if: needs.context.check.type == 'release'
name: Docker Meta (release)
uses: docker/metadata-action@v4
with:
images: |
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=semver,value=${{ needs.context.check.version }},pattern={{raw}}
type=semver,value=${{ needs.context.check.version }},pattern={{version}}
type=semver,value=${{ needs.context.check.version }},pattern=v{{major}}
type=semver,value=${{ needs.context.check.version }},pattern={{major}}.{{minor}}
- id: login
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- id: setup
name: Setup Toolchain
uses: docker/setup-buildx-action@v2
- name: Build and push
uses: docker/build-push-action@v4
with:
file: ./Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha