From 319b675ec921c145d5bb512412b4afea928d9411 Mon Sep 17 00:00:00 2001 From: "tavi.poldma" Date: Fri, 15 Sep 2023 11:12:11 +0300 Subject: [PATCH 1/3] improve Makefile structure --- Makefile | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6f71a856..582f0816 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,53 @@ -#-include .makerc -#-include .makerc-vars +#!make .DEFAULT_GOAL := help -.PHONY: help clean stop start shell console logs +## help: list all available make targets with descriptions +.PHONY: help help: - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-16s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + @echo "[*] usage: make " + @sed -nr 's/^##\s+/\t/p' ${MAKEFILE_LIST} | column -t -s ':' -clean: ## stop, remove data, containers and images +## clean: stop, remove data, containers and images +.PHONY: clean +clean: sudo docker compose -f docker/dev/docker-compose.yml down --rmi local -v --remove-orphans +## build: build containers / service +.PHONY: build build: sudo docker compose -f docker/dev/docker-compose.yml build -stop: ## stop containers / services +## stop: stop containers / service +.PHONY: stop +stop: sudo docker compose -f docker/dev/docker-compose.yml down -start: ## start containers daemonized +## start: start containers daemonized +.PHONY: start +start: sudo docker compose -f docker/dev/docker-compose.yml up -d +## restart: restart containers +.PHONY: restart restart: stop start -shell: ## open webapp shell +## shell: open webapp shell +.PHONY: shell +shell: sudo docker compose -f docker/dev/docker-compose.yml exec web sh -console: ## open rails console +## console: open rails console +.PHONY: console +console: sudo docker compose -f docker/dev/docker-compose.yml exec web rails c -logs: ## follow logs +## logs: tail container logs +.PHONY: logs +logs: sudo docker compose -f docker/dev/docker-compose.yml logs -f --tail=100 -clear-redis: ## clear redis (rails cache) +## clear-redis: clear redis (rails cache) +.PHONY: clear-redis +clear-redis: sudo docker compose -f docker/dev/docker-compose.yml exec redis redis-cli flushdb \ No newline at end of file From 54e5a95500e8275bc10ef184fe423abf4eb10424 Mon Sep 17 00:00:00 2001 From: "tavi.poldma" Date: Fri, 15 Sep 2023 11:12:49 +0300 Subject: [PATCH 2/3] add a quick debug script --- .dockerignore | 1 + scripts/debug.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 scripts/debug.sh diff --git a/.dockerignore b/.dockerignore index ec5f0de3..096bdc79 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,3 +15,4 @@ public/packs public/packs-test node_modules yarn-error.log +scripts \ No newline at end of file diff --git a/scripts/debug.sh b/scripts/debug.sh new file mode 100644 index 00000000..da780402 --- /dev/null +++ b/scripts/debug.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +PROVIDENTIA_TOKEN=your-api-token +PROVIDENTIA_FQDN=providentia-fqdn +PROVIDENTIA_PROJECT=exercise-name-here + +# Get all hosts from the API +ALL_HOSTS=$(curl -k -H "Authorization: Token ${PROVIDENTIA_TOKEN}" https://${PROVIDENTIA_FQDN}/api/v3/${PROVIDENTIA_PROJECT}/hosts) + +# Parse the JSON array and loop over each item, making an API call per host to get the HTTP status code +for host in $(echo $ALL_HOSTS | jq -r '.result[]'); do + curl -k -s -o /dev/null -I -w "${host} %{http_code}\n" -H "Authorization: Token ${PROVIDENTIA_TOKEN}" "https://${PROVIDENTIA_FQDN}/api/v3/dcm3/hosts/$host" +done From 5f11ed90ae141159b3c627d91bfac7459cc9399e Mon Sep 17 00:00:00 2001 From: "tavi.poldma" Date: Fri, 15 Sep 2023 11:52:05 +0300 Subject: [PATCH 3/3] fix debug script --- scripts/debug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/debug.sh b/scripts/debug.sh index da780402..2afcfbe1 100644 --- a/scripts/debug.sh +++ b/scripts/debug.sh @@ -9,5 +9,5 @@ ALL_HOSTS=$(curl -k -H "Authorization: Token ${PROVIDENTIA_TOKEN}" https://${PRO # Parse the JSON array and loop over each item, making an API call per host to get the HTTP status code for host in $(echo $ALL_HOSTS | jq -r '.result[]'); do - curl -k -s -o /dev/null -I -w "${host} %{http_code}\n" -H "Authorization: Token ${PROVIDENTIA_TOKEN}" "https://${PROVIDENTIA_FQDN}/api/v3/dcm3/hosts/$host" + curl -k -s -o /dev/null -I -w "${host} %{http_code}\n" -H "Authorization: Token ${PROVIDENTIA_TOKEN}" "https://${PROVIDENTIA_FQDN}/api/v3/${PROVIDENTIA_PROJECT}/hosts/$host" done