Skip to content

Commit d672244

Browse files
committed
Update
1 parent b264a2e commit d672244

File tree

6 files changed

+36
-39
lines changed

6 files changed

+36
-39
lines changed

scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wait4x

scripts/common.Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,13 @@ show-venv: venv ## show venv info
342342
@echo venv: $(VENV_DIR)
343343
344344
.PHONY: install
345-
install: requirements.txt venv ## install dependencies from ./requirements.txt
346-
@VIRTUAL_ENV=$(VENV_DIR) $(UV) pip install --requirement $<
345+
install: guard-optional-REQUIREMENTS_FILE venv ## install requirements.txt dependencies
346+
@if [ -z "$(REQUIREMENTS_FILE)" ]; then \
347+
REQUIREMENTS_FILE=./requirements.txt; \
348+
else \
349+
REQUIREMENTS_FILE=$(REQUIREMENTS_FILE); \
350+
fi; \
351+
VIRTUAL_ENV=$(VENV_DIR) $(UV) pip install --requirement $$REQUIREMENTS_FILE
347352
348353
# https://github.com/kolypto/j2cli?tab=readme-ov-file#customization
349354
ifeq ($(shell test -f j2cli_customization.py && echo -n yes),yes)
@@ -362,3 +367,16 @@ define jinja
362367
endef
363368
364369
endif
370+
371+
#
372+
# wait-fot-it functionality
373+
#
374+
375+
WAIT_FOR_IT := $(REPO_BASE_DIR)/scripts/wait4x
376+
377+
# https://github.com/wait4x/wait4x
378+
$(WAIT_FOR_IT):
379+
@curl --output-dir /tmp --silent --location --remote-name https://github.com/wait4x/wait4x/releases/download/v3.5.0/wait4x-linux-amd64.tar.gz
380+
@tar -xf /tmp/wait4x-linux-amd64.tar.gz -C $(REPO_BASE_DIR)/scripts/
381+
@rm /tmp/wait4x-linux-amd64.tar.gz
382+
$@ version

services/monitoring/grafana/Makefile

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,11 @@ terraform-apply: $(REPO_CONFIG_LOCATION) terraform/plan.cache $(TF_STATE_FILE) e
3939
terraform -chdir=./terraform apply plan.cache
4040

4141
.PHONY: ensure-grafana-online
42-
ensure-grafana-online:
42+
ensure-grafana-online: $(WAIT_FOR_IT)
4343
@set -o allexport; \
4444
source $(REPO_CONFIG_LOCATION); \
4545
set +o allexport; \
46-
url=$${TF_VAR_GRAFANA_URL}; \
47-
echo "Waiting for grafana at $$url to become reachable..."; \
48-
attempts=0; \
49-
max_attempts=10; \
50-
while [ $$attempts -lt $$max_attempts ]; do \
51-
status_code=$$(curl -k -o /dev/null -s -w "%{http_code}" --max-time 10 $$url); \
52-
if [ "$$status_code" -ge 200 ] && [ "$$status_code" -lt 400 ]; then \
53-
echo "Grafana is online"; \
54-
break; \
55-
else \
56-
echo "Grafana still unreachable, waiting 5s for grafana to become reachable... (Attempt $$((attempts+1)))"; \
57-
sleep 5; \
58-
attempts=$$((attempts + 1)); \
59-
fi; \
60-
done; \
61-
if [ $$attempts -eq $$max_attempts ]; then \
62-
echo "Max attempts reached, Grafana is still unreachable."; \
63-
exit 1; \
64-
fi;
46+
$(WAIT_FOR_IT) http $$TF_VAR_GRAFANA_URL --timeout=120s --interval=5s --expect-status-code 200
6547

6648
.PHONY: assets
6749
assets: ${REPO_CONFIG_LOCATION}

services/portainer/Makefile

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,38 @@ include ${REPO_BASE_DIR}/scripts/common.Makefile
1515
.PHONY: up ## Deploys portainer stack
1616
up: .init .env secrets ${TEMP_COMPOSE}
1717
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE} ${STACK_NAME}
18+
@$(MAKE) --noprint configure-portainer-registry
1819

