Skip to content

Commit

Permalink
build:调整工作流
Browse files Browse the repository at this point in the history
  • Loading branch information
Akimio521 committed Aug 26, 2024
1 parent 8435fc2 commit 3e6fcaf
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 99 deletions.
48 changes: 8 additions & 40 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,12 @@ on:
- main

jobs:
Docker-build:
runs-on: ubuntu-latest
Dev-Docker-Builder:
name: Build Docker Image
steps:
- uses: actions/checkout@v4

- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/autofilm
tags: |
type=raw,value=DEV,enable=true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64/v8
push: true
build-args: |
AUTOFILM_VERSION=${{ env.APP_VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}-docker
cache-to: type=gha, scope=${{ github.workflow }}-docker
use: ./.github/workflows/docker-builder.yaml
with:
APP_VERSION: DEV
IS_LATEST: false
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
72 changes: 72 additions & 0 deletions .github/workflows/docker-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: AutoFilm Docker Builder

on:
workflow_call:
inputs:
APP_VERSION:
description: "用于Docker镜像版本的标签号"
required: true
type: string
IS_LATEST:
description: "是否发布为Docker镜像最新版本"
required: true
type: boolean
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

env:
APP_VERSION: ${{ inputs.APP_VERSION }}
IS_LATEST: ${{ inputs.IS_LATEST }}

jobs:
Docker-build:
runs-on: ubuntu-latest
name: Build Docker Image
steps:
- name: Show Information
run: |
echo "Docker镜像版本的标签号:${{ env.APP_VERSION }}"
echo "是否发布为Docker镜像最新版本:${{ env.IS_LATEST }}"
- name: Clone Repository
uses: actions/checkout@v4

- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/autofilm
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ env.APP_VERSION }},enable=true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64/v8
push: true
build-args: |
AUTOFILM_VERSION=${{ env.APP_VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}-docker
cache-to: type=gha, scope=${{ github.workflow }}-docker
84 changes: 25 additions & 59 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,46 @@ on:
paths:
- app/version.py

env:
APP_VERSION: "0.0.0"

jobs:
Docker-build:
Get-Version:
runs-on: ubuntu-latest
name: Build Docker Image
outputs:
app_version: ${{ steps.version.outputs.app_version }}
steps:
- uses: actions/checkout@v4

- name: Clone Repository
uses: actions/checkout@v4

- name: APP Version
id: version
run: |
echo "APP_VERSION=$(cat app/version.py | sed -ne 's/APP_VERSION\s=\s"v\(.*\)"/\1/gp')" >> $GITHUB_ENV
- name: Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/autofilm
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ env.APP_VERSION }},enable=true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
APP_VERSION=$(cat app/version.py | sed -ne 's/APP_VERSION\s=\s"v\(.*\)"/\1/gp')
echo "检测到版本号为 $APP_VERSION"
echo "app_version=$APP_VERSION" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: |
linux/amd64
linux/arm64/v8
push: true
build-args: |
AUTOFILM_VERSION=${{ env.APP_VERSION }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha, scope=${{ github.workflow }}-docker
cache-to: type=gha, scope=${{ github.workflow }}-docker

Create-release:
Release-Docker-Builder:
name: Build Docker Image
needs: [ Get-Version ]
use: ./.github/workflows/docker-builder.yaml
with:
APP_VERSION: ${{ needs.Get-Version.outputs.app_version }}
IS_LATEST: true
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

Create-Release:
permissions: write-all
runs-on: ubuntu-latest
needs: [ Docker-build ]
needs: [ Get-Version, Release-Docker-Builder ]
steps:
- uses: actions/checkout@v2

- name: Release Version
id: release_version
run: |
echo "APP_VERSION=$(cat app/version.py | sed -ne 's/APP_VERSION\s=\s"v\(.*\)"/\1/gp')" >> $GITHUB_ENV
- name: Download Artifact
uses: actions/download-artifact@v3

- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.APP_VERSION }}
release_name: v${{ env.APP_VERSION }}
tag_name: v${{ needs.Get-Version.outputs.app_version }}
release_name: v${{ needs.Get-Version.outputs.app_version }}
body: ${{ github.event.commits[0].message }}
draft: false
prerelease: false

0 comments on commit 3e6fcaf

Please sign in to comment.