还原: 恢复Dockerfile到原始版本 #26
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
# 工作流名称 | |
name: 构建并推送 Docker 镜像 | |
# 定义触发工作流的条件 | |
on: | |
push: | |
branches: [ "main" ] # 只在 main 分支上触发 | |
paths: | |
- 'Dockerfile' # 当 Dockerfile 发生变化时触发 | |
- 'version' # 当 version 文件发生变化时触发 | |
pull_request: | |
branches: [ "main" ] # 当对 main 分支发起 pull request 时触发 | |
workflow_dispatch: # 允许手动触发工作流 | |
# 环境变量 | |
env: | |
IMAGE_NAME: rss2tg # Docker 镜像名称 | |
# 定义工作流中的任务 | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest # 在最新版本的 Ubuntu 上运行 | |
steps: | |
# 步骤1: 检出代码 | |
- name: 检出代码 | |
uses: actions/checkout@v2 | |
# 步骤2: 读取版本号 | |
- name: 读取版本号 | |
id: get_version | |
run: echo "VERSION=$(cat version)" >> $GITHUB_OUTPUT | |
# 步骤3: 设置 QEMU(用于多架构构建) | |
- name: 设置 QEMU | |
uses: docker/setup-qemu-action@v1 | |
# 步骤4: 设置 Docker Buildx(用于构建 Docker 镜像) | |
- name: 设置 Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
# 步骤5: 登录到 GitHub Container Registry | |
- name: 登录到 GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# 新步骤: 登录到 DockerHub | |
- name: 登录到 DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# 步骤6: 构建并推送 Docker 镜像到 GitHub Container Registry 和 DockerHub | |
- name: 构建并推送 | |
uses: docker/build-push-action@v2 | |
with: | |
context: . # 构建上下文为当前目录 | |
push: true # 推送镜像到仓库 | |
platforms: linux/amd64,linux/arm64 # 构建多架构镜像 | |
tags: | # 定义镜像标签 | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest | |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }} |