54 lines
2.5 KiB
YAML
54 lines
2.5 KiB
YAML
name: Build Tutorial
|
||
|
||
# 主仓库 gitea.idealjs.com/idealjs/stack 的 CI:打包新教程站。
|
||
# 构建环境全部封装在仓库根 Dockerfile(node24-bookworm-slim + yarn4 + npmmirror),
|
||
# runner 用 buildah 无 daemon 执行——不依赖 runner 宿主的 node/docker,也不碰 github.com。
|
||
# 源码:gitea API tarball(同机房);产物留在镜像 stack-tutorial:ci 内(/repo/apps/tutorial/dist)
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
pull_request:
|
||
workflow_dispatch:
|
||
|
||
env:
|
||
YARN_NPM_REGISTRY_SERVER: https://registry.npmmirror.com
|
||
API: https://gitea.idealjs.com/api/v1/repos/idealjs/stack
|
||
|
||
jobs:
|
||
build:
|
||
name: Build @stack/tutorial (buildah)
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: 拉源码(gitea tarball)
|
||
run: |
|
||
wget -q "$API/archive/$GITHUB_SHA.tar.gz" -O /tmp/src.tgz
|
||
tar -xzf /tmp/src.tgz --strip-components=1
|
||
ls Dockerfile
|
||
|
||
- name: 装 buildah(runner 无 docker;buildah 无 daemon 即可构建)
|
||
run: |
|
||
command -v buildah >/dev/null && exit 0
|
||
# 服务器在阿里云——apk 走阿里镜像源(dl-cdn 直连极慢)
|
||
sed -i 's#https://dl-cdn.alpinelinux.org#https://mirrors.aliyun.com#g' /etc/apk/repositories
|
||
apk add --no-cache buildah
|
||
|
||
- name: buildah 登录阿里云镜像仓(基座为私有 idealjs/node)
|
||
env:
|
||
ALIYUN_DOCKER_USERNAME: ${{ secrets.ALIYUN_DOCKER_USERNAME }}
|
||
ALIYUN_DOCKER_PASSWORD: ${{ secrets.ALIYUN_DOCKER_PASSWORD }}
|
||
run: |
|
||
printf '%s' "$ALIYUN_DOCKER_PASSWORD" | buildah login --username "$ALIYUN_DOCKER_USERNAME" --password-stdin registry.cn-hangzhou.aliyuncs.com
|
||
# authfile 按域名区分——构建走 VPC 端点,需单独 login(凭据相同)
|
||
printf '%s' "$ALIYUN_DOCKER_PASSWORD" | buildah login --username "$ALIYUN_DOCKER_USERNAME" --password-stdin registry-vpc.cn-hangzhou.aliyuncs.com
|
||
|
||
- name: buildah 构建镜像(环境封装在 Dockerfile)
|
||
run: |
|
||
# runner 与镜像仓同 region(杭州)——基座走 VPC 内网端点,快且不占公网带宽
|
||
buildah build --storage-driver=vfs --build-arg BASE_REGISTRY=registry-vpc.cn-hangzhou.aliyuncs.com -f Dockerfile -t stack-tutorial:ci .
|
||
|
||
- name: buildah 登出(清掉 runner 上 auth.json 里的凭据;长驻 runner 不留凭据)
|
||
if: always()
|
||
run: |
|
||
buildah logout registry.cn-hangzhou.aliyuncs.com || true
|
||
buildah logout registry-vpc.cn-hangzhou.aliyuncs.com || true
|