-
Notifications
You must be signed in to change notification settings - Fork 5
106 lines (88 loc) · 2.72 KB
/
build_and_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: Build and Deploy
on:
push:
branches: [main]
paths:
# Workflow is triggered only if src changes
- src/**
# Allow manual trigger
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
build:
name: Build Docker image
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Clone repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: naxa
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Build and push backend image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: naxa/dronetm:backend
file: ./src/backend/Dockerfile
- name: Write Environment Variables for Frontend
run: |
echo ${{ vars.FRONTEND_ENV_VARS }} > .env
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: .
push: true
target: live
tags: naxa/dronetm:frontend
file: ./src/frontend/Dockerfile
deploy_to_vm:
name: Deploy to VM
needs:
- build
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: naxa
password: ${{ secrets.DOCKERHUB_PAT }}
- name: Setup SSH Key
uses: webfactory/[email protected]
with:
ssh-private-key: "${{ secrets.SSH_PRIVATE_KEY }}"
- name: Add host keys to known_hosts
run: |
ssh-keyscan "${{ secrets.SSH_HOST }}" >> ~/.ssh/known_hosts
- name: create env file
run: |
echo '${{ secrets.BACKEND_ENV_VARS }}' > .env
- name: Deploy to VM
run: |
# Create db data volume if not exists
docker volume create drone-tm-db-data || true
# Run db upgrade if necessary
docker compose --file contrib/pg-upgrade/docker-compose.yml \
--env-file .env up || true
# Cleanup db upgrade containers
docker compose --file contrib/pg-upgrade/docker-compose.yml down
docker compose --file docker-compose.vm.yml --env-file .env up \
--detach --remove-orphans --force-recreate --pull=always
env:
DOCKER_HOST: "ssh://${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}"