-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.Taskfile
More file actions
executable file
·144 lines (119 loc) · 3.47 KB
/
.Taskfile
File metadata and controls
executable file
·144 lines (119 loc) · 3.47 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
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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
###################
# Building blocks #
###################
# One compose file full of the system dependencies
COMPOSE_FILE=$DIR/docker-compose.yml;
# Another compose file for scriptable one-off things
DEVTOOLS_COMPOSE=$DIR/docker-compose-devtools.yml
function dc() {
# Alias to docker compose that always chooses the right
# compose file
docker-compose -f $COMPOSE_FILE $@
}
function dc_dev() {
# Run devtools stuff
docker-compose -f $DEVTOOLS_COMPOSE $@
}
function dc_all() {
docker-compose -f $COMPOSE_FILE -f $DEVTOOLS_COMPOSE $@
}
function dc_do() {
# Runs the given command in docker-compose in an existing
# container if there is one, or spins up a new one if there
# isn't.
#
# Among other things, this lets us keep the DB up and
# running all the time, but bring up the API, front-end
# compiler, or the web container only temporarily to run
# a specific command
local CONTAINER_ID=$(docker-compose ps -q $1)
if [[ "$CONTAINER_ID" != "" ]]; then
echo "$1 has been created"
if [ -z `docker ps -q --no-trunc | grep $(docker-compose ps -q $1)` ]; then
echo "it's not running."
local do="run --rm"
else
echo "it's already running."
local do=exec
fi
else
echo "$1 has not been created"
local do=run
fi
dc $do $@
}
################
# Docker Tasks #
################
# Some commands we want to pass straight through to docker-compose
# We usually want to build, start, and stop specific containers
function build() { dc_all build $@; }
function start() { dc_all start $@; }
function stop() { dc_all stop $@; }
function restart() { dc_all restart $@; }
function logs() { dc_all logs $@; }
# Pass up/down to just the site-specific containers
function up() { dc up $@; }
function down() { dc down $@; }
function ps() { dc ps $@; }
function bash() {
# Grab a bash shell on the named container (api by default)
local container_name=${1:-api};
# Pass the rest of the args to bash directly
if [ "$#" != "0" ]; then
shift;
fi
dc_do $container_name bash $@;
}
################
# Python Tasks #
################
function pip_freeze() {
# Update pip requirements
local requirements_file=$(DIR/api/frozen_requirements.txt)
echo "Freezing pip requirements to $requirements_file";
dc_do api pip freeze > $requirements_file;
echo "Done"
}
function manage () {
# Run the django management command in the API container
dc_dev run manage $@;
}
function black() {
# Python code formatter.
# You can wear any color you like as long as it's black.
dc_dev run black-formatter $@
}
####################
# Typescript Tasks #
####################
function npm() {
dc run ts npm $@
}
function compile() {
dc_dev run ts-compile $@
}
##################
# Database Tasks #
##################
function dbshell() {
# Get a database shell in the existing docker container
dc_do db psql --user postgres;
}
function dbinit() {
# Get a database shell in the existing docker container
manage migrate
manage load_excel data.xlsx
}
########
# MAIN #
########
# This "$@" construct means we will run this file as if it were a
# standalone script. The first argument will be the command to run
# (which should be a function from within the file) and the rest
# of the args are passed to that command.
"$@"