-
Notifications
You must be signed in to change notification settings - Fork 8
43 lines (36 loc) · 1.06 KB
/
docker-build-on-commit.yml
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: Docker Build on Commit
on:
push:
branches:
- main
paths:
- 'Dockerfile'
- 'docker-compose.yml'
- '**.py'
- 'requirements.txt'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v3
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v2
- name: 登录到 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 获取短 SHA
id: vars
run: echo "GIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: 构建并推送 Docker 镜像
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ vars.DOCKERHUB_USERNAME }}/xybotv2:latest
${{ vars.DOCKERHUB_USERNAME }}/xybotv2:${{ env.GIT_SHA }}
cache-from: type=registry,ref=${{ vars.DOCKERHUB_USERNAME }}/xybotv2:latest
cache-to: type=inline