Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug scripts #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ public/packs
public/packs-test
node_modules
yarn-error.log
scripts
41 changes: 30 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 <target>"
@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
13 changes: 13 additions & 0 deletions scripts/debug.sh
Original file line number Diff line number Diff line change
@@ -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/${PROVIDENTIA_PROJECT}/hosts/$host"
done