-
Notifications
You must be signed in to change notification settings - Fork 2
72 lines (65 loc) · 2.68 KB
/
deploy-prod.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
name: deploy-prod
on:
release:
types: [published]
workflow_dispatch:
concurrency:
group: "deploy"
cancel-in-progress: false
jobs:
deploy:
environment: prod-aws-folclore
runs-on: ubuntu-latest
steps:
- name: 'Check out repository'
uses: actions/checkout@v4
- name: Log in to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
build-args: |
APP_VERSION=${{github.ref_name}}
push: ${{ github.event_name != 'pull_request' }}
tags: eduardoferro/capivara:${{ github.sha }},${{ github.event_name == 'release' && format('eduardoferro/capivara:latest,eduardoferro/capivara:{0}', github.ref_name) || '' }}
- name: 'Wait for SSH'
run: |
SLEEP=1
TRIES=0
MAX_TRIES=10
while ! nc -w5 -z $INSTANCE_IP 22; do
echo "SSH not available..."
if [[ $TRIES -eq $MAX_TRIES ]]; then
echo "Max tries reached, exiting"
exit 1
fi
((TRIES += 1))
sleep $SLEEP
done; echo "SSH ready!"
env:
INSTANCE_IP: ${{ secrets.INSTANCE_IP }}
- name: 'Push start-container.sh'
uses: appleboy/[email protected]
with:
host: ${{ secrets.INSTANCE_IP }}
username: ${{ secrets.SSH_USERNAME }}
passphrase: ${{ secrets.VM_SSH_PRIVATE_KEY_PASSPHRASE }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
source: "./start-container.sh"
target: /home/${{ secrets.SSH_USERNAME }}/capivara/
strip_components: 1
- name: 'Start BOT'
uses: appleboy/[email protected]
with:
host: ${{ secrets.INSTANCE_IP }}
username: ${{ secrets.SSH_USERNAME }}
passphrase: ${{ secrets.VM_SSH_PRIVATE_KEY_PASSPHRASE }}
key: ${{ secrets.VM_SSH_PRIVATE_KEY }}
script: |
cd /home/${{ secrets.SSH_USERNAME }}/capivara
DISCORD_TOKEN='${{ secrets.DISCORD_BOT_TOKEN }}' LOG_CHANNEL_ID='${{ secrets.DISCORD_LOG_CHANNEL_ID }}' CURUPIRA_RESET='true' DATABASE_DRIVER='org.postgresql.Driver' DATABASE_DIALECT='org.hibernate.dialect.PostgreSQL95Dialect' DATABASE_URL='jdbc:postgresql://capivara_database:5432/capivara' DATABASE_USERNAME='${{ secrets.DATABASE_USERNAME }}' DATABASE_PASSWORD='${{ secrets.DATABASE_PASSWORD }}' JAVA_ARGS='-Xmx350M' /bin/bash start-container.sh docker.io/eduardoferro/capivara:${{ github.sha }}