2021-01-24 19:26:34 +01:00
|
|
|
SHELL := /bin/bash
|
2020-10-04 17:41:35 +07:00
|
|
|
CURRENT_UID := $(shell id -u)
|
|
|
|
CURRENT_GID := $(shell id -g)
|
2021-09-07 11:36:11 -04:00
|
|
|
newsblur := $(shell docker ps -qf "name=newsblur_web")
|
2020-10-04 17:41:35 +07:00
|
|
|
|
2021-02-24 17:17:06 -05:00
|
|
|
.PHONY: node
|
|
|
|
|
2020-10-09 12:28:10 +07:00
|
|
|
#creates newsblur, but does not rebuild images or create keys
|
|
|
|
start:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose up -d
|
2020-11-03 11:25:31 +07:00
|
|
|
|
2021-05-19 10:28:16 -04:00
|
|
|
metrics:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose -f docker-compose.yml -f docker-compose.metrics.yml up -d
|
2021-05-19 10:28:16 -04:00
|
|
|
|
|
|
|
metrics-ps:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose -f docker-compose.yml -f docker-compose.metrics.yml ps
|
2021-05-19 10:28:16 -04:00
|
|
|
|
2020-11-03 11:25:31 +07:00
|
|
|
rebuild:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose down
|
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose up -d
|
2020-10-09 12:28:10 +07:00
|
|
|
|
2021-11-16 12:41:09 -05:00
|
|
|
collectstatic:
|
2022-01-04 15:54:37 -05:00
|
|
|
- rm -fr static
|
2022-02-24 10:41:20 -05:00
|
|
|
- docker pull newsblur/newsblur_deploy
|
2022-01-04 15:54:37 -05:00
|
|
|
- docker run --rm -v $(shell pwd):/srv/newsblur newsblur/newsblur_deploy
|
2021-11-16 12:41:09 -05:00
|
|
|
|
2020-10-04 17:41:35 +07:00
|
|
|
#creates newsblur, builds new images, and creates/refreshes SSL keys
|
2021-05-17 17:39:27 -04:00
|
|
|
nb: pull
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose down
|
2021-02-21 11:46:41 -05:00
|
|
|
- [[ -d config/certificates ]] && echo "keys exist" || make keys
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose up -d --build --remove-orphans
|
|
|
|
- docker exec newsblur_web ./manage.py migrate
|
|
|
|
- docker exec newsblur_web ./manage.py loaddata config/fixtures/bootstrap.json
|
|
|
|
nbup:
|
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose up -d --build --remove-orphans
|
2021-07-12 21:41:19 -04:00
|
|
|
coffee:
|
|
|
|
- coffee -c -w **/*.coffee
|
2020-10-04 17:41:35 +07:00
|
|
|
|
2020-11-03 11:25:31 +07:00
|
|
|
shell:
|
2021-06-29 08:42:45 -06:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker-compose exec newsblur_web ./manage.py shell_plus
|
2021-04-27 20:49:10 -04:00
|
|
|
bash:
|
2021-06-29 08:42:45 -06:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker-compose exec newsblur_web bash
|
2020-10-04 17:41:35 +07:00
|
|
|
# allows user to exec into newsblur_web and use pdb.
|
2020-10-12 12:28:02 +07:00
|
|
|
debug:
|
2021-09-07 11:36:11 -04:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker attach ${newsblur}
|
2021-04-29 11:44:12 -04:00
|
|
|
log:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20 newsblur_web newsblur_node
|
2021-08-02 16:30:12 -04:00
|
|
|
logweb: log
|
|
|
|
logcelery:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20 task_celery
|
2021-08-02 16:30:12 -04:00
|
|
|
logtask: logcelery
|
2021-06-29 08:33:30 -06:00
|
|
|
logmongo:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose logs -f db_mongo
|
2021-08-02 16:30:12 -04:00
|
|
|
alllogs:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20
|
2021-08-02 16:30:12 -04:00
|
|
|
logall: alllogs
|
2020-10-04 17:41:35 +07:00
|
|
|
# brings down containers
|
2021-04-07 15:32:11 -04:00
|
|
|
down:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True docker compose -f docker-compose.yml -f docker-compose.metrics.yml down
|
2021-05-12 18:54:04 -04:00
|
|
|
nbdown: down
|
2021-06-21 22:40:48 -04:00
|
|
|
jekyll:
|
|
|
|
- cd blog && bundle exec jekyll serve
|
2021-06-28 18:13:20 -04:00
|
|
|
jekyll_drafts:
|
|
|
|
- cd blog && bundle exec jekyll serve --drafts
|
2021-06-21 22:40:48 -04:00
|
|
|
|
2020-10-04 17:41:35 +07:00
|
|
|
# runs tests
|
|
|
|
test:
|
2022-01-26 13:33:59 -05:00
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} TEST=True docker compose -f docker-compose.yml up -d newsblur_web
|
|
|
|
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker compose exec newsblur_web bash -c "NOSE_EXCLUDE_DIRS=./vendor DJANGO_SETTINGS_MODULE=newsblur_web.test_settings python3 manage.py test -v 3 --failfast"
|
2020-10-04 17:41:35 +07:00
|
|
|
|
|
|
|
keys:
|
|
|
|
- mkdir config/certificates
|
|
|
|
- openssl dhparam -out config/certificates/dhparam-2048.pem 2048
|
|
|
|
- openssl req -x509 -nodes -new -sha256 -days 1024 -newkey rsa:2048 -keyout config/certificates/RootCA.key -out config/certificates/RootCA.pem -subj "/C=US/CN=Example-Root-CA"
|
|
|
|
- openssl x509 -outform pem -in config/certificates/RootCA.pem -out config/certificates/RootCA.crt
|
|
|
|
- openssl req -new -nodes -newkey rsa:2048 -keyout config/certificates/localhost.key -out config/certificates/localhost.csr -subj "/C=US/ST=YourState/L=YourCity/O=Example-Certificates/CN=localhost.local"
|
2021-02-17 09:29:16 -05:00
|
|
|
- openssl x509 -req -sha256 -days 1024 -in config/certificates/localhost.csr -CA config/certificates/RootCA.pem -CAkey config/certificates/RootCA.key -CAcreateserial -out config/certificates/localhost.crt
|
2020-10-04 17:41:35 +07:00
|
|
|
- cat config/certificates/localhost.crt config/certificates/localhost.key > config/certificates/localhost.pem
|
2021-05-07 09:59:35 -05:00
|
|
|
- /usr/bin/security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain ./config/certificates/RootCA.crt
|
2021-01-22 19:22:45 -05:00
|
|
|
|
2021-02-24 20:02:37 -05:00
|
|
|
# Digital Ocean / Terraform
|
2021-01-22 19:22:45 -05:00
|
|
|
list:
|
2021-02-08 14:15:03 -05:00
|
|
|
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` compute droplet list
|
2021-08-04 18:42:58 -04:00
|
|
|
sizes:
|
|
|
|
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` compute size list
|
2021-12-13 16:09:27 -05:00
|
|
|
size: sizes
|
2021-08-04 18:42:58 -04:00
|
|
|
ratelimit:
|
|
|
|
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` account ratelimit
|
2021-01-29 09:49:39 -05:00
|
|
|
ansible-deps:
|
|
|
|
ansible-galaxy install -p roles -r ansible/roles/requirements.yml --roles-path ansible/roles
|
2021-05-17 12:09:16 -04:00
|
|
|
tfrefresh:
|
2021-04-26 14:12:57 -04:00
|
|
|
terraform -chdir=terraform refresh
|
2021-02-19 17:58:01 -05:00
|
|
|
plan:
|
2021-04-26 14:12:57 -04:00
|
|
|
terraform -chdir=terraform plan -refresh=false
|
2021-02-19 17:58:01 -05:00
|
|
|
apply:
|
2021-06-30 00:22:09 -04:00
|
|
|
terraform -chdir=terraform apply -refresh=false -parallelism=15
|
2021-05-17 12:09:16 -04:00
|
|
|
inventory:
|
2021-05-17 17:37:51 -04:00
|
|
|
- ./ansible/utils/generate_inventory.py
|
2021-08-03 15:17:25 -04:00
|
|
|
oldinventory:
|
|
|
|
- OLD=1 ./ansible/utils/generate_inventory.py
|
2021-01-29 12:12:27 -05:00
|
|
|
|
2021-02-23 15:53:46 -05:00
|
|
|
# Docker
|
2021-05-17 17:32:54 -04:00
|
|
|
pull:
|
|
|
|
- docker pull newsblur/newsblur_python3
|
|
|
|
- docker pull newsblur/newsblur_node
|
2021-05-17 17:39:27 -04:00
|
|
|
- docker pull newsblur/newsblur_monitor
|
2021-05-17 17:32:54 -04:00
|
|
|
|
2022-01-26 13:33:59 -05:00
|
|
|
local_build_web:
|
|
|
|
# - docker buildx build --load . --file=docker/newsblur_base_image.Dockerfile --tag=newsblur/newsblur_python3
|
|
|
|
- docker build . --file=docker/newsblur_base_image.Dockerfile --tag=newsblur/newsblur_python3
|
2021-02-24 17:17:06 -05:00
|
|
|
build_web:
|
2022-01-18 17:25:07 -05:00
|
|
|
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/newsblur_base_image.Dockerfile --tag=newsblur/newsblur_python3
|
2021-02-24 17:17:06 -05:00
|
|
|
build_node:
|
2022-01-18 17:25:07 -05:00
|
|
|
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/node/Dockerfile --tag=newsblur/newsblur_node
|
2021-03-09 11:10:40 -05:00
|
|
|
build_monitor:
|
2022-01-18 17:25:07 -05:00
|
|
|
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/monitor/Dockerfile --tag=newsblur/newsblur_monitor
|
2021-11-16 12:41:09 -05:00
|
|
|
build_deploy:
|
2022-01-18 17:25:07 -05:00
|
|
|
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/newsblur_deploy.Dockerfile --tag=newsblur/newsblur_deploy
|
2021-11-16 12:41:09 -05:00
|
|
|
build: build_web build_node build_monitor build_deploy
|
2022-01-18 17:25:07 -05:00
|
|
|
push_web:
|
|
|
|
- docker buildx build . --push --platform linux/amd64,linux/arm64 --file=docker/newsblur_base_image.Dockerfile --tag=newsblur/newsblur_python3
|
|
|
|
push_node:
|
|
|
|
- docker buildx build . --push --platform linux/amd64,linux/arm64 --file=docker/node/Dockerfile --tag=newsblur/newsblur_node
|
|
|
|
push_monitor:
|
|
|
|
- docker buildx build . --push --platform linux/amd64,linux/arm64 --file=docker/monitor/Dockerfile --tag=newsblur/newsblur_monitor
|
|
|
|
push_deploy:
|
|
|
|
- docker buildx build . --push --platform linux/amd64,linux/arm64 --file=docker/newsblur_deploy.Dockerfile --tag=newsblur/newsblur_deploy
|
2021-11-16 12:41:09 -05:00
|
|
|
push_images: push_web push_node push_monitor push_deploy
|
2022-03-31 15:34:33 -04:00
|
|
|
push: push_images
|
2021-03-09 12:02:00 -05:00
|
|
|
|
2021-02-23 15:53:46 -05:00
|
|
|
# Tasks
|
2021-04-06 16:16:50 -04:00
|
|
|
deploy_web:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l app
|
2021-04-06 16:16:50 -04:00
|
|
|
deploy: deploy_web
|
2021-04-13 11:59:37 -04:00
|
|
|
app: deploy_web
|
2021-04-28 15:39:25 -04:00
|
|
|
web: deploy_web
|
|
|
|
deploy_static:
|
|
|
|
- ansible-playbook ansible/deploy.yml -l app --tags static
|
|
|
|
static: deploy_static
|
2021-02-24 20:02:37 -05:00
|
|
|
deploy_node:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l node
|
2021-04-06 16:16:50 -04:00
|
|
|
node: deploy_node
|
2021-02-24 20:02:37 -05:00
|
|
|
deploy_task:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l task
|
2021-04-06 16:16:50 -04:00
|
|
|
task: deploy_task
|
2021-02-25 10:31:29 -05:00
|
|
|
deploy_www:
|
2022-03-15 17:19:01 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l haproxy
|
2021-04-06 16:16:50 -04:00
|
|
|
www: deploy_www
|
2021-03-08 11:33:58 -05:00
|
|
|
deploy_work:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l work
|
2021-04-06 16:16:50 -04:00
|
|
|
work: deploy_work
|
2021-03-10 10:36:32 -05:00
|
|
|
deploy_monitor:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l db
|
2021-04-06 16:16:50 -04:00
|
|
|
monitor: deploy_monitor
|
2021-03-15 20:06:27 -04:00
|
|
|
deploy_staging:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l staging
|
2021-04-06 16:16:50 -04:00
|
|
|
staging: deploy_staging
|
|
|
|
celery_stop:
|
2021-04-13 11:59:37 -04:00
|
|
|
- ansible-playbook ansible/deploy.yml -l task --tags stop
|
2021-05-13 19:53:34 -04:00
|
|
|
maintenance_on:
|
|
|
|
- ansible-playbook ansible/deploy.yml -l web --tags maintenance_on
|
|
|
|
maintenance_off:
|
|
|
|
- ansible-playbook ansible/deploy.yml -l web --tags maintenance_off
|
2021-04-16 17:25:32 -04:00
|
|
|
|
2021-02-24 20:02:37 -05:00
|
|
|
# Provision
|
2021-02-23 15:53:46 -05:00
|
|
|
firewall:
|
2021-04-16 17:25:32 -04:00
|
|
|
- ansible-playbook ansible/all.yml -l db --tags firewall
|
|
|
|
oldfirewall:
|
|
|
|
- ANSIBLE_CONFIG=/srv/newsblur/ansible.old.cfg ansible-playbook ansible/all.yml -l db --tags firewall
|
2021-08-11 18:36:35 -04:00
|
|
|
repairmongo:
|
|
|
|
- sudo docker run -v "/srv/newsblur/docker/volumes/db_mongo:/data/db" mongo:4.0 mongod --repair --dbpath /data/db
|
|
|
|
|
2021-02-23 15:53:46 -05:00
|
|
|
|
2021-02-24 10:21:47 -05:00
|
|
|
# performance tests
|
|
|
|
perf-cli:
|
|
|
|
locust -f perf/locust.py --headless -u $(users) -r $(rate) --run-time 5m --host=$(host)
|
|
|
|
|
|
|
|
perf-ui:
|
|
|
|
locust -f perf/locust.py
|
|
|
|
|
|
|
|
perf-docker:
|
|
|
|
- docker build . --file=./perf/Dockerfile --tag=perf-docker
|
2021-02-24 12:07:44 -05:00
|
|
|
- docker run -it -p 8089:8089 perf-docker locust -f locust.py
|
2021-03-24 21:09:26 -04:00
|
|
|
|
|
|
|
clean:
|
|
|
|
- find . -name \*.pyc -delete
|
2021-12-15 13:40:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
grafana-dashboards:
|
2022-01-04 15:54:37 -05:00
|
|
|
- python3 utils/grafana_backup.py
|