amirkabiri commited on
Commit
361f8ee
·
1 Parent(s): b0c801d

Add GitHub Actions workflow for Docker build and push to DockerHub

Browse files
.github/workflows/docker-build-push.yml ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build and Push Docker Image
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ types: [ closed ]
8
+ branches: [ main ]
9
+
10
+ jobs:
11
+ build-and-push:
12
+ runs-on: ubuntu-latest
13
+ # Only run on merged PRs or direct pushes to main
14
+ if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
15
+
16
+ steps:
17
+ - name: Checkout code
18
+ uses: actions/checkout@v4
19
+
20
+ - name: Set up Docker Buildx
21
+ uses: docker/setup-buildx-action@v3
22
+
23
+ - name: Login to DockerHub
24
+ uses: docker/login-action@v3
25
+ with:
26
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
27
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
28
+
29
+ - name: Extract metadata for Docker
30
+ id: meta
31
+ uses: docker/metadata-action@v5
32
+ with:
33
+ images: ${{ secrets.DOCKERHUB_USERNAME }}/duckai
34
+ tags: |
35
+ type=sha,format=short
36
+ type=ref,event=branch
37
+ type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
38
+
39
+ - name: Build and push Docker image
40
+ uses: docker/build-push-action@v5
41
+ with:
42
+ context: .
43
+ push: true
44
+ tags: ${{ steps.meta.outputs.tags }}
45
+ labels: ${{ steps.meta.outputs.labels }}
46
+ cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/duckai:buildcache
47
+ cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/duckai:buildcache,mode=max