-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (45 loc) Β· 1.54 KB
/
Copy pathdocker-publish.yml
File metadata and controls
53 lines (45 loc) Β· 1.54 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
44
45
46
47
48
49
50
51
52
53
name: Docker Build and Push
on:
push:
branches: [ main, 'feature/*' ]
pull_request:
branches: [ main ]
jobs:
build-and-push:
name: Build and Push to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
# Secrets are NOT available on pull_request events β skip login on PRs
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push Docker image (push event)
# On push: build + push to Docker Hub with clean, valid tags
if: github.event_name == 'push'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
udaycodespace/credify:latest
udaycodespace/credify:v2
udaycodespace/credify:sha-${{ github.sha }}
cache-from: type=registry,ref=udaycodespace/credify:buildcache
cache-to: type=registry,ref=udaycodespace/credify:buildcache,mode=max
- name: Build only (pull_request validation β no push)
# On PR: just validate the image builds cleanly β no login, no push
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: credify:pr-validate
- name: Image digest
run: echo "β
Docker build step completed."