Kaynağa Gözat

Build: allow dynamically change docker image (#18112)

* Build: allow dynamically change docker image

Right now, only for couple DBs.
With the 2.1, you can do `${TAG:-5.6}` without needing the `.env` file, but
it seems it would be better for back-compat to support `.env` right now.

Fixes #17891

* Build: add prefix for removal process

* Docs: mention makefile command instead of the bash

Since we are moving to makefile for things and make command
simplifies some of the actions you have to perform to work with
different environments

* Docs: mention dynamic tags in the docs

* Docs: avoid name collision

Fixes #16107
Oleg Gaidarenko 6 yıl önce
ebeveyn
işleme
b049b003f2

+ 4 - 3
.gitignore

@@ -39,10 +39,11 @@ public/css/*.min.css
 /data/*
 /bin/*
 
+# devenv
+/devenv/docker-compose.yaml
+/devenv/.env
+
 conf/custom.ini
-fig.yml
-devenv/docker-compose.yml
-devenv/docker-compose.yaml
 /conf/provisioning/**/custom.yaml
 /conf/provisioning/**/dev.yaml
 /conf/ldap_dev.toml

+ 1 - 1
Makefile

@@ -125,7 +125,7 @@ devenv: devenv-down
 
 	@cd devenv; \
 	./create_docker_compose.sh $(targets) || \
-	(rm -rf docker-compose.yaml; exit 1)
+	(rm -rf {docker-compose.yaml,conf.tmp,.env}; exit 1)
 
 	@cd devenv; \
 	docker-compose up -d --build

+ 6 - 2
devenv/README.md

@@ -22,8 +22,7 @@ found. The dashboards are located in the `devenv/dev-dashboards` folder.
 # docker-compose with databases
 
 ```bash
-./create_docker_compose.sh influxdb prometheus2 elastic5
-docker-compose up
+make devenv sources=influxdb,prometheus2,elastic5
 ```
 
 This command will create a docker compose file with specified databases configured and ready to run. Each database has
@@ -31,3 +30,8 @@ a prepared image with some fake data ready to use. For available databases see `
 for some databases there are multiple images, for example there is prometheus_mac specifically for Macs or different
 version.
 
+Some of the blocks support dynamic change of the image version used in docker file. The signature looks like this - `make devenv sources=postgres,openldap name-of-block_version=9.2` -
+
+```bash
+make devenv sources=postgres,openldap postgres_version=9.2
+```

+ 15 - 9
devenv/create_docker_compose.sh

@@ -8,8 +8,8 @@ grafana_config_file=conf.tmp
 grafana_config=config
 
 compose_header_file=docker/compose_header.yml
-fig_file=docker-compose.yaml
-fig_config=docker-compose.yaml
+compose_file=docker-compose.yaml
+env_file=.env
 
 if [ "$#" == 0 ]; then
     blocks=`ls $blocks_dir`
@@ -24,15 +24,15 @@ if [ "$#" == 0 ]; then
     exit 0
 fi
 
-for file in $grafana_config_file $fig_file; do
+for file in $grafana_config_file $compose_file $env_file; do
     if [ -e $file ]; then
         echo "Deleting $file"
         rm $file
     fi
 done
 
-echo "Adding Compose header to $fig_file"
-cat $compose_header_file >> $fig_file
+echo "Adding Compose header to $compose_file"
+cat $compose_header_file >> $compose_file
 
 for dir in $@; do
     current_dir=$blocks_dir/$dir
@@ -47,10 +47,16 @@ for dir in $@; do
         echo "" >> $grafana_config_file
     fi
 
-    if [ -e $current_dir/$fig_config ]; then
-        echo "Adding $current_dir/$fig_config to $fig_file"
-        cat $current_dir/$fig_config >> $fig_file
-        echo "" >> $fig_file
+    if [ -e $current_dir/$compose_file ]; then
+        echo "Adding $current_dir/$compose_file to $compose_file"
+        cat $current_dir/$compose_file >> $compose_file
+        echo "" >> $compose_file
+    fi
+
+    if [ -e $current_dir/$env_file ]; then
+        echo "Adding $current_dir/$env_file to .env"
+        cat $current_dir/$env_file >> .env
+        echo "" >> .env
     fi
 done
 

+ 1 - 0
devenv/docker/blocks/mysql/.env

@@ -0,0 +1 @@
+mysql_version=5.6

+ 1 - 1
devenv/docker/blocks/mysql/docker-compose.yaml

@@ -1,5 +1,5 @@
   mysql:
-    image: mysql:5.6
+    image: mysql:${mysql_version}
     environment:
       MYSQL_ROOT_PASSWORD: rootpass
       MYSQL_DATABASE: grafana

+ 1 - 0
devenv/docker/blocks/postgres/.env

@@ -0,0 +1 @@
+postgres_version=9.3

+ 1 - 1
devenv/docker/blocks/postgres/docker-compose.yaml

@@ -1,5 +1,5 @@
   postgrestest:
-    image: postgres:9.3
+    image: postgres:${postgres_version}
     environment:
       POSTGRES_USER: grafana
       POSTGRES_PASSWORD: password