-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (107 loc) · 3.68 KB
/
Copy pathbuild-image.yml
File metadata and controls
120 lines (107 loc) · 3.68 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
117
118
119
120
name: 建置 · Smoke 測試 (Build + Smoke)
on:
workflow_dispatch:
inputs:
image:
description: |
Image name (directory name under images/).
Use "all" to build every image.
required: true
default: 'py-devkit-image-base'
env:
REGISTRY: ghcr.io
ORG: shumingyang-opencode
jobs:
discover:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.discover.outputs.matrix }}
steps:
- uses: actions/checkout@v7
- id: discover
run: |
if [ "all" = "${{ inputs.image }}" ]; then
FIRST=true
JSON='{"image":['
for dir in images/*/; do
name=$(basename "$dir")
[ -f "images/$name/Dockerfile" ] || continue
if [ "$FIRST" = true ]; then
JSON="$JSON\"$name\""
FIRST=false
else
JSON="$JSON,\"$name\""
fi
done
JSON="$JSON]}"
echo "matrix=$JSON" >> "$GITHUB_OUTPUT"
else
if [ ! -d "images/${{ inputs.image }}" ]; then
echo "Error: images/${{ inputs.image }} not found"
exit 1
fi
echo "matrix={\"image\":[\"${{ inputs.image }}\"]}" >> "$GITHUB_OUTPUT"
fi
build:
needs: discover
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix: ${{ fromJSON(needs.discover.outputs.matrix) }}
steps:
- uses: actions/checkout@v7
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version from Dockerfile
id: version
run: |
IMG=${{ matrix.image }}
VER=$(grep -oP 'org\.opencontainers\.image\.version="\K[^"]+' images/$IMG/Dockerfile || echo "0.0.0")
echo "version=$VER" >> "$GITHUB_OUTPUT"
echo "image=$IMG" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push
uses: docker/build-push-action@v7
with:
context: ./images/${{ steps.version.outputs.image }}
file: ./images/${{ steps.version.outputs.image }}/Dockerfile
push: true
tags: |
${{ env.REGISTRY }}/${{ env.ORG }}/${{ steps.version.outputs.image }}:${{ steps.version.outputs.version }}
${{ env.REGISTRY }}/${{ env.ORG }}/${{ steps.version.outputs.image }}:latest
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
test:
needs: [build, discover]
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
strategy:
matrix: ${{ fromJSON(needs.discover.outputs.matrix) }}
steps:
- uses: actions/checkout@v7
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image info
id: info
run: |
IMG=${{ matrix.image }}
VER=$(grep -oP 'org\.opencontainers\.image\.version="\K[^"]+' images/$IMG/Dockerfile || echo "0.0.0")
echo "tag=${{ env.REGISTRY }}/${{ env.ORG }}/$IMG:$VER" >> "$GITHUB_OUTPUT"
- name: Run smoke tests
run: |
docker pull ${{ steps.info.outputs.tag }}
docker run --rm -i ${{ steps.info.outputs.tag }} bash < images/${{ matrix.image }}/test-smoke.sh