This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
413 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,103 @@ | ||
dc=docker-compose | ||
d=docker | ||
dcp=docker-compose -f docker-compose-production.yml | ||
dcb=$(dc) -f docker-compose-build.yml | ||
dcp=$(dc) -f docker-compose-production.yml | ||
|
||
.PHONY: migrate create-env build-static watch-static \ | ||
build test backup restore \ | ||
generate-production-static-data deploy | ||
|
||
|
||
# ---------------------- Dev section ---------------------- | ||
migrate: | ||
$(dc) exec stb-python python manage.py migrate | ||
$(dc) exec app python manage.py migrate | ||
|
||
fixtures: | ||
$(dc) run --rm app bash -c "\ | ||
python manage.py loaddata stroyprombeton/fixtures/admin.json \ | ||
&& python manage.py loaddata stroyprombeton/fixtures/dump.json \ | ||
" | ||
|
||
prices: | ||
$(dc) exec app python manage.py price | ||
|
||
# for local env | ||
static: | ||
@docker-compose run --rm stb-nodejs bash -c "\ | ||
npm install && \ | ||
npm install -g gulp-cli && \ | ||
gulp build" | ||
create-env: | ||
@bash ./create-env.sh | ||
|
||
create-config: | ||
@bash ./create-config.sh | ||
|
||
build-static: | ||
$(dc) run --rm nodejs gulp build | ||
|
||
watch-static: | ||
$(dc) run --rm nodejs gulp watch | ||
|
||
# for local env | ||
build: static | ||
$(dc) build stb-python | ||
$(dc) build app | ||
|
||
collectstatic: | ||
$(dc) exec app python manage.py collectstatic --noinput | ||
|
||
# for local env | ||
test: static | ||
$(dc) up -d stb-selenium | ||
$(dc) exec stb-python python manage.py test --liveserver=stb-python:8001-8010 --parallel=8 | ||
test: build-static | ||
$(dc) up -d selenium | ||
$(dc) exec app python manage.py test --liveserver=app:8001-8009 --parallel | ||
$(dc) stop | ||
|
||
# for local env | ||
lint: | ||
$(dc) up -d stb-python | ||
$(d) run --rm --volumes-from stb-python --workdir=/usr/app/src -it coala/base coala | ||
$(dc) up -d app | ||
$(d) run --rm --volumes-from app --workdir=/usr/app/src -it coala/base coala | ||
$(dc) stop | ||
|
||
# for local env | ||
restore: | ||
@bash ../etc/stb-backup-restore.sh | ||
|
||
# for serv env | ||
# ---------------------- Deploy section ---------------------- | ||
deploy-dev: | ||
$(MAKE) create-env | ||
$(MAKE) create-config | ||
$(dc) pull | ||
$(dc) up -d app | ||
$(MAKE) build-static | ||
# Create admin user with login/pass: admin/asdfjkl; | ||
# Launch "collectstatic" not in static recipe because ManifestStaticStorage writes to db | ||
$(dc) exec app bash -c "\ | ||
python manage.py migrate \ | ||
&& python manage.py loaddata shopelectro/fixtures/admin.json \ | ||
&& python manage.py loaddata shopelectro/fixtures/dump.json \ | ||
&& python manage.py collectstatic --noinput \ | ||
" | ||
# to make fresh collected static visible immediately | ||
$(dc) stop app && $(dc) up -d app | ||
|
||
# @todo #142:60m Resurrect backup system. | ||
# Right now it's too dangerous and not used. | ||
backup: | ||
$(dcp) up stb-backup-data | ||
|
||
# start dev environment | ||
dev: build | ||
$(dc) up -d stb-python | ||
$(dc) exec stb-python python manage.py migrate | ||
# launch "collectstatic" not in static recipe because ManifestStaticStorage writes to db | ||
$(dc) exec stb-python python manage.py collectstatic --noinput | ||
$(dc) stop && $(dc) up -d # to make fresh collected static visible immediately | ||
|
||
# for serv env | ||
build-production: build | ||
$(dcp) build | ||
$(dcp) push | ||
|
||
deploy: backup | ||
$(dcp) run --rm backup-data sh /usr/bin/entrypoint.sh | ||
|
||
restore: | ||
@bash ../etc/backup/backup-restore.sh | ||
|
||
generate-production-static-data: | ||
$(dcp) exec app python manage.py price | ||
|
||
# drone should do this in working flow. | ||
# But if drone don't do this for some reasons, | ||
# you can run this recipe from local machine. | ||
prepare-deploy: | ||
rm -rf front/build | ||
$(dc) stop app && $(dcp) stop app | ||
$(dc) rm -f app && $(dcp) rm -f app | ||
$(MAKE) build-static | ||
$(dcb) build --no-cache python-dev python-prod | ||
$(dcb) push python-dev python-prod | ||
|
||
deploy: | ||
$(dcp) pull | ||
$(dcp) stop | ||
$(dcp) rm -f stb-source | ||
$(dcp) up -d | ||
$(dcp) exec stb-python python manage.py migrate | ||
# launch "collectstatic" not in build env, but on deploy. | ||
# Because ManifestStaticStorage writes to db | ||
$(dcp) exec stb-python python manage.py collectstatic --noinput | ||
$(dcp) stop && $(dcp) up -d # to make fresh collected static visible immediately | ||
# to flush nginx's inner static caches | ||
$(dcp) rm -f app nginx && $(dcp) up -d app nginx | ||
$(dcp) exec app python manage.py migrate | ||
$(MAKE) -j generate-production-static-data | ||
# Launch "collectstatic" not in static recipe because ManifestStaticStorage writes to db | ||
$(dcp) exec app python manage.py collectstatic --noinput | ||
# to make fresh collected static visible immediately | ||
$(dcp) stop && $(dcp) up -d |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copy the .dist environment files and wait them modifications. | ||
# Merge them to .env file for docker-compose. | ||
|
||
# Usage: | ||
# `./create-env.sh` | ||
# `./create-env.sh -q # Quite mode` | ||
# `./create-env.sh --quite # Quite mode` | ||
|
||
set -e | ||
|
||
QUITE=false | ||
for arg in "$@" | ||
do | ||
if [[ $arg = "--quite" || $arg = "-q" ]] | ||
then | ||
QUITE=true | ||
fi | ||
done | ||
|
||
|
||
function join_by { local IFS="$1"; shift; echo "$*"; } | ||
|
||
function create_env_files { | ||
new_files=() | ||
for file in env_files/*.dist | ||
do | ||
new_file=${file%.dist} | ||
new_files+=( "$new_file" ) | ||
|
||
if [[ ! -f "$new_file" ]] | ||
then | ||
cp $file $new_file | ||
fi | ||
done | ||
|
||
if ! $QUITE | ||
then | ||
file_names=$(join_by , ${new_files[@]}) | ||
read -p \ | ||
"Go to this files and fill them with your own values. | ||
Files list: $file_names. | ||
Hope you finished to configure files from list below. | ||
Now going to merge new config values to .env file. Let's do it? [y/n]: " yn | ||
if [[ $yn != "y" ]] | ||
then | ||
# Give user possibility to refuse on .env generation, | ||
# but exit with zero code. | ||
# It's useful for `make deploy-dev`, for example. | ||
echo "Skip .env file creation" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
local env_doc=\ | ||
$'# Both .env and env_files/ are needed because of docker-compose realization. | ||
# See good explanation here: | ||
# https://github.com/docker/compose/issues/4223#issuecomment-280077263\n' | ||
echo "$env_doc" > .env | ||
|
||
for file in ${new_files[@]} | ||
do | ||
cat $file >> .env | ||
done | ||
} | ||
|
||
if [[ -f ".env" ]] | ||
then | ||
if ! $QUITE | ||
then | ||
read -p "Env file already exists. Remove it? [y/n]: " yn | ||
if [[ $yn = "y" ]] | ||
then | ||
rm .env | ||
fi | ||
else | ||
rm .env | ||
fi | ||
fi | ||
|
||
create_env_files | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: '2' | ||
|
||
services: | ||
|
||
python-dev: | ||
image: fidals/stb:dev | ||
build: | ||
context: ../ | ||
dockerfile: docker/images/python/Dockerfile.dev | ||
|
||
python-prod: | ||
image: fidals/stb:prod | ||
build: | ||
context: ../ | ||
dockerfile: docker/images/python/Dockerfile.prod | ||
|
||
nodejs: | ||
image: fidals/stb-nodejs:dev | ||
build: | ||
context: ../ | ||
dockerfile: docker/images/node/Dockerfile | ||
|
||
nginx: | ||
image: fidals/stb-nginx:prod | ||
build: | ||
context: ../ | ||
dockerfile: docker/images/nginx/Dockerfile |
Oops, something went wrong.