Skip to content

Commit 871988d

Browse files
committed
feat: add GitHub Actions workflow for Docker image CI/CD
1 parent dba8320 commit 871988d

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Docker Image CI/CD
2+
3+
on:
4+
push:
5+
branches: [master]
6+
env:
7+
IMAGE_NAME: OpenShop-Django-REST-API
8+
9+
jobs:
10+
build-and-push:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Log in to GitHub Container Registry
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Log in to Docker Hub
28+
uses: docker/login-action@v3
29+
with:
30+
username: ${{ secrets.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
# Extract metadata for Docker image
34+
- name: Extract Docker metadata
35+
id: meta
36+
uses: docker/metadata-action@v5
37+
with:
38+
images: |
39+
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
40+
docker.io/${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
type=semver,pattern={{version}}
43+
type=semver,pattern={{major}}.{{minor}}
44+
type=sha,format=short
45+
type=ref,event=branch
46+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
47+
48+
- name: Build and push Docker image
49+
uses: docker/build-push-action@v5
50+
with:
51+
context: .
52+
push: ${{ github.event_name != 'pull_request' }}
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)