forked from ling-drag0n/CloudPaste
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (59 loc) · 2.02 KB
/
docker-build-backend.yml
File metadata and controls
68 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Build and Push backend Docker Image
on:
workflow_dispatch:
inputs:
version:
description: "自定义版本标签(不包含v前缀)"
required: false
default: ""
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-version.outputs.version }}
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 设置版本
id: set-version
run: |
# 1. 首先检查是否有手动指定的版本
if [[ "${{ github.event.inputs.version }}" != "" ]]; then
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
exit 0
fi
# 2. 使用短提交哈希作为版本(因为没有标签推送触发)
SHORT_SHA=$(git rev-parse --short HEAD)
echo "version=dev-${SHORT_SHA}" >> $GITHUB_OUTPUT
build-backend:
needs: setup
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 设置QEMU
uses: docker/setup-qemu-action@v3
- name: 设置Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 登录到Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 构建并推送后端镜像
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/backend/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/cloudpaste-backend:latest
${{ secrets.DOCKERHUB_USERNAME }}/cloudpaste-backend:${{ needs.setup.outputs.version }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}