generated from Xen0Xys/NestJS-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (52 loc) · 1.8 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
name: Build & Deploy API
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Secret check
env:
YOUR_SECRET: ${{ secrets.DOCKER_PASSWORD }}
run: |
if [ -z "$YOUR_SECRET" ]; then
echo "The secret is not defined. Exiting."
echo "SECRET_NOT_DEFINED=true" >> "$GITHUB_ENV"
else
echo "The secret is defined. Continuing."
fi
- name: Checkout
if: env.SECRET_NOT_DEFINED != 'true'
uses: actions/checkout@v4
- name: Set up Docker Buildx
if: env.SECRET_NOT_DEFINED != 'true'
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: env.SECRET_NOT_DEFINED != 'true'
uses: docker/login-action@v3
with:
username: xen0xys
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Docker Image
if: env.SECRET_NOT_DEFINED != 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: xen0xys/phoenix-api:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: SSH into Server and Deploy
if: env.SECRET_NOT_DEFINED != 'true'
uses: appleboy/ssh-action@v1.0.2
with:
host: ${{ secrets.SERVER_ADDRESS }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_PRIVATE_KEY }}
script: |
docker pull xen0xys/phoenix-api:latest
docker stop phoenix-api || true
docker rm phoenix-api || true
docker run -d -p 3000:3000 -e DOTENV_KEY=${{ secrets.DOTENV_KEY }} -v /home/${{ secrets.SERVER_USERNAME }}/keys:/home/keys --name phoenix-api --restart on-failure:2 xen0xys/phoenix-api