Skip to content
Merged
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
21 changes: 21 additions & 0 deletions .docker/scalingo-job/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM alpine:3.19

RUN apk add --no-cache \
bash \
curl \
ca-certificates \
coreutils \
tar \
gzip \
&& update-ca-certificates

ENV TMPDIR=/tmp
RUN mkdir -p /tmp

RUN curl -fsSL https://cli-dl.scalingo.com/install.sh | bash && scalingo --version

COPY .docker/scalingo-job/sync-db.sh /sync-db.sh

RUN chmod +x /sync-db.sh

ENTRYPOINT ["/sync-db.sh"]
35 changes: 35 additions & 0 deletions .docker/scalingo-job/sync-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh

set -eu

IMAGE_VERSION="1.0.1"

log() {
level="$1"
shift
echo "$(date -u '+%Y-%m-%dT%H:%M:%SZ') [$level] $*"
}

log INFO "Image version: ${IMAGE_VERSION}"

: "${SCALINGO_API_TOKEN:?Missing SCALINGO_API_TOKEN}"
SCALINGO_APP="${METABASE_SYNC_SCALINGO_APP:-histologe-preprod}"

command -v scalingo >/dev/null 2>&1 || { log ERROR "scalingo CLI not found"; exit 127; }

log INFO "Starting Scalingo job"
log INFO "App: ${SCALINGO_APP}"
log INFO "Remote command: sh /app/scripts/sync-db.sh"

log INFO "Version installée : $(scalingo --version)"

# LOCAL MODE
if [ "${METABASE_SYNC_LOCAL_MODE:-0}" = "1" ]; then
log WARN "Running in LOCAL MODE"
log INFO "Executing safe Scalingo command: scalingo apps"
exec scalingo apps
fi

# PROD MODE
log INFO "Executing remote sync-db script on Scalingo"
exec scalingo -a "$SCALINGO_APP" run -d -- sh /app/scripts/sync-db.sh
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ PHPUNIT = ./vendor/bin/phpunit
SYMFONY = php bin/console
NPX = npx
NPM = npm
METABASE_SYNC_LOCAL_MODE = 1
METABASE_SYNC_IMAGE_NAME = scalingo-sync-silo-metabase
METABASE_SYNC_SCALINGO_APP = histologe-preprod
METABASE_SYNC_IMAGE_LOCAL = $(METABASE_SYNC_IMAGE_NAME):local
METABASE_SYNC_SCALINGO_JOB_DOCKERFILE = .docker/scalingo-job/Dockerfile
METABASE_SYNC_SCW_REGISTRY = rg.fr-par.scw.cloud
METABASE_SYNC_SCW_NAMESPACE = signal-logement

help:
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
Expand Down Expand Up @@ -267,6 +274,42 @@ scalingo-update-cli: ## Install/Update Scalingo CLI
run-concurrency-request: ## Run concurrency request based postman collection ex: make run-concurrency-request nb=5 envName=local|demo
@bash -l -c 'node ./tools/newman/run_concurrency_request.js nb=$(nb) envName=$(envName)'

## Sync metabase
scalingo-job-build: ## Build Scalingo sync job container
@echo "\033[33mBuilding Scalingo job image...\033[0m"
docker build \
-f $(METABASE_SYNC_SCALINGO_JOB_DOCKERFILE) \
-t $(METABASE_SYNC_IMAGE_NAME):local \
.
@echo "\033[32m✅ Image built: $(METABASE_SYNC_IMAGE_NAME):local\033[0m"
@echo "\n\033[36m💡 Vous pouvez tester l'image localement en exécutant : make scalingo-job-run\033[0m"
@echo "\033[33m⚠️ Note : Assurez-vous d'avoir ajouté la variable d'envionnement export SCALINGO_API_TOKEN=xxxxxxxxxxxxxx"
@echo " Pour générez un token API : https://dashboard.scalingo.com/account/tokens\033[0m"
@echo "\n\033[31m/!\ ATTENTION : Vérifiez bien le dernier tag distant avant de pousser /!\ \033[0m"
@echo "\033[33mTags actuellement présents sur le registry distant https://console.scaleway.com/registry \033[0m"
@echo "\n\033[35m🚀 RELEASE : Pour pousser l'image, exécutez :"
@echo " make scalingo-job-release IMAGE_VERSION=999.999\033[0m"

scalingo-job-run: ## Run Scalingo sync job locally
@echo "\033[33mRunning Scalingo job locally...\033[0m"
docker run --rm \
-e SCALINGO_API_TOKEN=$(METABASE_SYNC_SCALINGO_API_TOKEN) \
-e METABASE_SYNC_SCALINGO_APP=$(METABASE_SYNC_SCALINGO_APP) \
-e METABASE_SYNC_LOCAL_MODE=0 \
$(METABASE_SYNC_IMAGE_NAME):local

scalingo-job-tag: ## Tag the local image with a version for Scaleway registry - make scalingo-job-tag IMAGE_VERSION=1.0.x
@echo "Tagging image $(METABASE_SYNC_IMAGE_LOCAL) as $(IMAGE_VERSION)"
docker tag $(METABASE_SYNC_IMAGE_LOCAL) \
$(METABASE_SYNC_SCW_REGISTRY)/$(METABASE_SYNC_SCW_NAMESPACE)/$(METABASE_SYNC_IMAGE_NAME):$(IMAGE_VERSION)

scalingo-job-push: ## Push the versioned image to Scaleway registry - make scalingo-job-push IMAGE_VERSION=1.0.x
@echo "Pushing image version $(IMAGE_VERSION) to Scaleway registry"
docker push \
$(METABASE_SYNC_SCW_REGISTRY)/$(METABASE_SYNC_SCW_NAMESPACE)/$(METABASE_SYNC_IMAGE_NAME):$(IMAGE_VERSION)

scalingo-job-release: scalingo-job-tag scalingo-job-push ## Tag and push image to Scaleway - make scalingo-job-release IMAGE_VERSION=1.0.x

.tools-destroy:
@echo "\033[33mRemoving tools containers ...\033[0m"
@$(DOCKER_COMP) -f $(DOCKER_COMP_FILE_TOOLS) rm -v --force --stop || true
Expand Down
4 changes: 1 addition & 3 deletions config/app/cron_scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ parameters:
-
command: 'php bin/console app:sync-esabora-schs'
schedule: '%env(ESABORA_CRON_SCHEDULE_SYNC_SCHS)%'
-
command: 'sh /app/scripts/sync-db.sh'
schedule: '%env(METABASE_CRON_SCHEDULE_SYNC_BDD)%'
Comment on lines -14 to -16
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai déja désactivé le container clock sur preprod

Image


Loading