Skip to content

Commit c263d84

Browse files
committed
自动化构建
1 parent 988b178 commit c263d84

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
tags: ["v*"]
7+
pull_request:
8+
branches: ["main"]
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: false
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to Docker Hub
28+
if: github.event_name != 'pull_request'
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ vars.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
- name: Log in to Container registry
34+
if: github.event_name != 'pull_request'
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ghcr.io
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
- name: Extract Docker metadata
41+
id: meta
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: |
45+
sunwuyuan/coderun
46+
ghcr.io/zerocatdev/coderun
47+
tags: |
48+
type=ref,event=branch
49+
type=ref,event=pr
50+
type=semver,pattern={{version}}
51+
type=semver,pattern={{major}}.{{minor}}
52+
type=semver,pattern={{major}}
53+
type=sha,format=long
54+
flavor: |
55+
latest=auto
56+
57+
- name: Show generated image tags
58+
run: echo "${{ steps.meta.outputs.tags }}"
59+
- name: Build and push Docker image
60+
uses: docker/build-push-action@v5
61+
with:
62+
context: .
63+
push: ${{ github.event_name != 'pull_request' }}
64+
tags: ${{ steps.meta.outputs.tags }}
65+
labels: ${{ steps.meta.outputs.labels }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)