-
Notifications
You must be signed in to change notification settings - Fork 8
47 lines (37 loc) · 1.68 KB
/
dev-pipeline.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
name: Deploy Docker Compose
on:
push:
branches:
- dev
paths:
- 'README.md'
jobs:
deploy-dev:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev' # Only run for the 'feature' branch
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.TIM_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.MAIN_SERVER_IP }} >> ~/.ssh/known_hosts
- name: Create directory on remote server
run: |
ssh -i $HOME/.ssh/id_rsa ubuntu@${{ secrets.MAIN_SERVER_IP }} 'mkdir -p /opt/etapp2/dev/tim'
- name: Check if directory exists on remote server
id: check-directory
run: |
ssh -i $HOME/.ssh/id_rsa ubuntu@${{ secrets.MAIN_SERVER_IP }} 'if [ -d "/opt/etapp2/dev/tim" ]; then echo "Directory exists"; else echo "Directory does not exist"; fi'
- name: Create directory on remote server
run: |
if [[ "${{ steps.check-directory.outputs.check-directory }}" == *"Directory does not exist"* ]]; then
ssh -i $HOME/.ssh/id_rsa ubuntu@${{ secrets.MAIN_SERVER_IP }} 'mkdir -p /opt/etapp2/dev/tim'
fi
- name: Push repository to MAIN server
run: rsync -az --exclude='.git/' -e "ssh -i $HOME/.ssh/id_rsa" $GITHUB_WORKSPACE/ ubuntu@${{ secrets.MAIN_SERVER_IP }}:/opt/etapp2/dev/tim
- name: Run Docker Compose on MAIN server
run: |
ssh -i $HOME/.ssh/id_rsa ubuntu@${{ secrets.MAIN_SERVER_IP }} 'cd /opt/etapp2/dev/tim && docker-compose down && docker-compose up -d --build'