Skip to content

Commit e8dfab6

Browse files
author
davidbingmann
committed
Add GitHub Actions workflow for Docker build and push
1 parent a098930 commit e8dfab6

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v3
19+
20+
- name: Log in to Docker Hub
21+
if: github.event_name != 'pull_request'
22+
uses: docker/login-action@v3
23+
with:
24+
username: ${{ secrets.DOCKER_USERNAME }}
25+
password: ${{ secrets.DOCKER_PASSWORD }}
26+
27+
- name: Extract metadata
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ${{ secrets.DOCKER_USERNAME }}/davidbingmann-de
32+
tags: |
33+
type=ref,event=branch
34+
type=ref,event=pr
35+
type=sha
36+
type=raw,value=latest,enable={{is_default_branch}}
37+
38+
- name: Build and push Docker image
39+
uses: docker/build-push-action@v5
40+
with:
41+
context: .
42+
file: ./Dockerfile
43+
push: ${{ github.event_name != 'pull_request' }}
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)