-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (70 loc) · 2.97 KB
/
server-dpl.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
name: Server Deployment
on:
push:
branches:
- main
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Create .env file
run: |
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" > ./server/.env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> ./server/.env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> ./server/.env
echo "DATABASE_MIGRATION_URL=${{ secrets.DATABASE_MIGRATION_URL }}" >> ./server/.env
echo "PORT=${{ secrets.PORT }}" >> ./server/.env
echo "ENVIRONMENT=${{ secrets.ENVIRONMENT }}" >> ./server/.env
echo "REDIS_URL=${{ secrets.REDIS_URL }}" >> ./server/.env
echo "WHITELIST_DOMAIN=${{ secrets.WHITELIST_DOMAIN }}" >> ./server/.env
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
DATABASE_MIGRATION_URL: ${{ secrets.DATABASE_MIGRATION_URL }}
PORT: ${{ secrets.PORT }}
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
REDIS_URL: ${{ secrets.REDIS_URL }}
WHITELIST_DOMAIN: ${{ secrets.WHITELIST_DOMAIN }}
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: ./server/Dockerfile # Specify the path to your Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
slackingdjaeger/jagadis-server:latest
slackingdjaeger/jagadis-server:${{ github.sha }}
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh/authorized_keys
ssh-keyscan -t rsa ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Deploy server
run: |
ssh ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "mkdir -p jagadis"
scp ./server/.env ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:jagadis/.env
scp ./server/docker-compose.yml ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:jagadis/docker-compose.yml
ssh ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "cd jagadis && sudo docker compose up -d"
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
cache: 'go'
- name: Migrate Database
run: cd server/src/db && go run migrate.go