-
-
Notifications
You must be signed in to change notification settings - Fork 7
48 lines (41 loc) · 1.71 KB
/
docker-build-publish.yml
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
name: Build and Publish Docker Image
# Trigger the workflow on push or pull request to the main branch
on:
push:
# branches:
# - main
# - release
tags:
- 'v*.*.*'
# pull_request:
# branches:
# - main
# - release
workflow_dispatch:
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository code
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Step 3: Log in to Docker Hub (or GHCR if you prefer)
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }} # Docker Hub username (use GitHub actor if using GHCR)
password: ${{ secrets.GITHUB_TOKEN }} # Docker Hub password (use GitHub token if using GHCR)
# Step 4: Build and push the backend Docker image
- name: Build and push backend Docker image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/farmcart-api:latest -f ./backend/Dockerfile.prod ./backend
docker push ghcr.io/${{ github.repository_owner }}/farmcart-api:latest
# Step 5: Build and push the frontend Docker image
- name: Build and push frontend Docker image
run: |
docker build --build-arg VITE_STRIPE_PUBLIC_KEY=${{ secrets.VITE_STRIPE_PUBLIC_KEY }} --build-arg VITE_MAPBOX_API_KEY=${{ secrets.VITE_MAPBOX_API_KEY }} -t ghcr.io/${{ github.repository_owner }}/farmcart-app:latest -f ./frontend/Dockerfile.prod ./frontend
docker push ghcr.io/${{ github.repository_owner }}/farmcart-app:latest