Skip to content

Commit f8e4b74

Browse files
committed
chore(ci): update Docker workflows for publishing images
- Change Docker image publishing from GitHub Container Registry to Docker Hub - Add a new workflow for publishing images to GitHub Packages - Update paths and permissions in the Docker publish workflow - Adjust metadata extraction and login steps for Docker Hub
1 parent 4165bfc commit f8e4b74

2 files changed

Lines changed: 85 additions & 12 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
name: Build and push Docker images to GHCR
1+
name: Publish Docker images to Docker Hub
22

33
on:
44
push:
55
branches: [main]
6+
paths:
7+
- "apps/backend/**"
8+
- "apps/frontend/**"
9+
- ".github/workflows/docker-publish.yml"
610
workflow_dispatch:
711

812
env:
9-
REGISTRY: ghcr.io
13+
REGISTRY: docker.io
1014

1115
jobs:
12-
build-and-push:
16+
publish:
1317
runs-on: ubuntu-latest
1418
permissions:
1519
contents: read
16-
packages: write
1720

1821
strategy:
1922
matrix:
@@ -32,24 +35,24 @@ jobs:
3235
- name: Set up Docker Buildx
3336
uses: docker/setup-buildx-action@v3
3437

35-
- name: Log in to GitHub Container Registry
38+
- name: Log in to Docker Hub
3639
uses: docker/login-action@v3
3740
with:
3841
registry: ${{ env.REGISTRY }}
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
42+
username: ${{ secrets.DOCKERHUB_USERNAME }}
43+
password: ${{ secrets.DOCKERHUB_TOKEN }}
4144

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

0 commit comments

Comments
 (0)