-
Notifications
You must be signed in to change notification settings - Fork 104
43 lines (37 loc) · 1.26 KB
/
cd.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
name: CD Pipeline
on:
workflow_run:
workflows: ["CI Workflow"]
types:
- completed
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unnecessary
if_key_exists: replace
- name: Add known hosts
run: |
ssh-keyscan -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts
- name: Prepare environment file
run: |
# Creating .env file using secrets
echo "SERVER_PORT=${{ secrets.SERVER_PORT }}" >> .env
echo "SERVER_HOST=${{ secrets.SERVER_HOST }}" >> .env
echo "SERVER_USER=${{ secrets.SERVER_USER }}" >> .env
echo "PROJECT_PATH=${{ secrets.PROJECT_PATH }}" >> .env
- name: Deploy to server
run: |
ssh -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} "
mkdir -p ${{ secrets.PROJECT_PATH }}
cd ${{ secrets.PROJECT_PATH }}
docker-compose pull && docker-compose up --detach --remove-orphans
"