1920
.PHONY: up-local ## Deploys portainer stack for local deployment
2021
up-local: .init .env secrets ${TEMP_COMPOSE} ${TEMP_COMPOSE}-local
2122
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-local ${STACK_NAME}
23+
@$(MAKE) --noprint configure-portainer-registry
2224

2325
.PHONY: up-dalco ## Deploys portainer stack for Dalco Cluster
2426
up-dalco: .init .env secrets ${TEMP_COMPOSE}-dalco
2527
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-dalco ${STACK_NAME}
28+
@$(MAKE) --noprint configure-portainer-registry
2629

2730
.PHONY: up-aws ## Deploys portainer stack for AWS
2831
up-aws: .init .env secrets ${TEMP_COMPOSE}-aws
2932
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-aws ${STACK_NAME}
33+
@$(MAKE) --noprint configure-portainer-registry
3034

3135
.PHONY: up-public ## Deploys portainer stack for public access Cluster
3236
up-public: up-dalco
3337

3438
.PHONY: up-master ## Deploys portainer stack for master Cluster
3539
up-master: .init .env secrets ${TEMP_COMPOSE}-master
3640
@docker stack deploy --with-registry-auth --prune --compose-file ${TEMP_COMPOSE}-master ${STACK_NAME}
41+
@$(MAKE) --noprint configure-portainer-registry
3742

3843

39-
.PHONY: configure-registry
40-
configure-registry: ## Add if necessary dockerhub registry configuration to portainer.
41-
@set -o allexport; \
42-
source $(REPO_CONFIG_LOCATION); \
43-
set +o allexport; \
44-
while [ "$$(curl -s -o /dev/null -I -w "%{http_code}" --max-time 10 -H "Accept: application/json" -H "Content-Type: application/json" -X GET https://"$$MONITORING_DOMAIN"/portainer/#/auth)" != 200 ]; do\
45-
echo "waiting for portainer to run...";\
46-
sleep 5s;\
47-
done;\
48-
echo "Updating docker-hub config";\
49-
authentificationToken=$$(curl -o /dev/null -X POST "https://"$$MONITORING_DOMAIN"/portainer/api/auth" -H "Content-Type: application/json" -d "{ \"Username\": \"$${PORTAINER_ADMIN_LOGIN}\", \"Password\": \"$${PORTAINER_ADMIN_PWD}\"}"); \
50-
authentificationToken=$$(echo "$$authentificationToken" | jq --raw-output '.jwt'); \
51-
update_hub=$$(curl -o /dev/null -X PUT "https://"$$MONITORING_DOMAIN"/portainer/api/dockerhub" -H "accept: application/json" -H \
52-
"Authorization: Bearer $${authentificationToken}" -H "Content-Type: application/json" \
53-
-d "{ \"Authentication\": true, \"Username\": \"$$DOCKER_HUB_LOGIN\", \"Password\": \"$$DOCKER_HUB_PASSWORD\"}"); \
44+
.PHONY: configure-portainer-registry
45+
configure-portainer-registry: venv $(VENV_BIN)/python $(WAIT_FOR_IT) ## Add if necessary dockerhub registry configuration to portainer.
46+
@$(MAKE) --no-print install REQUIREMENTS_FILE=./scripts/requirements.txt
47+
@set -o allexport; source $(REPO_CONFIG_LOCATION); set +o allexport; \
48+
$(WAIT_FOR_IT) http $$PORTAINER_URL --timeout=120s --interval=5s --expect-status-code 200 && \
49+
$(VENV_BIN)/python ./scripts/configure_portainer_registry.py
5450

5551

5652
# Helpers -------------------------------------------------
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
tenacity==2.32.4
2-
requests==9.1.2
1+
tenacity==9.1.2
2+
requests==2.32.4

0 commit comments

Comments
 (0)