-
Notifications
You must be signed in to change notification settings - Fork 0
Populate by files
Le Gall, Benoit edited this page May 2, 2024
·
9 revisions
-
consul.files.root-path: path to root directory (Required) -
consul.files.target: subdirectory used to override root configurations (Required) -
consul.files.format: (YAML | JSON | PROPERTIES) Supported format of the files (Required)
You need to have:
- all base configurations in the root of the configurations directory
- 1 subdirectory by environment, with only the configurations to override with environment related values (usually url, table name, ... all those values that change between environments)
Given we have a very classic platform with
- orders-services => need configurations to postgres and rabbitmq
- products-services => need configurations to couchbase and rabbitmq
- users-services => need configurations to postgres
you will have this structure:
.
└── path_to_configuration
├── dev
│ ├── application,couchbase.yaml
│ ├── application,postgres.yaml
│ ├── application,rabbitmq.yaml
│ └── orders-services.yaml
├── stg
│ ├── application,couchbase.yaml
│ ├── application,postgres.yaml
│ ├── application,rabbitmq.yaml
│ └── products-services.yaml
├── qa
│ ├── application,couchbase.yaml
│ ├── application,postgres.yaml
│ └── application,rabbitmq.yaml
├── prod
│ ├── application,couchbase.yaml
│ ├── application,postgres.yaml
│ ├── application,rabbitmq.yaml
│ └── users-services.yaml
├── application.yaml
├── application,couchbase.yaml
├── application,postgres.yaml
├── application,rabbitmq.yaml
├── orders-services.yaml
├── products-services.yaml
└── users-services.yaml
You will need to define the postgres, rabbitmq and couchbase as environment (Micronaut) or profile (Spring)
public class MyApplication {
public static void main(final String[] args) {
Micronaut.build(args)
.mainClass(MyApplication.class)
.environments("rabbitmq", "postgres")
.start();
}
}java -jar {path_to_archive}/consul-populate-1.0.0 \
--consul.host=localhost \
--consul.port=8500 \
--consul.kv.prefix=frog \
--consul.kv.version=1.2.3 \
--consul.files.format=YAML \
--consul.files.target=dev \
--consul.files.root-path={path_to_configuration}services:
consul:
image: hashicorp/consul:1.18.1
hostname: consul
ports:
- "8500:8500"
consul-populate:
image: frogdevelopment/consul-populate:1.0.0
environment:
CONSUL_HOST: consul
CONSUL_PORT: 8500
CONSUL_KV_PREFIX: frog
CONSUL_KV_VERSION: 1.2.3
CONSUL_FILES_FORMAT: YAML
CONSUL_FILES_TARGET: dev
CONSUL_FILES_ROOT_PATH: /configurations
volumes:
- {path_to_configuration}:/configurations:ro# FIXME not tested yet
apiVersion: batch/v1
kind: Job
metadata:
name: consul-populate
spec:
template:
spec:
automountServiceAccountToken: false
containers:
- name: consul-populate
image: frogdevelopment/consul-populate:1.0.0
args:
- "consul.host=consul-svc"
- "consul.port=8500"
- "consul.kv.prefix=frog"
- "consul.kv.version=1.2.3"
- "consul.files.format=YAML"
- "consul.files.target=dev"
- "consul.files.root-path=/configurations"
imagePullPolicy: Always
volumeMounts:
- mountPath: /configurations
name: configurations
restartPolicy: Never
volumes:
- name: configurations
persistentVolumeClaim:
claimName: configurationsPVC
readOnly: true
backoffLimit: 3