-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (52 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
57
58
59
60
61
62
63
64
65
66
name: Build and Deploy Docker Image on Server
on:
push
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_USER: ${{ secrets.SERVER_USER }}
SERVER_HOST: ${{ secrets.SERVER_HOST }}
KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }}
DIRECTORY: "${{ vars.DIRECTORY }}/${{ github.event.repository.name }}"
jobs:
build-and-deploy:
environment: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "latest"
- name: Create .env file
run: |
echo "${{ secrets.ENVS }}" > .env
- name: Set up SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ env.SSH_PRIVATE_KEY }}
- name: Add server to known hosts
run: |
mkdir -p ~/.ssh
echo "$KNOWN_HOSTS" > ~/.ssh/known_hosts
- name: Deploy on Server
run: |
ssh -t $SERVER_USER@$SERVER_HOST << EOF
# Prepare the directory
if [ -d "$DIRECTORY" ]; then
rm -rf $DIRECTORY
fi
mkdir -p $DIRECTORY
cd $DIRECTORY
echo ${{ env.SSH_PRIVATE_KEY }} >> id_rsa
# Clone the repository with submodules
git clone -b cicd https://github.com/${{ github.repository }} .
git submodule init
git submodule update
# Create .env file
echo "${{ secrets.ENVS }}" > .env
# Run deploy script
sh deploy.sh
EOF