From 9871ba73ef0c2a6a3337974543688d2d772271d0 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 11:29:29 +0300 Subject: [PATCH] replace migrator & add local domain --- .env | 4 ++++ Makefile | 16 ++++++++++++++-- docker-compose.yml | 11 ++++++++--- files/Dockerfile.migrator | 3 +++ .../1698135711_create_logs_table.down.sql | 1 - ...35711_create_logs_table.up.sql => 1_init.sql} | 0 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 .env create mode 100644 files/Dockerfile.migrator delete mode 100644 files/migrations/1698135711_create_logs_table.down.sql rename files/migrations/{1698135711_create_logs_table.up.sql => 1_init.sql} (100%) diff --git a/.env b/.env new file mode 100644 index 0000000..03ba094 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +CLICKHOUSE_USER=default +CLICKHOUSE_PASSWORD=default +CLICKHOUSE_DB=default +CLICKHOUSE_PORT=8123 diff --git a/Makefile b/Makefile index c57a52c..aeb8bc8 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,24 @@ +include .env SHELL = /bin/bash -o pipefail ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -MIGRATIONS_DIR=$(SRC_DIR)/files/migrations +MIGRATIONS_DIR=$(ROOT_DIR)/files/migrations + +all: migrator migrate up + +migrator: + @docker buildx build --tag neur0toxine/clickhouse-migrations:latest -f $(ROOT_DIR)/files/Dockerfile.migrator $(ROOT_DIR)/files migrate: @docker-compose up -d - @docker run -v $(MIGRATIONS_DIR):/migrations --network host migrate/migrate -path=/migrations/ -database "clickhouse://localhost:8123?username=default&password=default&database=default" up all + @docker run -v $(MIGRATIONS_DIR):/migrations --network host neur0toxine/clickhouse-migrations:latest migrate --host=http://localhost:$(CLICKHOUSE_PORT) --user=$(CLICKHOUSE_USER) --password=$(CLICKHOUSE_PASSWORD) --db=default --migrations-home=/migrations @docker-compose stop up: @docker-compose up + +stop: + @docker-compose stop + +down: + @docker-compose down -v diff --git a/docker-compose.yml b/docker-compose.yml index 5131ab6..07d436e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,13 +7,18 @@ services: - grafana_data:/var/lib/grafana ports: - '3000:3000' + labels: + traefik.enable: "true" + traefik.http.routers.grafana.entrypoints: web + traefik.http.routers.grafana.rule: "Host(`grafana.test`)" + traefik.http.services.grafana.loadbalancer.server.port: "3000" clickhouse: image: docker.io/bitnami/clickhouse:23 environment: - - CLICKHOUSE_ADMIN_USER=default - - CLICKHOUSE_ADMIN_PASSWORD=default + - CLICKHOUSE_ADMIN_USER=${CLICKHOUSE_USER} + - CLICKHOUSE_ADMIN_PASSWORD=${CLICKHOUSE_PASSWORD} ports: - - '8123:8123' + - '${CLICKHOUSE_PORT}:8123' volumes: - clickhouse_data:/bitnami/clickhouse vector: diff --git a/files/Dockerfile.migrator b/files/Dockerfile.migrator new file mode 100644 index 0000000..3d43416 --- /dev/null +++ b/files/Dockerfile.migrator @@ -0,0 +1,3 @@ +FROM node:lts-alpine +RUN npm install --global clickhouse-migrations && npm cache clean --force +ENTRYPOINT ["/usr/local/bin/clickhouse-migrations"] \ No newline at end of file diff --git a/files/migrations/1698135711_create_logs_table.down.sql b/files/migrations/1698135711_create_logs_table.down.sql deleted file mode 100644 index b1c111a..0000000 --- a/files/migrations/1698135711_create_logs_table.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE log_docker_raw; \ No newline at end of file diff --git a/files/migrations/1698135711_create_logs_table.up.sql b/files/migrations/1_init.sql similarity index 100% rename from files/migrations/1698135711_create_logs_table.up.sql rename to files/migrations/1_init.sql