containers/.forgejo/workflows/ansible.yml

82 lines
3 KiB
YAML
Raw Normal View History

2025-07-13 23:49:10 +02:00
run-name: Build and Push Ansible Container
on:
push:
branches:
- main
paths:
2025-07-14 00:45:11 +02:00
- 'containers/${{ github.workflow }}/**' # This path will look for 'containers/Build and Push Ansible Container/**'
2025-07-14 00:25:58 +02:00
- '.forgejo/workflows/ansible.yml'
2025-07-13 23:49:10 +02:00
workflow_dispatch: {}
schedule:
2025-07-14 00:45:11 +02:00
- cron: '0 20 * * 5' # Runs every Friday at 8 PM UTC
2025-07-13 23:49:10 +02:00
jobs:
build-and-push:
strategy:
matrix:
arch: [ amd64, arm64 ]
2025-07-14 00:40:00 +02:00
runs-on: ${{ matrix.arch }}
2025-07-14 00:41:01 +02:00
container:
2025-07-14 00:50:47 +02:00
image: node:latest
2025-07-14 00:48:43 +02:00
volumes:
- /var/run/docker.sock:/var/run/docker.sock
2025-07-13 23:49:10 +02:00
steps:
2025-07-14 00:07:38 +02:00
2025-07-14 00:50:47 +02:00
- name: Install Docker CLI
run: |
apt-get update
apt-get install -y docker.io
2025-07-14 00:45:11 +02:00
- name: Checkout repository
2025-07-13 23:49:10 +02:00
uses: actions/checkout@v4
2025-07-14 00:45:11 +02:00
- name: Set up Docker Buildx
2025-07-13 23:49:10 +02:00
uses: docker/setup-buildx-action@v3
- name: Login to Forgejo Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.CI_REGISTRY }}
username: ${{ secrets.CI_REGISTRY_USER }}
password: ${{ secrets.CI_TOKEN }}
2025-07-14 00:45:11 +02:00
# Removed the `cd` step as `context` and `file` can handle the path directly.
2025-07-13 23:49:10 +02:00
- name: Build and push (${{ matrix.arch }})
uses: docker/build-push-action@v5
with:
2025-07-14 00:45:11 +02:00
context: ./containers/${{ github.workflow }}/ # Relative to the checkout root
file: ./containers/${{ github.workflow }}/Dockerfile # Relative to the checkout root
2025-07-13 23:49:10 +02:00
platforms: linux/${{ matrix.arch }}
push: true
tags: |
${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:${{ matrix.arch }}-latest
2025-07-14 00:45:11 +02:00
cache-from: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:buildcache-${{ matrix.arch }} # Add caching
cache-to: type=registry,ref=${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:buildcache-${{ matrix.arch }},mode=max # Add caching
2025-07-13 23:49:10 +02:00
manifest:
needs: build-and-push
2025-07-14 00:45:11 +02:00
runs-on: ubuntu-latest # or amd64 if you have a specific AMD64 runner for manifest creation
2025-07-13 23:49:10 +02:00
steps:
2025-07-14 00:45:11 +02:00
- name: Install Docker CLI
2025-07-14 00:07:38 +02:00
run: |
2025-07-14 00:45:11 +02:00
# Ensure docker CLI is available in the runner environment for `docker manifest`
# Most `ubuntu-latest` runners already have it, but explicit is better.
sudo apt-get update
sudo apt-get install -y docker-ce-cli # Install only the client if the runner is not dind
2025-07-14 00:07:38 +02:00
2025-07-13 23:49:10 +02:00
- name: Login to Forgejo Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.CI_REGISTRY }}
username: ${{ secrets.CI_REGISTRY_USER }}
password: ${{ secrets.CI_TOKEN }}
- name: Create and push multi-arch manifest
run: |
2025-07-14 00:45:11 +02:00
# Use the explicit "docker" command which should be available
2025-07-13 23:49:10 +02:00
docker manifest create ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:latest \
${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:amd64-latest \
${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:arm64-latest
docker manifest push ${{ secrets.CI_REGISTRY }}/${{ secrets.CI_REPOSITORY }}:latest