-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun
executable file
·93 lines (82 loc) · 3.58 KB
/
run
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
#!/bin/bash
COLOR="\e["
RED="${COLOR}31m"
GREEN="${COLOR}32m"
PURPLE="${COLOR}35m"
BLUE="${COLOR}34m"
WHITE="${COLOR}m"
YELLOW="${COLOR}36m"
GRAY="${COLOR}37m"
# Run dev servers
dev() {
echo -e "\n${YELLOW}--[ Building developement images… ]--${WHITE}\n"
docker-compose up --remove-orphans --build --force-recreate
}
# Generate NuxtJS static files
gen() {
echo -e "\n${GREEN}--[ Generating nuxt static files… ]--${WHITE}\n"
mkdir -p frontend/.output/public
chmod 777 frontend/.output/public
docker-compose -f docker-compose.nuxt.yml up --remove-orphans --build --force-recreate
}
# Run production servers
prod() {
gen
echo -e "\n${GREEN}--[ Looking for .env file… ]--${WHITE}\n"
env_dir="backend/backend"
env_file=".env"
env_sample="sample.env"
test -f ${env_dir}/${env_file} || cp ${env_dir}/${env_sample} ${env_dir}/${env_file} && echo "Using .env file created from sample.env!\n"
echo -e "\n${GREEN}--[ Building production images… ]--${WHITE}\n"
docker-compose -f docker-compose.prod.yml up --remove-orphans --build --force-recreate
}
wag() {
echo -e "\n${GREEN}--[ Logging in to Wagtail docker image… ]--${WHITE}\n"
echo -e "To create superuser:\n${YELLOW}./manage.py createsuperuser${WHITE}"
echo -e "To generate new SECRET_KEY:\n${YELLOW}./manage.py shell -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'${WHITE}\n"
docker exec -it `docker ps|grep backend|awk '{print $1}'` bash || echo -e "${PURPLE}Is container running?${WHITE}"
}
save() {
mkdir -p ./export
echo -e "\n${GREEN}--[ Saving docker image… ]--${WHITE}\n"
docker save -o ./export/wagtail_gunicorn.tar wagtail_nuxt_web || echo -e "${PURPLE}Something went wrong!${WHITE}"
echo -e "\n${GREEN}--[ Saving static, public files, database, .env and nginx example config… ]--${WHITE}\n"
cp ./nginx/nginx.conf ./export
cp -R ./backend/static ./export
cp ./backend/db.sqlite3 ./export
cp ./backend/backend/.env ./export
cp -R ./frontend/.output/public ./export
echo -e "\n${GREEN}--[ Saving wagtail_nuxt_production.tar.gz…]--${WHITE}\n"
tar czf ./wagtail_nuxt_production.tar.gz export
echo -e "\n${GREEN}--[ Cleaning up…]--${WHITE}\n"
rm -R ./export
echo -e "\n${GREEN}--[ DONE ]--${WHITE}\n"
echo -e "Use ${YELLOW}docker load -i ./wagtail_gunicorn.tar${WHITE} to import docker image."
echo -e "Create vhost config based on ${YELLOW}nginx.conf${WHITE}."
echo -e "Copy ${YELLOW}/static${WHITE} and ${YELLOW}/public${WHITE} to where nginx proxy would get them from."
echo -e "Use ${YELLOW}docker run${WHITE} with exec command ${YELLOW}./docker-entrypoint.prod.sh${WHITE} to start container from image.\n"
echo -e "${PURPLE}Remember you must bind some source files because db.sqlite3 and .env is not in docker image!${WHITE}\n"
echo -e "Example:\n"
echo -e "${YELLOW}docker run -d \\n\
--name wagtail \\n\
--mount type=bind,source=/LOCAL/db.sqlite3,target=/app/db.sqlite3 \\n\
--mount type=bind,source=/LOCAL/.env,target=/app/backend/.env \\n\
--restart=unless-stopped \\n\
-p 7999:7999 \\n\
wagtail_nuxt_web \\n\
./docker-entrypoint.prod.sh${WHITE}"
}
# How to use
usage() {
echo -e "\n${GREEN}Usage: ${WHITE}run ${RED}[${YELLOW}dev${RED}/${GREEN}gen${RED}/${PURPLE}prod${RED}]${WHITE}\n"
echo -e "${YELLOW}dev${GRAY} = serve for developement;\n${GREEN}gen${GRAY} = generate nuxt static files;\n${PURPLE}prod${GRAY} = serve for production (includes ${GREEN}gen${GRAY})${WHITE}"
}
case $1 in
"dev") dev;;
"gen") gen ;;
"prod") prod ;;
"wag") wag ;;
"save") save ;;
*) usage ;;
esac
echo -e "${WHITE}"