-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-assist
executable file
·123 lines (119 loc) · 4.07 KB
/
docker-assist
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
#!/bin/bash
# This script pulls together frequent commands for orchestrating
# our docker setup.
set -x
cd "$(dirname $0)"
task=$1 # More descriptive name
arg=$2
args=${*:2}
# Copy the env file if it doesn't exist
if [ ! -f .env ]; then
cp .env.example .env
fi
source .env
case $task in
build)
# Build docker containers. Pass --no-cache to force re-downloading of images.
# See build --help for additional info
docker-compose build $args
;;
start)
# Start docker containers.
# See up --help for additional info
docker-compose up $args
;;
stop)
# Stop docker containers.
docker-compose stop
;;
clean)
# Remove docker containers (if they exist)
# Run this with --rmi all to remove the mysql image too
docker-compose down --rmi local
;;
bash)
# SSH (bash) into server container.
# Useful for running Django shell commands.
docker exec -it uplifty bash
;;
bashdb)
# SSH (bash) into database container.
# Useful for running commands directly against database.
docker exec -it uplifty-db bash
;;
shell)
# SSH (bash) into server container.
# Useful for running Django shell commands.
docker exec -it uplifty python manage.py shell
;;
install-local)
# Install package, e.g. ./docker-assist install --dev django_extensions
docker exec -it uplifty pipenv install $args
;;
install-system)
# Install/reinstall from pipenv
docker exec -it server pipenv install --system --deploy --ignore-pipfile --dev
;;
lint)
# Lint server code automatically with black and autoflake
# WARNING: This updates files in-place.
docker exec uplifty black /code/server
docker exec uplifty autoflake . --in-place --recursive --remove-all-unused-imports --remove-duplicate-keys --remove-unused-variables
if ! git diff-index --quiet HEAD --; then
echo "Changes made. See git diff"
exit 1
fi
;;
security-check)
# Security vulnerability checks
# Check packages
docker exec server pipenv check --system
# Check files, except tests. See also server/.bandit config
docker exec server bandit -r .
;;
dbshell)
# SSH (bash) into database container.
# Useful for running postgres commands.
docker exec -it uplifty-db psql -U postgres
;;
cleandb)
# Drop the local database.
docker exec -it uplifty-db psql -h db -U postgres -c "DROP DATABASE IF EXISTS uplifty"
;;
migrate)
# Run database migrations.
docker exec -it server python manage.py migrate $args
;;
test)
echo "Running tests with cache (use --cache-clear otherwise)..."
docker-compose run \
--rm \
--name uplifty-test \
uplifty \
pytest --pylama $args
;;
'help')
scriptname=`basename "$0"`
echo 'Usage: ./'$scriptname' action [params]. Available actions:'
echo ' build: build or rebuild containers'
echo ' start: start containers'
echo ' stop: stop containers'
echo ' clean: remove containers, including databases'
echo ' bash: bash into the server container'
echo ' shell: start django shell'
echo ' migrate: run django migrations'
echo ' lint: lint server (python) code'
echo ' bashdb: bash into the database container'
echo ' cleandb: drop database'
echo ' dbshell: start database cli'
echo ' security-check: run a security check for server-side vulnerabilities'
;;
'')
scriptname=`basename "$0"`
echo 'Usage: ./'$scriptname' action [params]. For a list of actions, run ./'$scriptname' help'
;;
*)
scriptname=`basename "$0"`
echo 'Unknown action '$task'. For a list of the available actions, run ./'$scriptname' help'
;;
esac