-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (48 loc) · 1.65 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
name: Publish and Deploy
on:
push:
branches:
- main
env:
SSH_USER: lhendrix
SSH_HOST: 51.68.188.78
REGISTRY: ghcr.io
IMAGE_NAME: battmoteam/battmogui: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: Install SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.ACTIONS_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ env.SSH_HOST }} >> ~/.ssh/known_hosts
- name: Test SSH Connection
run: ssh -o StrictHostKeyChecking=no ${{ 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: Stop Running Containers
# run: ssh ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "cd ${{ env.WORKDIR }} && docker compose -f docker-compose-server.yml down"
- name: Pull and Run Containers
run: |
ssh ${{ env.SSH_USER }}@${{ env.SSH_HOST }} "cd ${{ env.WORKDIR }} && \
docker compose -f docker-compose-server.yml pull && \
docker compose -f docker-compose-server.yml up -d"
- name: Cleanup
run: rm -rf ~/.ssh