-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_dev_env.sh
executable file
·97 lines (72 loc) · 2.48 KB
/
run_dev_env.sh
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
#!/bin/bash
# (c) 2020 SotolitoLabs
# Iván Chavero <[email protected]>
#
# This program runs a podman/kubernetes manifest from a directory
# the it will concatenate the first argument to the MANIFEST_PREFIX
# variable tha will complete the manifest name
# The second argument will set the django superuser password
MANIFEST_PREFIX="django-env"
PODS="infra/pods"
HOST="localhost"
WAIT_TIME=10
SUPERUSER_NAME="sotolito_admin"
SUPERUSER_EMAIL="[email protected]"
SUPERUSER_PW="prueba123"
DEBUG=false
PG_CONTAINER="django-postgres"
DJANGO_CONTAINER="django-rest"
pod=$(podman pod ps --format '{{.Name}}' --filter "name=django-env")
if [[ "${1}" == "--help" ]]; then
echo "Usage: $0 <manifest hostname> <django superuser password>"
exit
fi
if [[ "${pod}" == "django-env" ]]; then
echo "Development environment already running, use ./stop_dev_env.sh to stop it or cleanup"
exit
fi
if [[ "${1}" != "" ]]; then
HOST=$1
fi
if [[ "${2}" != "" ]]; then
SUPERUSER_PW=$2
fi
function wait_for_postgres {
ready=""
while [[ ${ready} != *"accepting connections"* ]]; do
ready=$(podman exec -ti ${PG_CONTAINER} /usr/bin/pg_isready 2>&1)
if [[ ${DEBUG} == true ]]; then
echo "READY: ${ready}"
fi
echo -n "."
done
echo
echo "PostgreSQL database ready"
}
echo "Starting development environment for ${HOST}"
podman play kube ${PODS}/${MANIFEST_PREFIX}-${HOST}.yaml
PG_CONTAINER=$(podman ps --format '{{.Names}}' --filter "name=postgres")
DJANGO_CONTAINER=$(podman ps --format '{{.Names}}' --filter "name=django-rest")
if [[ $? != 0 ]]; then
echo "Error creating pod $!"
exit
fi
echo "Checking pods:"
podman pod ps
echo "Checking containers"
podman ps -a --format '{{ .ID }} {{ .Names }} {{ .Ports }} {{ .Pod }}'
echo "Waiting for the database to come up"
# Get the container name because in some systems the pod name gets concatenated
# to the container name
PG_CONTAINER=$(podman ps --filter 'name=postgres' --format '{{.Names}}')
wait_for_postgres
echo "DJANGO: $DJANGO_CONTAINER"
echo "Running migrations in ${DJANGO_CONTAINER}"
podman exec -ti ${DJANGO_CONTAINER} /code/sm/manage.py migrate
echo "Creating superuser"
res=$(podman exec -e "DJANGO_SUPERUSER_PASSWORD=${SUPERUSER_PW}" -ti ${DJANGO_CONTAINER} /code/sm/manage.py createsuperuser --no-input --username=${SUPERUSER_NAME} --email=${SUPERUSER_EMAIL} 2>&1)
if [[ ${res} == *"successfully"* ]]; then
echo $res
else
echo "Superuser ${SUPERUSER_NAME} already created"
fi