Skip to content

Commit 48828bf

Browse files
committed
feat(ci): add GitHub Actions workflow for Docker image build and push
- Create a new workflow to build and push Docker images for backend and frontend applications to GitHub Container Registry - Configure steps for checking out the repository, setting up Docker Buildx, logging in to the registry, extracting metadata, and building/pushing images
1 parent cac1203 commit 48828bf

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and push Docker images to GHCR
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
strategy:
19+
matrix:
20+
include:
21+
- name: backend
22+
dockerfile: apps/backend/Dockerfile
23+
image: repohub-backend
24+
- name: frontend
25+
dockerfile: apps/frontend/Dockerfile
26+
image: repohub-frontend
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Log in to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ${{ env.REGISTRY }}
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract metadata (tags, labels)
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
47+
tags: |
48+
type=ref,event=branch
49+
type=sha,prefix=
50+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
file: ${{ matrix.dockerfile }}
57+
push: true
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)