-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·54 lines (41 loc) · 1.57 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
# Copy this script over to the private server and run it to deploy the app.
# Copy: scp deploy.sh root@<server_ip>:/app
# Run: ssh root@<server_ip> "/app/deploy.sh" [gitlab|github]
# Configuration
# shellcheck disable=SC2034
gitlab_url="[email protected]:calvetalex/fs3-pokedex-back.git"
github_url="https://github.com/Haltarys/Pokedex-Server.git"
root_directory="/app"
app_directory="pokedex-server"
branch_name=main
image_name=$app_directory
container_name=$app_directory
echo "Deploying..."
# Ensure we start in the right directory
cd $root_directory
# Determine repository URL
repository_url="${1:-gitlab}_url"
repository_url="${!repository_url}"
[ -z "$repository_url" ] && echo "Repository URL not found." && exit 1
# Remove and clone repository
rm -rf $app_directory
git clone $repository_url $app_directory --depth 1 --branch $branch_name
commit_hash=$(git --git-dir="$app_directory/.git" rev-parse --short HEAD)
# Build Docker image
cp production.env "$app_directory/.env"
rm -rf $app_directory/ssl
cp -Lr ssl $app_directory
echo "Building image..."
docker build -t $image_name $app_directory
# Stop previous container
echo "Stopping previous container..."
docker stop $container_name
docker rm $container_name && echo "Container stopped and deleted." || echo "No container named $container_name."
# Run image
echo "Starting app server..."
docker run -d --name=$container_name -p 443:443 "$image_name:latest" && echo "Server started."
# Log
echo "Deployed commit $commit_hash."
echo "$(date +"%Y-%m-%d %H:%M:%S"): Deployed commit $commit_hash." >>deploy.log
echo "Done."