-
Notifications
You must be signed in to change notification settings - Fork 1
88 lines (72 loc) · 3.56 KB
/
deploy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Deploy Next.js application
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Create .env file
run: |
echo "BASE_URL=${{ secrets.BASE_URL }}" >> .env
echo "CLOUDINARY_API_KEY=${{ secrets.CLOUDINARY_API_KEY }}" >> .env
echo "CLOUDINARY_API_SECRET=${{ secrets.CLOUDINARY_API_SECRET }}" >> .env
echo "CLOUDINARY_CLOUD_NAME=${{ secrets.CLOUDINARY_CLOUD_NAME }}" >> .env
echo "MONGO_URL=${{ secrets.MONGO_URL }}" >> .env
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env
echo "NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }}" >> .env
echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_API_KEY=${{ secrets.NEXT_PUBLIC_FIREBASE_API_KEY }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_APP_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_APP_ID }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=${{ secrets.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_PROJECT_ID=${{ secrets.NEXT_PUBLIC_FIREBASE_PROJECT_ID }}" >> .env
echo "NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${{ secrets.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET }}" >> .env
echo "RESEND_API_KEY=${{ secrets.RESEND_API_KEY }}" >> .env
echo "STRIPE_SECRET_KEY=${{ secrets.STRIPE_SECRET_KEY }}" >> .env
- name: Archive .env file
run: tar -czf env.tar.gz .env
- name: Build Docker image
run: docker build -t prominhaj/learn-pulse-edu .
- name: Login to Docker Hub
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Publish image to Docker Hub
run: docker push prominhaj/learn-pulse-edu:latest
- name: Upload environment file
uses: actions/upload-artifact@v3
with:
name: env-file
path: env.tar.gz
deploy:
needs: build
runs-on: self-hosted
steps:
- name: Download environment file
uses: actions/download-artifact@v3
with:
name: env-file
path: .
- name: Extract environment file
run: tar -xzf env.tar.gz
- name: Check Disk Space
run: df -h
- name: Stop and remove old container if exists
run: |
if [ $(docker ps -q -f name=nextjs-app-container) ]; then
docker stop nextjs-app-container
docker rm nextjs-app-container
fi
- name: Remove old Docker images
run: |
docker rmi -f $(docker images -q)
- name: Free up Docker space
run: |
docker system prune -af
docker volume prune -f
- name: Pull image from Docker Hub
run: docker pull prominhaj/learn-pulse-edu:latest
- name: Run Docker container
run: docker run -d -p 3000:3000 --env-file .env --name nextjs-app-container prominhaj/learn-pulse-edu:latest