-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (122 loc) · 4.38 KB
/
scatter_build_and_push_to_ghcrio.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: build_docker_container_and_push_to_ghcrio
on:
push:
branches:
- "main"
concurrency: image_builds
jobs:
get_images_to_build:
runs-on: ubuntu-latest
steps:
# Standard checkout step
- name: Checkout code
id: checkout_code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Log in to GitHub Container registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Determine images that need work
- id: get_images_to_build
run: |
python3 .github/scripts/get-images-to-build.py
env:
REPO_NAME: ${{ github.repository_owner }}
# Output value for images to build
outputs:
image_tags_to_build: ${{ steps.get_images_to_build.outputs.image_tags_to_build }}
scatter_image_builds:
needs: get_images_to_build
runs-on: ubuntu-latest
strategy:
matrix:
image_tag: ${{ fromJSON(needs.get_images_to_build.outputs.image_tags_to_build) }}
fail-fast: false # Don't fail if one image fails to run
steps:
# Standard checkout step
- name: Checkout code
id: git_checkout
uses: actions/checkout@v4
with:
lfs: true
# Tag to path
- name: Strip tag as path
id: tag_to_path
run: echo "image_path=$( echo ${{ matrix.image_tag }} | tr ':' '/' )" >> "${GITHUB_OUTPUT}"
# Check if platforms.yaml is present
- name: Get platforms to build
id: get_platforms
shell: bash
run: |
# FIXME eventually place conditional if platforms exist
# Get platforms
DEFAULT_PLATFORMS_STR="linux/amd64,linux/arm64"
# Config path
config_path="repositories/${{ steps.tag_to_path.outputs.image_path }}/config.yaml"
# Initialise
platforms_str=""
# Get config.yaml to determine output
if [[ -f "${config_path}" ]]; then
# Docker ception - run yq container
platforms_str="$(docker run --rm \
--volume "$PWD:$PWD" \
--workdir "$PWD" \
docker.io/mikefarah/yq:4.23.1 \
'.platforms | join(",")' \
"${config_path}")"
fi
# If string is empty, set default platforms
if [[ -z "${platforms_str}" ]]; then
platforms_str="${DEFAULT_PLATFORMS_STR}"
fi
# Set output
echo "platforms_as_str=${platforms_str}" >> "${GITHUB_OUTPUT}"
# Use qemu to perform multiplatform builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Use docker buildx to build multi-platform containers
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
use: true
install: true
buildkitd-config-inline: |
[worker.oci]
max-parallelism = 2
# Log in to GitHub Container registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push docker images
- name: Build and Push Docker Image
uses: docker/build-push-action@v5
with:
context: repositories/${{ steps.tag_to_path.outputs.image_path }}
platforms: ${{ steps.get_platforms.outputs.platforms_as_str }}
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.image_tag }}
# Ensure if image is latest, push latest tag with skopeo
# Determine images that need work
- name: Push latest tag
id: push_latest_tag
shell: bash
run: |
# Push latest tag
# Install semantic version
pip install semantic-version
# Run latest tag python script
python3 .github/scripts/push-latest-tag.py
env:
REGISTRY: ghcr.io
ORG_NAME: ${{ github.repository_owner }}
REPO_TAG: ${{ matrix.image_tag }}
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}