forked from LoserLus/DBond
-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (37 loc) · 1.12 KB
/
build_docker_image.yml
File metadata and controls
43 lines (37 loc) · 1.12 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
name: Auto Build Docker Image x86
on:
push:
branches:
- main
paths:
- 'Dockerfile'
- '.github/workflows/build_docker_image.yml'
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: 检出源码
- name: Checkout source
uses: actions/checkout@v4
# Step 2: 提取 SHA 的前 5 位
- name: Extract short SHA
id: short_sha
run: |
SHORT_SHA="${{ github.sha }}"
echo "SHORT_SHA=${SHORT_SHA:0:5}" >> $GITHUB_OUTPUT
# Step 3: 登录 Docker Hub
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Step 4: 构建并推送镜像(支持多标签)
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/dbond_env:latest
${{ secrets.DOCKERHUB_USERNAME }}/dbond_env:${{ steps.short_sha.outputs.SHORT_SHA }}