Skip to content

Commit a8f7831

Browse files
committed
docker: build dep images
1 parent 71d9a20 commit a8f7831

3 files changed

Lines changed: 99 additions & 1 deletion

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and Push Dependency Images
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- 'install_deps.sh'
9+
- 'docker/Dockerfile.deps'
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
15+
jobs:
16+
# amd64 和 arm64 都用各自架构的原生 runner 构建(和 create-release.yml 的策略保持一致),
17+
# 不使用 QEMU 模拟,避免影响构建速度。
18+
build:
19+
runs-on: ${{ matrix.os }}
20+
permissions:
21+
contents: read
22+
packages: write
23+
strategy:
24+
matrix:
25+
os: [ubuntu-latest, ubuntu-24.04-arm]
26+
version: ["ubuntu:noble", "ubuntu:jammy", "ubuntu:focal", "debian:trixie", "debian:bookworm", "debian:bullseye"]
27+
fail-fast: false
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v5
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Log in to Container Registry
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Compute image tag
44+
id: vars
45+
run: |
46+
CODENAME=$(echo "${{ matrix.version }}" | cut -d':' -f2)
47+
ARCH="amd64"
48+
[[ "${{ matrix.os }}" == *arm* ]] && ARCH="arm64"
49+
echo "codename=${CODENAME}" >> $GITHUB_OUTPUT
50+
echo "arch=${ARCH}" >> $GITHUB_OUTPUT
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
file: ./docker/Dockerfile.deps
57+
build-args: |
58+
BASE_IMAGE=${{ matrix.version }}
59+
push: true
60+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }}
61+
cache-from: type=gha,scope=deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }}
62+
cache-to: type=gha,mode=max,scope=deps-${{ steps.vars.outputs.codename }}-${{ steps.vars.outputs.arch }}

.github/workflows/create-release.yml

100644100755
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77

88
permissions:
99
contents: write
10+
packages: read
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
1015

1116
jobs:
1217
build:
@@ -24,10 +29,30 @@ jobs:
2429
fetch-depth: 0
2530
persist-credentials: false
2631

32+
- name: Set image tag
33+
id: vars
34+
run: |
35+
CODENAME=$(echo "${{ matrix.version }}" | cut -d':' -f2)
36+
ARCH="amd64"
37+
[[ "${{ matrix.os }}" == *arm* ]] && ARCH="arm64"
38+
echo "arch=${ARCH}" >> $GITHUB_OUTPUT
39+
echo "codename=${CODENAME}" >> $GITHUB_OUTPUT
40+
echo "image=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:deps-${CODENAME}-${ARCH}" >> $GITHUB_OUTPUT
41+
42+
- name: Log in to Container Registry
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Pull prebuilt dependency image
50+
run: docker pull ${{ steps.vars.outputs.image }}
51+
2752
- name: Compile ${{ matrix.version }} on ${{ matrix.os }}
2853
run: |
2954
./pullsrc.sh
30-
docker run --rm -v ${{ github.workspace }}:/work -w /work library/${{ matrix.version }} bash -c "./install_deps.sh && ./compile.sh"
55+
docker run --rm -v ${{ github.workspace }}:/work -w /work ${{ steps.vars.outputs.image }} bash -c "./compile.sh"
3156
3257
- name: Install test with ${{ matrix.version }}
3358
run: |

docker/Dockerfile.deps

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 通用依赖镜像:基于任意 ubuntu/debian 基础镜像,预先跑好 install_deps.sh
2+
# 用法(构建时传入 BASE_IMAGE):
3+
# docker build --build-arg BASE_IMAGE=ubuntu:noble -f docker/Dockerfile.deps -t xxx .
4+
ARG BASE_IMAGE
5+
FROM ${BASE_IMAGE}
6+
7+
COPY install_deps.sh /tmp/install_deps.sh
8+
9+
RUN chmod +x /tmp/install_deps.sh \
10+
&& /tmp/install_deps.sh \
11+
&& rm -f /tmp/install_deps.sh

0 commit comments

Comments
 (0)