Skip to content

Update workflow to push PR images with unique tags #2

Update workflow to push PR images with unique tags

Update workflow to push PR images with unique tags #2

Workflow file for this run

---
name: Build
'on':
pull_request:
push:
branches:
- main
schedule:
- cron: "10 2 * * 0"
jobs:
# Test AlmaLinux 8 with both Ansible versions
test-almalinux8:
name: Test AlmaLinux 8 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if AlmaLinux 8 files changed
id: changed
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
git fetch origin ${{ github.base_ref }}
if git diff --name-only \
origin/${{ github.base_ref }}...HEAD | \
grep -q "^docker-almalinux8-ansible/"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
else
# Always build on main branch or cron
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Set Ansible version build arg and tags
id: ansible
if: steps.changed.outputs.changed == 'true'
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag_suffix=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag_suffix=core-2.16" >> $GITHUB_OUTPUT
fi
# Set PR-specific tag if this is a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "docker_tag=pr-${PR_NUMBER}-${{ matrix.ansible_version }}" \
>> $GITHUB_OUTPUT
echo "should_push=true" >> $GITHUB_OUTPUT
else
echo "should_push=false" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- uses: docker/setup-buildx-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- name: Login to DockerHub
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push PR image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux8-ansible
file: ./docker-almalinux8-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
mrkoopie/almalinux8-ansible:${{ steps.ansible.outputs.docker_tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}
- name: Test building image locally
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker build \
--build-arg \
ANSIBLE_VERSION="${{ steps.ansible.outputs.build_arg }}" \
-t docker-ansible \
./docker-almalinux8-ansible
- name: Run the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: >-
docker run --name test-container -d --privileged
-v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host
docker-ansible
- name: Verify Ansible is accessible in the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker exec --tty test-container \
env TERM=xterm ansible --version
# Test AlmaLinux 9 with both Ansible versions
test-almalinux9:
name: Test AlmaLinux 9 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if AlmaLinux 9 files changed
id: changed
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
git fetch origin ${{ github.base_ref }}
if git diff --name-only \
origin/${{ github.base_ref }}...HEAD | \
grep -q "^docker-almalinux9-ansible/"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
else
# Always build on main branch or cron
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Set Ansible version build arg and tags
id: ansible
if: steps.changed.outputs.changed == 'true'
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag_suffix=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag_suffix=core-2.16" >> $GITHUB_OUTPUT
fi
# Set PR-specific tag if this is a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "docker_tag=pr-${PR_NUMBER}-${{ matrix.ansible_version }}" \
>> $GITHUB_OUTPUT
echo "should_push=true" >> $GITHUB_OUTPUT
else
echo "should_push=false" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- uses: docker/setup-buildx-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- name: Login to DockerHub
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push PR image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux9-ansible
file: ./docker-almalinux9-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
mrkoopie/almalinux9-ansible:${{ steps.ansible.outputs.docker_tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}
- name: Test building image locally
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker build \
--build-arg \
ANSIBLE_VERSION="${{ steps.ansible.outputs.build_arg }}" \
-t docker-ansible \
./docker-almalinux9-ansible
- name: Run the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: >-
docker run --name test-container -d --privileged
-v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host
docker-ansible
- name: Verify Ansible is accessible in the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker exec --tty test-container \
env TERM=xterm ansible --version
# Test AlmaLinux 10 with both Ansible versions
test-almalinux10:
name: Test AlmaLinux 10 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if AlmaLinux 10 files changed
id: changed
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
git fetch origin ${{ github.base_ref }}
if git diff --name-only \
origin/${{ github.base_ref }}...HEAD | \
grep -q "^docker-almalinux10-ansible/"; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
else
# Always build on main branch or cron
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Set Ansible version build arg and tags
id: ansible
if: steps.changed.outputs.changed == 'true'
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag_suffix=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag_suffix=core-2.16" >> $GITHUB_OUTPUT
fi
# Set PR-specific tag if this is a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
echo "docker_tag=pr-${PR_NUMBER}-${{ matrix.ansible_version }}" \
>> $GITHUB_OUTPUT
echo "should_push=true" >> $GITHUB_OUTPUT
else
echo "should_push=false" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- uses: docker/setup-buildx-action@v3
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
- name: Login to DockerHub
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push PR image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'true'
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux10-ansible
file: ./docker-almalinux10-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
mrkoopie/almalinux10-ansible:${{ steps.ansible.outputs.docker_tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}
- name: Test building image locally
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker build \
--build-arg \
ANSIBLE_VERSION="${{ steps.ansible.outputs.build_arg }}" \
-t docker-ansible \
./docker-almalinux10-ansible
- name: Run the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: >-
docker run --name test-container -d --privileged
-v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host
docker-ansible
- name: Verify Ansible is accessible in the built image
if: |
steps.changed.outputs.changed == 'true' &&
steps.ansible.outputs.should_push == 'false'
run: |
docker exec --tty test-container \
env TERM=xterm ansible --version
# Release AlmaLinux 8 images to DockerHub
release-almalinux8:
name: Release AlmaLinux 8 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
needs: test-almalinux8
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule'
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
- name: Set Ansible version build arg and tag
id: ansible
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag=core-2.16" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux8-ansible
file: ./docker-almalinux8-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mrkoopie/almalinux8-ansible:${{ steps.ansible.outputs.tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}
# Release AlmaLinux 9 images to DockerHub
release-almalinux9:
name: Release AlmaLinux 9 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
needs: test-almalinux9
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule'
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
- name: Set Ansible version build arg and tag
id: ansible
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag=core-2.16" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux9-ansible
file: ./docker-almalinux9-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mrkoopie/almalinux9-ansible:${{ steps.ansible.outputs.tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}
# Release AlmaLinux 10 images to DockerHub
release-almalinux10:
name: Release AlmaLinux 10 - Ansible ${{ matrix.ansible_version }}
runs-on: ubuntu-latest
needs: test-almalinux10
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule'
strategy:
matrix:
ansible_version: [latest, core-2.16]
steps:
- uses: actions/checkout@v4
- name: Set Ansible version build arg and tag
id: ansible
run: |
if [ "${{ matrix.ansible_version }}" == "latest" ]; then
echo "build_arg=ansible" >> $GITHUB_OUTPUT
echo "tag=latest" >> $GITHUB_OUTPUT
else
echo "build_arg=ansible-core~=2.16.0" >> $GITHUB_OUTPUT
echo "tag=core-2.16" >> $GITHUB_OUTPUT
fi
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: ./docker-almalinux10-ansible
file: ./docker-almalinux10-ansible/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: mrkoopie/almalinux10-ansible:${{ steps.ansible.outputs.tag }}
build-args: |
ANSIBLE_VERSION=${{ steps.ansible.outputs.build_arg }}