Skip to content

Commit

Permalink
Merge pull request #23 from murdos/micronaut-support
Browse files Browse the repository at this point in the history
Add support for Micronaut distributed configuration
  • Loading branch information
pascalgrimaud authored Sep 27, 2020
2 parents ddfa7f8 + 9fd9a03 commit dde1d77
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ RUN apk --update add nodejs git openssh curl bash inotify-tools jq && \
mkdir -p /etc/git2consul.d

ADD /load-config.sh /
ADD /upload-consul-file.sh /
VOLUME /config

ENV CONFIG_MODE=filesystem
ENV INIT_SLEEP_SECONDS=5
ENV CONSUL_URL=localhost
ENV CONSUL_PORT=8500
ENV CONFIG_DIR=/config
ENV ENABLE_SPRING=true
ENV ENABLE_MICRONAUT=false

CMD /load-config.sh
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

[![Azure DevOps Build Status][azure-devops-image]][azure-devops-url-main] [![Build Status][travis-image]][travis-url] [![Docker Pulls](https://img.shields.io/docker/pulls/jhipster/consul-config-loader.svg)](https://hub.docker.com/r/jhipster/consul-config-loader/)

A small docker based tool to load Spring Boot property files into Consul K/V Store. It features hot-reload as well as filesystem and git support.
A small docker based tool to load Spring Boot and/or Micronaut property files into Consul K/V Store. It features hot-reload as well as filesystem and git support.

## Enabling Spring Boot and Micronaut support

Both Spring Boot and Micronaut frameworks are supported, and by default only Spring Boot is enabled.
To control the compatibility for each framework you should use the following environnement variables: `ENABLE_SPRING` and `ENABLE_MICRONAUT`, with values `true` or `false`.

## Filesystem mode

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ services:
#- CONFIG_MODE=git
- INIT_SLEEP_SECONDS=5
- CONSUL_URL=consul
- ENABLE_SPRING=true
- ENABLE_MICRONAUT=false
8 changes: 3 additions & 5 deletions load-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ sleep $INIT_SLEEP_SECONDS
echo "----------------------------------------------------------------------
Starting Consul Config Loader in $CONFIG_MODE mode"

function loadPropertiesFilesIntoConsul {
function loadPropertiesFilesIntoConsul {
for file in $CONFIG_DIR/*."${CONFIG_FORMAT:-yml}"
do
filename=$(basename $file)
app=${filename%.*}
curl --output /dev/null -sX PUT --data-binary @$file http://$CONSUL_URL:$CONSUL_PORT/v1/kv/config/$app/data
/upload-consul-file.sh $file
done
echo " Consul Config reloaded"
}
Expand All @@ -36,7 +34,7 @@ if [[ "$CONFIG_MODE" == "filesystem" ]]; then
loadPropertiesFilesIntoConsul

# Reload the files when there is a file change
simplywatch -g "$CONFIG_DIR/**" -x "curl --output /dev/null -sX PUT --data-binary @{{path}} http://$CONSUL_URL:$CONSUL_PORT/v1/kv/config/{{name}}/data && echo ' Consul Config reloaded'"
simplywatch -g "$CONFIG_DIR/**" -x "/upload-consul-file.sh {{path}}"

fi

Expand Down
14 changes: 14 additions & 0 deletions upload-consul-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

file="$1"
filename=$(basename $file)
app=${filename%.*}
if [[ "$ENABLE_SPRING" == "true" ]]; then
curl --output /dev/null -sX PUT --data-binary @$file http://$CONSUL_URL:$CONSUL_PORT/v1/kv/config/$app/data
echo " $file uploaded to Consul in Spring mode"
fi

if [[ "$ENABLE_MICRONAUT" == "true" ]]; then
curl --output /dev/null -sX PUT --data-binary @$file http://$CONSUL_URL:$CONSUL_PORT/v1/kv/config/$app
echo " $file uploaded to Consul in Micronaut mode"
fi

0 comments on commit dde1d77

Please sign in to comment.