-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·52 lines (39 loc) · 1.42 KB
/
deploy.sh
File metadata and controls
executable file
·52 lines (39 loc) · 1.42 KB
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
#!/bin/bash
set -e
COLOR_YELLOW='\033[1;33m'
COLOR_GREEN='\033[1;32m'
NO_COLOR='\033[0m'
if [ -f /opt/project_folder ]; then
PROJECT_FOLDER=$(cat /opt/project_folder)
else
echo -e "${COLOR_YELLOW}Project folder not set, using current directory${NO_COLOR}"
PROJECT_FOLDER=$(pwd)
fi
cd $PROJECT_FOLDER
# Check if $1 is a ref if so pull it
if [ -n "$1" ]; then
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/github || echo -e "${COLOR_YELLOW}SSH Key ~/.ssh/github not found${NO_COLOR}"
git fetch
if git show-ref --verify --quiet "refs/remotes/origin/$1"; then
git checkout -B "$1" "origin/$1"
git pull --ff-only
else
git checkout "$1"
echo -e "${COLOR_YELLOW}Checked out '$1' in detached HEAD state; skipping 'git pull'.${NO_COLOR}"
fi
fi
# Only pull if we're on a branch (not in detached HEAD)
if git symbolic-ref -q HEAD > /dev/null; then
git pull --recurse-submodules
fi
set -a
source .env
set +a
RENDERED_SWARM_COMPOSE_FILE=/tmp/.swarm.docker-compose.rendered.yml
docker stack config -c base/swarm.docker-compose.yml -c swarm.docker-compose.yml > "$RENDERED_SWARM_COMPOSE_FILE"
docker compose -f "$RENDERED_SWARM_COMPOSE_FILE" pull
docker stack deploy -c "$RENDERED_SWARM_COMPOSE_FILE" "$STACK_NAME" --with-registry-auth -d
echo -e "${COLOR_GREEN}Deployment successful.${NO_COLOR}"
echo "Run 'docker service ls' to check the services"
echo "Run shell <service_name> [optional] <command> to attach to a service"