-
Notifications
You must be signed in to change notification settings - Fork 3
92 lines (80 loc) · 3.06 KB
/
build.yml
File metadata and controls
92 lines (80 loc) · 3.06 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
name: build-docker-image
on:
workflow_dispatch:
inputs:
targets:
description: 'Targets to build'
required: true
default: 'all'
tool_chain_version:
description: 'Tool chain version'
required: false
default: 'stable'
tag:
description: 'remark'
required: false
default: 'latest'
jobs:
set_matrix:
runs-on: ubuntu-22.04
outputs:
targets_json: ${{ steps.set_targets.outputs.targets_json }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Parse and Find Dockerfiles for Targets
id: set_targets
run: |
TARGETS="${{ github.event.inputs.targets }}"
if [[ "$TARGETS" == "all" ]]; then
# Find all Dockerfile paths and extract the architecture part (e.g., aarch64-apple-darwin)
TARGETS=$(find Dockerfiles -type f -name 'Dockerfile.*' | grep -v 'Dockerfile.cross-base' | sed -E 's|.*/Dockerfile\.||' | paste -sd ',')
fi
TARGETS_JSON=$(echo "[\"${TARGETS//,/\",\"}\"]")
echo "targets_json=$TARGETS_JSON" >> $GITHUB_OUTPUT
build:
needs: set_matrix
runs-on: ubuntu-22.04
continue-on-error: true
strategy:
matrix:
target: ${{ fromJson(needs.set_matrix.outputs.targets_json) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Chmod +x for script
run: chmod -R +x script/
- name: Generate image name
run: |
IMAGE_NAME=${{ matrix.target }}:${{ github.event.inputs.tool_chain_version }}
DOCKERFILE=$(find Dockerfiles/*/*/*${{ matrix.target }} -name 'Dockerfile.*')
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
echo "DOCKERFILE=$DOCKERFILE" >> $GITHUB_ENV
- name: Build (${{ matrix.target }})
run: |
docker build \
--label "org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}" \
--build-arg TOOLCHAIN_VERSION=${{ github.event.inputs.tool_chain_version }} \
-t ${{ env.IMAGE_NAME }} \
-f ${{ env.DOCKERFILE }} .
- name: Push to ghcr.io
run: |
docker tag ${{ env.IMAGE_NAME }} ghcr.io/${{ secrets.GHCR_USERNAME }}/${{ env.IMAGE_NAME }}
docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/${{ env.IMAGE_NAME }}
- name: Push to DockerHub
run: |
docker tag ${{ env.IMAGE_NAME }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}