Skip to content

Commit 8e72eaf

Browse files
committed
feat(ci): push Docker image to ghcr.io on main
On main branch: build and push with sha-<commit> and latest tags. On PR: build only (verify image is buildable). Images: ghcr.io/nantian-gw/nantian-controlplane
1 parent f15e107 commit 8e72eaf

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/docker.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
packages: write
14+
15+
jobs:
16+
build:
17+
name: Build image
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v6
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v4
24+
25+
- name: Docker metadata
26+
id: meta
27+
uses: docker/metadata-action@v6
28+
with:
29+
images: ghcr.io/${{ github.repository_owner }}/nantian-controlplane
30+
tags: |
31+
type=sha,prefix=sha-,format=short
32+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
33+
34+
- name: Login to GHCR
35+
if: github.ref == 'refs/heads/main'
36+
uses: docker/login-action@v4
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Build and push
43+
uses: docker/build-push-action@v7
44+
with:
45+
context: .
46+
push: ${{ github.ref == 'refs/heads/main' }}
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)