Skip to content

refactor: [#296] Phase 2: Create DockerComposeTopology Aggregate (P2.1, P2.2) #62

refactor: [#296] Phase 2: Create DockerComposeTopology Aggregate (P2.1, P2.2)

refactor: [#296] Phase 2: Create DockerComposeTopology Aggregate (P2.1, P2.2) #62

Workflow file for this run

# Container workflow for Torrust Tracker Deployer
#
# This workflow builds, tests, and publishes the deployer Docker image.
# Following patterns from torrust/torrust-tracker container.yaml workflow.
#
# Triggers:
# - Push to main/develop branches
# - Pull requests to main/develop
# - Manual dispatch
#
# Publishing:
# - Images are pushed to Docker Hub on push to main/develop (not PRs)
# - Requires Docker Hub credentials in repository secrets
name: Container
on:
push:
branches:
- "develop"
- "main"
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
- "docker/deployer/**"
- ".github/workflows/container.yaml"
pull_request:
branches:
- "develop"
- "main"
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
- "docker/deployer/**"
- ".github/workflows/container.yaml"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
DOCKER_HUB_USERNAME: torrust
jobs:
test:
name: Build & Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/deployer/Dockerfile
target: release
push: false
load: true
tags: torrust-tracker-deployer:local
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Inspect Image
run: docker image inspect torrust-tracker-deployer:local
- name: Verify Tools
run: |
echo "=== Verifying installed tools ==="
docker run --rm torrust-tracker-deployer:local --version || true
echo "=== Checking OpenTofu ==="
docker run --rm --entrypoint tofu torrust-tracker-deployer:local version
echo "=== Checking Ansible ==="
docker run --rm --entrypoint ansible torrust-tracker-deployer:local --version
echo "=== Checking SSH ==="
docker run --rm --entrypoint ssh torrust-tracker-deployer:local -V
echo "=== Checking Git ==="
docker run --rm --entrypoint git torrust-tracker-deployer:local --version
- name: Test Help Output
run: |
docker run --rm torrust-tracker-deployer:local --help
context:
name: Context
needs: test
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
steps:
- name: Check Context
id: check
run: |
if [[ "${{ github.repository }}" == "torrust/torrust-tracker-deployer" ]]; then
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "type=production" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
fi
fi
fi
# Default: don't continue
if [[ -z "$(cat $GITHUB_OUTPUT 2>/dev/null)" ]]; then
echo "continue=false" >> $GITHUB_OUTPUT
fi
publish_development:
name: Publish (Development)
environment: dockerhub-torrust
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'development'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-deployer
tags: |
type=ref,event=branch
type=sha,prefix=dev-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/deployer/Dockerfile
target: release
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
publish_production:
name: Publish (Production)
environment: dockerhub-torrust
needs: context
if: needs.context.outputs.continue == 'true' && needs.context.outputs.type == 'production'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKER_HUB_USERNAME }}/tracker-deployer
tags: |
type=raw,value=latest
type=ref,event=branch
type=sha
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/deployer/Dockerfile
target: release
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max