-
-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (95 loc) · 3.93 KB
/
service_docker-build-and-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Build and Publish Docker Images
on:
workflow_call:
inputs:
release_type:
type: string
required: true
description: 'Release type (latest, beta, edge, dev, etc)'
default: 'edge'
ref:
type: string
default: ${{ github.ref }}
description: 'The git ref to checkout (branch, tag, or commit SHA)'
jobs:
setup-matrix:
runs-on: ubuntu-24.04
outputs:
ansible-version-map-json: ${{ steps.get-ansible-versions.outputs.matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Assemble Ansible versions into the matrix 😎
id: get-ansible-versions
run: |
MATRIX_JSON=$(yq eval -o=json ansible-versions.yml | jq -c '{include: [.ansible_variations[] | select(.versions != null) as $variation | .versions[] as $version | ($version.python_versions // [])[] as $python | ($version.base_os // [])[] as $os | {ansible_variation: $variation.name, ansible_version: $version.version, python_version: $python, base_os: $os.name, latest_stable: ($version.latest_stable // false)}]}')
echo "matrix=${MATRIX_JSON}" >> $GITHUB_OUTPUT
echo "Generated matrix:"
echo "${MATRIX_JSON}" | jq '.'
build-and-push:
needs: setup-matrix
runs-on: ubuntu-24.04
strategy:
matrix: ${{fromJson(needs.setup-matrix.outputs.ansible-version-map-json)}}
steps:
- name: Check out code.
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: "📦 Assemble the Docker Tags"
run: |
bash build.sh \
--variation ${{ matrix.ansible_variation }} \
--version ${{ matrix.ansible_version }} \
--python ${{ matrix.python_version }} \
--os ${{ matrix.base_os }} \
--release-type ${{ inputs.release_type }} \
--print-tags-only\
- name: Set REPOSITORY_BUILD_VERSION
id: set_version
run: |
if [ "${{ github.ref_type }}" == "tag" ]; then
echo "🚀 Setting REPOSITORY_BUILD_VERSION to Tag"
echo "REPOSITORY_BUILD_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
else
echo "👨🔬 Setting REPOSITORY_BUILD_VERSION to GIT Short SHA and GitHub Run ID"
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
echo "REPOSITORY_BUILD_VERSION=git-${SHORT_SHA}-${{ github.run_id }}" >> $GITHUB_ENV
fi
- name: Build and push
uses: docker/build-push-action@v6
with:
file: src/Dockerfile
cache-from: type=gha,mode=max
cache-to: type=gha,mode=max
build-args: |
BUILD_PYTHON_VERSION=${{ matrix.python_version }}
BUILD_BASE_OS_VERSION=${{ matrix.base_os }}
BUILD_ANSIBLE_VARIATION=${{ matrix.ansible_variation }}
BUILD_ANSIBLE_PATCH_VERSION=${{ env.BUILD_ANSIBLE_PATCH_VERSION }}
PACKAGE_DEPENDENCIES=${{ env.PACKAGE_DEPENDENCIES }}
REPOSITORY_BUILD_VERSION=${{ env.REPOSITORY_BUILD_VERSION }}
platforms: |
linux/amd64
linux/arm64/v8
pull: true
push: true
tags: ${{ env.DOCKER_TAGS }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Run Ansible anywhere with the power of Docker