Repository navigation
49 lines (41 loc) · 1.53 KB
/
Copy pathdocker.yml
File metadata and controls
49 lines (41 loc) · 1.53 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
# Optional: publish the image to Docker Hub on every push to main.
# Skips cleanly when DOCKERHUB_USERNAME / DOCKERHUB_PASSWORD are not set.
name: Build and Publish Docker Image to DockerHub
on:
push:
branches: ["main"]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Check DockerHub Credentials
id: check_creds
run: |
if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" ] && [ -n "${{ secrets.DOCKERHUB_PASSWORD }}" ]; then
echo "has_creds=true" >> $GITHUB_OUTPUT
else
echo "has_creds=false" >> $GITHUB_OUTPUT
echo "DockerHub credentials not provided; skipping image push."
fi
- name: DockerHub Login
if: steps.check_creds.outputs.has_creds == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Set up Docker Buildx
if: steps.check_creds.outputs.has_creds == 'true'
uses: docker/setup-buildx-action@v3
- name: Build and Push Docker image
if: steps.check_creds.outputs.has_creds == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}