-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.bash
executable file
·53 lines (40 loc) · 1.85 KB
/
deploy.bash
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
#!/bin/bash
set -e
##########################################################################################
# #
# Checks out a git revision and make sure the repository is cloned on the remote server. #
# After that it builds and starts the service via docker-compose. #
# #
##########################################################################################
### Needs those variables in the environment ###
# ENVIRONMENT_NAME - Name of the environment to deploy
# REPO_NAME - Repository name to deploy
# REPO_URL - Repository url to deploy
# REVISON - Git revison to deploy
# ENVIRONMENT - Environment file string to be used with docker-compose files
### Variables end ###
### Configuration ###
# Directory on remote server where services should be located
BASE_DIR=/srv
### Configuration end ###
# Concat paths to get target path of service on remote server
repo_path="$BASE_DIR/$REPO_NAME"
# Check if repository is already cloned
if [ ! -d "$repo_path" ] ; then
# If not we clone the default branch into the target remote path
git clone "$REPO_URL" "$repo_path"
fi
# Go into services directory
cd "$repo_path" || exit 1
# Reset current changes if any
git reset --hard
# fetch new branches and tags
git fetch
# Checkout to target revison
git checkout --detach "$REVISON"
# Write environment string to file
echo "$ENVIRONMENT" > .env.local
# Pull newer images
docker-compose --env-file .env.local -f docker-compose.yml -f "docker-compose.$ENVIRONMENT_NAME.yml" pull
# Start service up again and build if needed
docker-compose --env-file .env.local -f docker-compose.yml -f "docker-compose.$ENVIRONMENT_NAME.yml" up --detach --build