-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.docker-compose.template
87 lines (67 loc) · 2 KB
/
Taskfile.docker-compose.template
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
PATH=./bin:./vendor/bin:$PATH
# Import .env file as environment variables
[ -f .env ] && export $(grep -v '^#' .env | xargs -d '\n')
# PROJECT_NAME defaults to name of the current directory.
PROJECT_NAME=${PROJECT_NAME:-${PWD##*/}}
# Or you can use COMPOSE_PROJECT_NAME variable and delete all specifications
# of `-p` parameter from docker-compose command.
#COMPOSE_PROJECT_NAME=$PROJECT_NAME
# Note. If you change this, you also need to update docker-compose.yml.
# only useful in a setting with multiple services.
SERVICE_TARGET=${SERVICE_TARGET:-php}
function default {
it
}
function it {
echo "I'm runnint!"
}
function up {
echo "Starting up containers for ${PROJECT_NAME}..."
docker-compose -p ${PROJECT_NAME} pull
docker-compose -p ${PROJECT_NAME} up -d --remove-orphans
}
function down {
stop
}
function start {
echo "Starting containers for ${PROJECT_NAME} from where you left off..."
docker-compose -p ${PROJECT_NAME} start
}
function stop {
echo "Stopping containers for ${PROJECT_NAME}..."
docker-compose -p ${PROJECT_NAME} stop
}
function restart {
stop && start
}
function prune {
echo "Removing containers for ${PROJECT_NAME}..."
docker-compose -p ${PROJECT_NAME} down --remove-orphans --volumes
}
function ps {
docker-compose -p ${PROJECT_NAME} ps
}
function logs {
docker-compose -p ${PROJECT_NAME} logs --follow ${@}
}
function shell {
CMD=${@}
if [ -z "${CMD}" ]; then
# no command is given, default to shell
docker-compose -p ${PROJECT_NAME} exec ${SERVICE_TARGET} bash
else
# run the command
docker-compose -p ${PROJECT_NAME} exec ${SERVICE_TARGET} bash -c "${CMD}"
fi
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
compgen -A function | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time ${@:-default}
# Unset all environment variables from .env file loaded at beginning
[ -f .env ] && unset $(grep -v '^#' .env | sed -E 's/(.*)=.*/\1/' | xargs)
unset PATH