NewsBlur/Makefile

191 lines
7.9 KiB
Makefile
Raw Normal View History

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)
newsblur := $(shell docker ps -qf "name=newsblur_web")
2020-10-04 17:41:35 +07:00
.PHONY: node
#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
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
metrics-ps:
2022-01-26 13:33:59 -05:00
- RUNWITHMAKEBUILD=True docker compose -f docker-compose.yml -f docker-compose.metrics.yml ps
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
collectstatic:
- rm -fr static
2022-02-24 10:41:20 -05:00
- docker pull newsblur/newsblur_deploy
- docker run --rm -v $(shell pwd):/srv/newsblur newsblur/newsblur_deploy
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
coffee:
- coffee -c -w **/*.coffee
2020-10-04 17:41:35 +07:00
2020-11-03 11:25:31 +07:00
shell:
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker-compose exec newsblur_web ./manage.py shell_plus
bash:
- 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:
- RUNWITHMAKEBUILD=True CURRENT_UID=${CURRENT_UID} CURRENT_GID=${CURRENT_GID} docker attach ${newsblur}
log:
2022-01-26 13:33:59 -05:00
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20 newsblur_web newsblur_node
logweb: log
logcelery:
2022-01-26 13:33:59 -05:00
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20 task_celery
logtask: logcelery
logmongo:
2022-01-26 13:33:59 -05:00
- RUNWITHMAKEBUILD=True docker compose logs -f db_mongo
alllogs:
2022-01-26 13:33:59 -05:00
- RUNWITHMAKEBUILD=True docker compose logs -f --tail 20
logall: alllogs
2020-10-04 17:41:35 +07:00
# brings down containers
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
# Digital Ocean / Terraform
list:
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` compute droplet list
sizes:
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` compute size list
size: sizes
ratelimit:
- doctl -t `cat /srv/secrets-newsblur/keys/digital_ocean.token` account ratelimit
ansible-deps:
ansible-galaxy install -p roles -r ansible/roles/requirements.yml --roles-path ansible/roles
tfrefresh:
terraform -chdir=terraform refresh
plan:
terraform -chdir=terraform plan -refresh=false
apply:
terraform -chdir=terraform apply -refresh=false -parallelism=15
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
# 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
build_web:
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/newsblur_base_image.Dockerfile --tag=newsblur/newsblur_python3
build_node:
- 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:
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/monitor/Dockerfile --tag=newsblur/newsblur_monitor
build_deploy:
- docker buildx build . --platform linux/amd64,linux/arm64 --file=docker/newsblur_deploy.Dockerfile --tag=newsblur/newsblur_deploy
build: build_web build_node build_monitor build_deploy
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
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
# Tasks
2021-04-06 16:16:50 -04:00
deploy_web:
- ansible-playbook ansible/deploy.yml -l app
2021-04-06 16:16:50 -04:00
deploy: deploy_web
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
deploy_node:
- ansible-playbook ansible/deploy.yml -l node
2021-04-06 16:16:50 -04:00
node: deploy_node
deploy_task:
- ansible-playbook ansible/deploy.yml -l task
2021-04-06 16:16:50 -04:00
task: deploy_task
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
deploy_work:
- 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:
- ansible-playbook ansible/deploy.yml -l db
2021-04-06 16:16:50 -04:00
monitor: deploy_monitor
deploy_staging:
- ansible-playbook ansible/deploy.yml -l staging
2021-04-06 16:16:50 -04:00
staging: deploy_staging
celery_stop:
- ansible-playbook ansible/deploy.yml -l task --tags stop
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
# Provision
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
repairmongo:
- sudo docker run -v "/srv/newsblur/docker/volumes/db_mongo:/data/db" mongo:4.0 mongod --repair --dbpath /data/db
# 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
clean:
- find . -name \*.pyc -delete
grafana-dashboards:
- python3 utils/grafana_backup.py