-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (101 loc) · 3.82 KB
/
build.yml
File metadata and controls
116 lines (101 loc) · 3.82 KB
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
name: Build and Push Multi-arch Docker Images
permissions:
contents: read
packages: write
on:
workflow_dispatch:
inputs:
services:
description: "Comma-separated list of services to build (e.g., caddy,i2pd-tools). Leave empty to auto-detect."
required: false
type: string
default: ""
jobs:
setup-services:
runs-on: ubuntu-24.04
outputs:
services: ${{ steps.set-services.outputs.services }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up matrix
id: set-services
run: |
if [ -n "${{ github.event.inputs.services }}" ]; then
echo "Using provided services: ${{ github.event.inputs.services }}"
SERVICES=$(echo "${{ github.event.inputs.services }}" | tr ',' '\n' | xargs -I {} echo '"{}"' | jq -c -s '.')
else
echo "Auto-detecting projects..."
SERVICES=$(jq -r '.projects | keys[]' projects.json | jq -R . | jq -c -s '.')
fi
echo "services=$SERVICES" >> $GITHUB_OUTPUT
build:
needs: setup-services
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }}
strategy:
matrix:
service: ${{ fromJson(needs.setup-services.outputs.services) }}
arch: [amd64, arm64]
steps:
- name: Checkout code (sparse for service)
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
sparse-checkout: |
${{ matrix.service }}
projects.json
sparse-checkout-cone-mode: true
- name: Clone repository
run: |
REPO=$(jq -r ".projects.\"${{ matrix.service }}\".repo // empty" projects.json)
if [ -n "$REPO" ] && [ "$REPO" != "null" ]; then
REF=$(jq -r ".projects.\"${{ matrix.service }}\".ref" projects.json)
echo "Cloning $REPO:$REF into ${{ matrix.service }}/src/"
git clone --depth 1 --branch "$REF" --recursive "$REPO" "${{ matrix.service }}/src"
fi
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx (required to use buildx imagetools)
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- name: Build and push native image (per-arch)
uses: docker/build-push-action@v4
with:
context: ${{ matrix.service }}
file: ${{ matrix.service }}/Dockerfile
platforms: linux/${{ matrix.arch }}
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:${{ matrix.arch }}-latest
cache-from: type=gha
cache-to: type=gha,mode=max
create-manifest:
needs: [setup-services, build]
runs-on: ubuntu-24.04
strategy:
matrix:
service: ${{ fromJson(needs.setup-services.outputs.services) }}
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- name: Create and push multi-arch manifest (imagetools)
run: |
AMD64_TAG="ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:amd64-latest"
ARM64_TAG="ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:arm64-latest"
MULTI_TAG="ghcr.io/${{ github.repository_owner }}/${{ matrix.service }}:latest"
docker buildx imagetools create --tag "$MULTI_TAG" "$AMD64_TAG" "$ARM64_TAG"