-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (57 loc) · 2.18 KB
/
deploy.yml
File metadata and controls
66 lines (57 loc) · 2.18 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Build & Push Portfolio Images
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
# IMPORTANT: NEXT_PUBLIC_* vars are build-time only in Next.js!
# They get embedded into the JS bundle during build.
# Set NEXT_PUBLIC_API_URL secret in GitHub repo settings, or change the default below.
# This should be the URL where users' browsers can reach the backend API.
- name: Build frontend image
run: |
API_URL="${{ secrets.NEXT_PUBLIC_API_URL }}"
if [ -z "$API_URL" ]; then
API_URL="https://portfolio-api.medevs.local"
fi
echo "Building frontend with API_URL: ${API_URL}"
docker build \
--build-arg NEXT_PUBLIC_API_URL=${API_URL} \
-t ghcr.io/${{ github.repository_owner }}/portfolio-frontend:latest \
./frontend
- name: Build backend image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/portfolio-backend:latest ./backend
- name: Push frontend image
run: |
docker push ghcr.io/${{ github.repository_owner }}/portfolio-frontend:latest
- name: Push backend image
run: |
docker push ghcr.io/${{ github.repository_owner }}/portfolio-backend:latest
deploy:
runs-on: self-hosted
needs: build-and-push
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to homelab
run: |
set -e
cd ~/projects/local-smart-portfolio
echo "📥 Pulling latest GHCR images..."
docker compose -f docker-compose.yml -f docker-compose.homelab.yml pull
echo "🔄 Recreating containers with homelab overrides..."
docker compose -f docker-compose.yml -f docker-compose.homelab.yml up -d --force-recreate
echo "🧹 Cleaning up old images..."
docker image prune -f
echo "✅ Deployment complete!"