-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile
executable file
·203 lines (169 loc) · 5.97 KB
/
Taskfile
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# =========================================================
# Taskfile gives you a set of quick tasks for your project
# More info: https://github.com/Enrise/Taskfile
# =========================================================
function banner {
echo -e "${BLUE}"\
" ▗▄▖ ▗▄▄▖ ▗▄▄▖ ▗▄▄▄ ▗▄▖ ▗▄▄▖▗▖ ▗▖▗▄▄▖ ▗▄▖ ▗▄▖ ▗▄▄▖ ▗▄▄▄ \n"\
"▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌ ▐▌ █▐▌ ▐▌▐▌ ▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ ▐▌▐▌ █\n"\
"▐▛▀▜▌▐▛▀▘ ▐▛▀▘ ▐▌ █▐▛▀▜▌ ▝▀▚▖▐▛▀▜▌▐▛▀▚▖▐▌ ▐▌▐▛▀▜▌▐▛▀▚▖▐▌ █\n"\
"▐▌ ▐▌▐▌ ▐▌ ▐▙▄▄▀▐▌ ▐▌▗▄▄▞▘▐▌ ▐▌▐▙▄▞▘▝▚▄▞▘▐▌ ▐▌▐▌ ▐▌▐▙▄▄▀${RESET}"
}
# =========================================================
## Project
# =========================================================
function task:init { ## Initialise the project for local development
project:git-config
task:build
task:start
project:update
# Finalize setting up the project
task:help
}
function task:start { ## Start the project in development mode
docker:start
}
function task:update { ## Update all dependencies and files
project:update
}
function project:update {
title "Run project updates"
# TODO: Add project update commands here
}
function task:stop { ## Stop the local project
docker:stop
}
function task:restart { ## Restart the local project
docker:stop
docker:start
}
function project:git-config {
title "Setting git configuration"
git config --local core.hooksPath dev/git-hooks
echo -e "Git hooks directory is set to ${YELLOW}./dev/git-hooks${RESET}."
}
function task:pr { ## Check out pull request <number> and update
project:checkout-pr $1
project:update
}
function project:checkout-pr {
title "Checking out pull request"
if [ -z "$1" ]; then
echo "You need to provide a pull request number to check out."
echo -e "${BLUE}Usage:${RESET} $0 pr ${YELLOW}<number>${RESET}"
exit 1
fi
echo "Checking out pull request $1..."
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1
git checkout origin/pr/$1
}
# =========================================================
## Docker
# =========================================================
function task:build { ## Build all docker compose containers
title "Building docker compose project"
dockercompose build
}
function docker:start {
title "Starting docker compose project"
dockercompose up --detach
}
function docker:stop {
title "Stopping docker compose project"
dockercompose down
}
function task:logs { ## Show the docker compose logs
title "Following local logs"
dockercompose logs --tail="20" --follow
}
function task:dc { ## Run docker compose command <command>
title "Docker compose $@"
dockercompose "$@"
}
function docker:assert-running {
if [ -z "$(dockercompose ps -q)" ]; then
echo -e "${RED}Oh noes, docker was not running yet, starting...${RESET}"
task:start
title "Resuming task"
fi
}
function dockercompose {
USERID=$USERID GROUPID=$GROUPID docker compose --file ./docker-compose.yml --project-name app-dashboard "$@"
}
# =========================================================
## Production
# =========================================================
function task:build-latest { ## Build the enrise/dashboard:latest container
title "Building the latest production container"
docker build --tag enrise/dashboard:latest .
}
function task:run-latest { ## Run the enrise/dashboard:latest container on port 3030
title "Running the latest production container"
echo "Running production container at ${GREEN}http://localhost:3030${RESET}.";
title "Container logs"
docker run --rm -ti \
--publish 3030:8000 \
--env DASHBOARD_NAME="Production build" \
--env DASHBOARD_LINK_DEVELOPMENT_SETUP="http://localhost:8000" \
enrise/dashboard:latest
}
function task:publish { ## Run the enrise/dashboard:latest container on port 3030
title "Publishing to the docker hub"
docker push enrise/dashboard:latest
}
# =========================================================
# Utilities
# =========================================================
function file:ensure { # Abort if the desired file is not found
if [ ! -f $1 ]; then
echo -e "${RED}Missing required file: ${YELLOW}$1${RESET}"
exit 1
fi
}
function file:ensure-copy { # file:ensure-copy $COPY_TARGET $COPY_SOURCE
if [ ! -f $1 ]; then
cp $2 $1;
echo -e "Created copy of ${YELLOW}$2${RESET} to create ${GREEN}$1${RESET}.";
else
echo "${GREEN}$1${RESET} is present.";
fi
}
# =========================================================
## Taskfile
# =========================================================
set -eo pipefail
BLUE=$(printf '\033[36m')
YELLOW=$(printf '\033[33m')
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
RESET=$(printf '\033[0m')
USERID=$(id -u)
GROUPID=$(id -g)
NETWORK="app-dashboard-network"
function title {
echo -e "\n${BLUE}=>${RESET} $1\n"
}
function task:help { ## Show all available tasks
title "Available tasks"
awk 'BEGIN {FS = " { [#][#][ ]?"} /^([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ \
{printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\
sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\
sed -E "s/function task:*/ /g"
echo -e "\n${BLUE}Usage:${RESET} $0 ${YELLOW}<task>${RESET} <args>"
}
function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile
title "Creating task shorthand"
echo -e "You're about to create ${YELLOW}/usr/local/bin/task${RESET} that requires ${RED}root${RESET} permission..."
sudo curl --location --silent --output /usr/local/bin/task https://enri.se/taskfile-bin
sudo chmod +x /usr/local/bin/task
echo -e "${BLUE}You can now use:${RESET} task ${YELLOW}<task>${RESET} <args>"
}
banner
if [[ ! "$(declare -F task:${@-help})" ]]; then
title "Task not found"
echo -e "Task ${RED}$1${RESET} doesn't exist."
task:help
exit 1
fi
task:${@-help}