-
Notifications
You must be signed in to change notification settings - Fork 8
86 lines (72 loc) · 2.46 KB
/
build-and-deploy-preview.yaml
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
name: Build and deploy preview
on:
pull_request:
types:
- opened
- synchronize
env:
tag: preview-${{ github.event.number }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build, tag and push backend
uses: docker/build-push-action@v6
with:
file: ./apps/backend/Dockerfile
tags: ${{ vars.DOCKERHUB_USERNAME }}/dundring-backend:${{ env.tag }}
push: true
- name: Build, tag and push frontend
uses: docker/build-push-action@v6
with:
file: ./apps/frontend/Dockerfile
push: true
tags: ${{ vars.DOCKERHUB_USERNAME }}/dundring-frontend:${{ env.tag }}
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: preview
url: https://${{ env.tag }}.dundring.com
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Add docker compose file to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
source: docker/preview/docker-compose.yaml
target: previews/${{ env.tag }}
strip_components: 2
- name: Start the containers with Docker Compose
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
cd previews/${{ env.tag }}
TAG=${{ env.tag }} \
docker compose pull
TAG=${{ env.tag }} \
DB_USERNAME=dundring \
DB_PASSWORD=password \
CLOUDFLARE_DNS_API_TOKEN=${{ secrets.CLOUDFLARE_API_TOKEN }} \
MAIL_HOST=${{ secrets.MAIL_HOST }} \
MAIL_PORT=${{ secrets.MAIL_PORT }} \
MAIL_USER=${{ secrets.MAIL_USER }} \
MAIL_PASSWORD='${{ secrets.MAIL_PASSWORD }}' \
STRAVA_CLIENT_ID='${{ secrets.STRAVA_CLIENT_ID }}' \
STRAVA_CLIENT_SECRET='${{ secrets.STRAVA_CLIENT_SECRET }}' \
docker compose up -d