-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
40 lines (32 loc) · 1.02 KB
/
deploy.sh
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
#!/bin/bash
# Translated from deploy.ps1
# Pack target/*.jar and Dockerfile into tar.gz
echo "Packing target/*.jar and Dockerfile into tar.gz"
randomString=$(tr -dc A-Za-z </dev/urandom | head -c 10)
archiveName="$randomString.tar.gz"
tar -czf "$archiveName" target/*.jar Dockerfile
# Read first and second line from .env file and raise error if not found
if [ ! -f .env ]; then
echo "Error: .env file not found"
exit 1
fi
hostConnection=$(sed -n '1p' .env)
deployPath=$(sed -n '2p' .env)
if [ -z "$hostConnection" ] || [ -z "$deployPath" ]; then
echo "Error: .env file is missing hostConnection or deployPath"
exit 1
fi
# Copy archive to remote host
echo "Copying archive to remote host"
scp -P 22 "$archiveName" "$hostConnection":/tmp/"$archiveName"
# Execute remote commands:
echo "Executing deploy commands"
ssh -p 22 "$hostConnection" << EOF
tar -xzf /tmp/$archiveName -C $deployPath --overwrite
rm /tmp/$archiveName
cd $deployPath
./deploy.sh
EOF
# Delete archive
echo "Finishing up"
rm "$archiveName"