@@ -2,10 +2,12 @@ name: Build and Publish
2
2
3
3
on :
4
4
push :
5
+ branches : [ 'main', 'master' ] # Trigger on push to 'main'& 'master' master will be remove step by step
6
+ tags : [ '[0-9]+.[0-9]+.[0-9]+' ] # Trigger on version tags like '0.1.0'
5
7
6
8
jobs :
7
9
build-and-publish :
8
- name : Build and Publish
10
+ name : Build and Publish Docker image
9
11
runs-on : ubuntu-latest
10
12
steps :
11
13
- name : Checkout code
@@ -17,13 +19,31 @@ jobs:
17
19
username : ${{ secrets.DOCKERHUB_USERNAME }}
18
20
password : ${{ secrets.DOCKERHUB_TOKEN }}
19
21
22
+ - name : Log in to GitHub Container Registry
23
+ uses : docker/login-action@v3
24
+ with :
25
+ registry : ghcr.io
26
+ username : ${{ github.actor }}
27
+ password : ${{ secrets.GITHUB_TOKEN }}
28
+
20
29
- name : Extract metadata (tags, labels) for Docker
21
30
id : meta
22
31
uses : docker/metadata-action@v5
23
32
with :
24
- images : ${{ vars.DOCKER_ORG }}/${{ github.event.repository.name }}
33
+ images : |
34
+ ${{ vars.DOCKER_ORG }}/${{ github.event.repository.name }}
35
+ ghcr.io/${{ github.repository }}
36
+ tags : |
37
+ type=ref,event=branch # Tag with branch name
38
+ type=semver,pattern={{version}}
39
+ type=semver,pattern={{major}}.{{minor}}
40
+ type=semver,pattern={{major}}
41
+ # labels: |
42
+ # org.opencontainers.image.source=${{ github.repository }}
43
+ # org.opencontainers.image.revision=${{ github.sha }}
44
+ # org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
25
45
26
- - name : Build and push Docker image
46
+ - name : Build and push Docker image to DockerHub and GHCR
27
47
uses : docker/build-push-action@v5
28
48
with :
29
49
context : .
0 commit comments