Skip to content

Merge pull request #340 from pysio2007/deepsource-autofix-ea9fa82e #286

Merge pull request #340 from pysio2007/deepsource-autofix-ea9fa82e

Merge pull request #340 from pysio2007/deepsource-autofix-ea9fa82e #286

Workflow file for this run

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow
name: Build Docker Image
# 当 push 到 master 分支,或者创建以 v 开头的 tag 时触发,可根据需求修改
on:
push:
branches:
- main
tags:
- v*
env:
REGISTRY: docker.io
IMAGE: pysio/pysioblog
jobs:
build-and-push:
runs-on: ubuntu-latest
# 这里用于定义 GITHUB_TOKEN 的权限
permissions:
packages: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
# 缓存 Docker 镜像以加速构建
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: ./
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# 配置 QEMU 和 buildx
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- 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 }}"
# 登录到 Docker Hub 容器仓库
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# 根据输入自动生成 tag 和 label 等数据,说明见下
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE }}
# 构建并上传
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Inspect image
run: |
docker buildx imagetools inspect \
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ steps.meta.outputs.version }}