-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (54 loc) · 2.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Publish and Deploy
on:
push:
branches:
- main
env:
SSH_USER: lhendrix
SSH_HOST: 51.68.188.78
REGISTRY: ghcr.io
IMAGE_NAME: battmoteam/battmoapp:latest
WORKDIR: battmogui
jobs:
publish:
name: publish image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login
run: echo ${{ secrets.PAT }} | docker login ghcr.io -u lorenah84 --password-stdin
- name: Build
run: |
docker compose -f docker-compose-deploy.yml build
- name: Publish
run: docker compose -f docker-compose-deploy.yml push
deploy:
name: Deploy image
runs-on: ubuntu-latest
needs: publish
steps:
- name: Checkout code # <-- This step ensures docker-compose-deploy.yml is available
uses: actions/checkout@v3
- name: Install SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.ACTIONS_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Test SSH Connection
run: ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "echo SSH connection successful"
- name: Login to Registry
run: echo ${{ secrets.PAT }} | docker login ghcr.io -u lorenah84 --password-stdin
- name: Copy docker-compose-deploy file to the server
run: scp -P ${{ secrets.SSH_PORT }} docker-compose-deploy.yml ${{ env.SSH_USER }}@${{ env.SSH_HOST }}:${{ env.WORKDIR }}
- name: Pull and Run Containers with Deploy File
run: |
ssh -p ${{ secrets.SSH_PORT }} ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "cd ${{ env.WORKDIR }} && \
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} \
HASH_SALT=${{ secrets.HASH_SALT }} \
docker compose -f docker-compose-deploy.yml pull && \
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} \
HASH_SALT=${{ secrets.HASH_SALT }} \
docker compose -f docker-compose-deploy.yml up -d"
- name: Cleanup
run: rm -rf ~/.ssh