Build Rpi Manylinux Image #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow | |
name: Build Rpi Manylinux Image | |
# 当 push 到 master 分支,或者创建以 v 开头的 tag 时触发,可根据需求修改 | |
on: | |
workflow_dispatch: | |
ref: rpi | |
inputs: | |
image: | |
description: 'build image' | |
required: true | |
default: 'manylinux' | |
type: choice | |
options: | |
- manylinux | |
- rpi | |
env: | |
REGISTRY: ghcr.io | |
IMAGE: richard-xx/manylinux | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
# 这里用于定义 GITHUB_TOKEN 的权限 | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# 配置 QEMU 和 buildx 用于多架构镜像的构建 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
version: latest | |
config-inline: | | |
[worker.oci] | |
max-parallelism = 4 | |
- name: Inspect builder | |
run: | | |
echo "Name: ${{ steps.buildx.outputs.name }}" | |
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" | |
echo "Status: ${{ steps.buildx.outputs.status }}" | |
echo "Flags: ${{ steps.buildx.outputs.flags }}" | |
echo "Platforms: ${{ steps.buildx.outputs.platforms }}" | |
# 登录到 GitHub Packages 容器仓库 | |
# 注意 secrets.GITHUB_TOKEN 不需要手动添加,直接就可以用 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# 根据输入自动生成 tag 和 label 等数据,说明见下 | |
- name: Extract metadata for Docker | |
if: github.event.inputs.image == 'manylinux' | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE }} | |
tags: | | |
type=raw,value=rpi_stretch | |
type=raw,value=rpi_9 | |
# 构建并上传 | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
if: github.event.inputs.image == 'manylinux' | |
with: | |
context: . | |
file: ./Dockerfile | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/arm/v7 | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Inspect image | |
if: github.event.inputs.image == 'manylinux' | |
run: | | |
docker buildx imagetools inspect \ | |
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.meta.outputs.version }} | |
- name: Extract metadata for Docker | |
if: github.event.inputs.image == 'rpi' | |
id: meta_rpi | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/richard-xx/raspbian | |
tags: | | |
type=raw,value=stretch | |
type=raw,value=9 | |
# 构建并上传 | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
if: github.event.inputs.image == 'rpi' | |
with: | |
context: . | |
file: ./Dockerfile.rpi | |
builder: ${{ steps.buildx.outputs.name }} | |
platforms: linux/arm/v7 | |
push: true | |
tags: ${{ steps.meta_rpi.outputs.tags }} | |
labels: ${{ steps.meta_rpi.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Inspect image | |
if: github.event.inputs.image == 'rpi' | |
run: | | |
docker buildx imagetools inspect \ | |
${{ env.REGISTRY }}/richard-xx/raspbian:${{ steps.meta_rpi.outputs.version }} |