From d30614a3c5ce9983de3b820260dcde48cf33cbde Mon Sep 17 00:00:00 2001 From: Quirino Zagarese Date: Wed, 19 Jun 2019 18:56:02 +0100 Subject: [PATCH 01/22] [ISSUE-10] Including container ip in service instance at discovery time Signed-off-by: qzagarese --- .../dockerunit/discovery/consul/ConsulDiscoveryProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java index ff66140..24e3ea4 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java @@ -84,7 +84,9 @@ private Service doDiscovery(Service s) { .map(si -> { InspectContainerResponse r = dockerClient.inspectContainerCmd(si.getContainerId()).exec(); return si.withPort(findPort(r, records).orElse(0)) - .withIp(DOCKER_HOST) + .withGatewayIp(DOCKER_HOST) + .withContainerName(r.getName()) + .withContainerIp(ContainerUtils.extractBridgeIpAddress(r.getNetworkSettings()).orElse("")) .withStatus(ServiceInstance.Status.DISCOVERED) .withStatusDetails("Discovered via consul"); }).collect(Collectors.toSet()); From 0ef3dcc3d698f647f29349d86de2bd99b0cb0290 Mon Sep 17 00:00:00 2001 From: Quirino Zagarese Date: Thu, 11 Jul 2019 12:56:23 +0100 Subject: [PATCH 02/22] [ISSUE-10] Removing getIp and introducing getContainerPort and getGatewayPort for service instances Signed-off-by: qzagarese --- .../dockerunit/discovery/consul/ConsulDiscoveryProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java index 24e3ea4..e9518b5 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProvider.java @@ -83,8 +83,9 @@ private Service doDiscovery(Service s) { Set withPorts = s.getInstances().stream() .map(si -> { InspectContainerResponse r = dockerClient.inspectContainerCmd(si.getContainerId()).exec(); - return si.withPort(findPort(r, records).orElse(0)) - .withGatewayIp(DOCKER_HOST) + return si.withGatewayPort(findPort(r, records).orElse(0)) + .withContainerPort(records.stream().findFirst().map(sr -> sr.getPort()).orElse(0)) + .withGatewayAddress(DOCKER_HOST) .withContainerName(r.getName()) .withContainerIp(ContainerUtils.extractBridgeIpAddress(r.getNetworkSettings()).orElse("")) .withStatus(ServiceInstance.Status.DISCOVERED) From 0c0bbb5fce0592ff3083c3084918c7d2c9ab96ad Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:51:46 +0100 Subject: [PATCH 03/22] Remove markdown extension from license file Signed-off-by: pnsantos Signed-off-by: qzagarese --- LICENSE.md => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE.md => LICENSE (100%) diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE From 69d7fe29dc537f0779d2d404c7ec895c1bcbfcbc Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:52:35 +0100 Subject: [PATCH 04/22] Remove from .gitignore stuff that belongs in gitignore_global Signed-off-by: pnsantos Signed-off-by: qzagarese --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8360da6..2f7896d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -.settings/ -.classpath -.project target/ From 593601261b62caca4fb4f49720203d36b9982c0d Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:53:19 +0100 Subject: [PATCH 05/22] Tidy up pom.xml - Move a couple of section to parent pom (inherited) - Inherit the parent pom version and groupId - Add jacoco and surefire to build (still no tests though) - Bump lombok to 1.18.3 - Add snapshot repo (so checkout+build requires no config) Signed-off-by: pnsantos Signed-off-by: qzagarese --- pom.xml | 131 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 43 deletions(-) diff --git a/pom.xml b/pom.xml index 6c6d2bd..c1b4721 100644 --- a/pom.xml +++ b/pom.xml @@ -1,83 +1,128 @@ - + + + 4.0.0 com.github.dockerunit dockerunit-parent - 2.0.0-SNAPSHOT + 0.1.0-SNAPSHOT + dockerunit-consul - 2.0.0-SNAPSHOT - dockerunit-consul Java Framework for testing of dockerised applications and services. Consul based service discovery package. https://github.com/dockerunit/dockerunit-consul - - - - Quirino Zagarese - - - Pedro Nuno Santos - - - Vincenzo Candela - - - Francesco Sorice - - + + + scm:https://github.com/dockerunit/dockerunit-consul.git + scm:https://github.com/dockerunit/dockerunit-consul.git + https://github.com/dockerunit/dockerunit-consul.git + + - 2.0.0-SNAPSHOT - 1.16.6 + 1.18.8 + 2.9.8 + 3.1.2 + 4.5.6 + 4.4.10 - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - + + + + com.fasterxml.jackson + jackson-bom + ${jackson.version} + import + pom + + + - - com.github.dockerunit - dockerunit-core - ${dockerunit.core.version} - org.projectlombok lombok ${lombok.version} provided + + ${project.groupId} + dockerunit-core + ${project.version} + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.github.docker-java + docker-java + ${docker-java.version} + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + commons-logging + commons-logging + + + + + org.slf4j + jcl-over-slf4j + runtime + + + + ossrh-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + maven-compiler-plugin - - org.sonatype.plugins - nexus-staging-maven-plugin + maven-surefire-plugin - - maven-source-plugin + org.jacoco + jacoco-maven-plugin - - maven-javadoc-plugin + maven-source-plugin - - maven-gpg-plugin + maven-javadoc-plugin - + From 25e3434c185b70f18230c9d836bece88ab5fa906 Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:54:16 +0100 Subject: [PATCH 06/22] Add lgtm config Signed-off-by: pnsantos Signed-off-by: qzagarese --- .lgtm.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .lgtm.yml diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 0000000..4ac96b1 --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,6 @@ +extraction: + java: + index: + java_version: 8 + maven: + version: 3.6.1 From 9b9ad9b9761ba753be698da08c40f6961303934d Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:54:37 +0100 Subject: [PATCH 07/22] Add BetterCodeHub config Signed-off-by: pnsantos Signed-off-by: qzagarese --- .bettercodehub.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .bettercodehub.yml diff --git a/.bettercodehub.yml b/.bettercodehub.yml new file mode 100644 index 0000000..dc42046 --- /dev/null +++ b/.bettercodehub.yml @@ -0,0 +1 @@ +component_depth: 9 From 4f9465e764a83bd31eff2eeea69c636f383201e1 Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:55:12 +0100 Subject: [PATCH 08/22] Add CircleCI config Signed-off-by: pnsantos Signed-off-by: qzagarese --- .circleci/config.yml | 95 ++++++++++++++++++ .circleci/mvn/codesigning.asc.enc | 157 ++++++++++++++++++++++++++++++ .circleci/mvn/settings.xml | 27 +++++ 3 files changed, 279 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .circleci/mvn/codesigning.asc.enc create mode 100644 .circleci/mvn/settings.xml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..cef158e --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,95 @@ +version: 2.1 + +# ----------------------------------------------------------------------------- +# YAML Anchors +# ----------------------------------------------------------------------------- + +_anchors: + - &mvn-cache-key consul-{{ .Branch }}-{{ checksum "pom.xml" }} + - &mvn-cache-key-fallback consul-{{ .Branch }} + + - &build-image circleci/openjdk:8u212-jdk-stretch + + - &default-env + MAVEN_CONFIG_DIR: .circleci/mvn + +# ----------------------------------------------------------------------------- +# Jobs +# ----------------------------------------------------------------------------- + +jobs: + + # jobs: build --------------------------------------------------------------- + + build: + docker: [ image: *build-image ] + steps: + - checkout + + - restore_cache: + keys: [ *mvn-cache-key, *mvn-cache-key-fallback ] + + - run: mvn verify + + - save_cache: + paths: [ ~/.m2 ] + key: *mvn-cache-key + + # jobs: deploy -------------------------------------------------------------- + + deploy: + docker: [ image: *build-image ] + steps: + - checkout + + - run: + name: Install GPG signing keys + environment: + <<: *default-env + GPG_KEY_FILENAME: codesigning.asc + command: | + openssl aes-256-cbc -d -a -in ${MAVEN_CONFIG_DIR}/${GPG_KEY_FILENAME}.enc -out ${MAVEN_CONFIG_DIR}/${GPG_KEY_FILENAME} -k "${ENCRYPTION_KEY}" + gpg --batch --fast-import ${MAVEN_CONFIG_DIR}/${GPG_KEY_FILENAME} + + - restore_cache: + keys: [ *mvn-cache-key, *mvn-cache-key-fallback ] + + - run: + name: mvn deploy + environment: + <<: *default-env + command: | + export GPG_TTY=$(tty) + mvn -B -s ${MAVEN_CONFIG_DIR}/settings.xml -Dstyle.color=always -Dmaven.install.skip deploy + + - save_cache: + paths: [ ~/.m2 ] + key: *mvn-cache-key + + +# ----------------------------------------------------------------------------- +# Workflows +# ----------------------------------------------------------------------------- + +workflows: + + version: 2 + + # workflow: pr-check -------------------------------------------------------- + + pr-check: + jobs: + - build: + filters: + branches: + ignore: master + + # workflow: master ---------------------------------------------------------- + + deploy: + jobs: + - deploy: + context: ossrh + filters: + branches: + only: master diff --git a/.circleci/mvn/codesigning.asc.enc b/.circleci/mvn/codesigning.asc.enc new file mode 100644 index 0000000..13b708f --- /dev/null +++ b/.circleci/mvn/codesigning.asc.enc @@ -0,0 +1,157 @@ +U2FsdGVkX1+EK2vrfSJT1SclixeJ66fh3z/l7wH/CFhlP1k1HSFMm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M8gBMSb/F9iBzDeWkaSmPnsD +oW3SFzK3Mn6bvc3aQXiHELZZol4fYUkG1xYcmZqMhhmu3ztTwcQduXFNl7s1tweR +70gLJ4G2px2gJKPx2lrZz+lpFUPIaANs0DO4UE6FCZfmeItfzGCbUduL8jEu/Qxt +qR4arzYckCmSCXmermHymJMNRhFP0oI1p2TDhi2zjWlbhADMForjNdrH/9UzYf9Y +xTGGnqXc2L2H3/QIjtdbvtGKpLuDYfGyBTCZvYxKr+/mdAirugZCFSe9H2vyx3iP +Aq823zbZbjZKW6fyJ/MFYhRGc88SCmJBkcWVA29pmDC5n8kTaV8iP8d5NqEoqqZj +GUH3n55rd1cL/QCXdFPCb3GrXzzsW25b1r49nc8YeMYd/Xp4RpXWAMPTf6fQGv8Z +03F7chDa4dM5ZhUI1dhfDxO8TpVyMrJ7B2EYs9ypQkcbHOKwrKZXVJ0mzsmkrrdB +G9rc47T7l3pBDJJOXkPKoEyhtnA/RBqRfb8ijFF7F30= diff --git a/.circleci/mvn/settings.xml b/.circleci/mvn/settings.xml new file mode 100644 index 0000000..99cc307 --- /dev/null +++ b/.circleci/mvn/settings.xml @@ -0,0 +1,27 @@ + + + + + + ossrh + ${env.OSSRH_USERNAME} + ${env.OSSRH_PASSWORD} + + + + + + ossrh + + true + + + gpg + ${env.GPG_KEYNAME} + ${env.GPG_PASSPHRASE} + + + + + From c50d8091df611244f8047c8825e22b423cf2923d Mon Sep 17 00:00:00 2001 From: pnsantos Date: Fri, 12 Jul 2019 22:55:30 +0100 Subject: [PATCH 09/22] Add several badges to README.md Signed-off-by: pnsantos Signed-off-by: qzagarese --- README.md | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1a88529..3841644 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,29 @@ -dockerunit-consul - A Consul based discovery provider for Dockerunit -=========================================================================== +[![CircleCI](https://img.shields.io/circleci/build/gh/dockerunit/dockerunit-consul/master.svg?style=flat)](https://circleci.com/gh/dockerunit/dockerunit-consul/tree/master) +  +[![Codacy](https://img.shields.io/codacy/coverage/22445615da7d47e8b50e17f937ca9b49.svg?style=flat)](https://app.codacy.com/project/dockerunit/dockerunit-consul/dashboard) +  +[![Coverity](https://img.shields.io/coverity/scan/18572.svg?style=flat)](https://scan.coverity.com/projects/dockerunit-dockerunit-consul) +  +[![License](https://img.shields.io/github/license/dockerunit/dockerunit-consul.svg?style=flat)](https://choosealicense.com/licenses/apache-2.0/) + +[![Codacy](https://img.shields.io/codacy/grade/22445615da7d47e8b50e17f937ca9b49.svg?style=flat&label=codacy)](https://app.codacy.com/project/dockerunit/dockerunit-consul/dashboard) +  +[![BetterCodeHub](https://bettercodehub.com/edge/badge/dockerunit/dockerunit-consul?branch=master)](https://bettercodehub.com/) +  +[![LGTM](https://img.shields.io/lgtm/grade/java/github/dockerunit/dockerunit-consul.svg?style=flat&label=lgtm)](https://lgtm.com/projects/g/dockerunit/dockerunit-consul/context:java) +  +[![LGTM](https://img.shields.io/lgtm/alerts/github/dockerunit/dockerunit-consul.svg?style=flat&label=lgtm)](https://lgtm.com/projects/g/dockerunit/dockerunit-consul/alerts) + +[![Maven](https://img.shields.io/maven-central/v/com.github.dockerunit/dockerunit-consul.svg?style=flat)](https://search.maven.org/search?q=g:com.github.dockerunit%20AND%20a:dockerunit-consul&core=gav) +  +[![Javadoc](https://javadoc.io/badge/com.github.dockerunit/dockerunit-consul.svg)](https://www.javadoc.io/doc/com.github.dockerunit/dockerunit-consul) +  +[![Nexus](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.github.dockerunit/dockerunit-consul.svg?style=flat)](https://oss.sonatype.org/index.html#nexus-search;gav~com.github.dockerunit~dockerunit-consul~~~) + +[![Discord](https://img.shields.io/discord/587583543081959435.svg?style=flat)](https://discordapp.com/channels/587583543081959435/587583543081959437) This module allows you to configure the discovery phase for the testing of your services. -Service Discovery is necessary for dockerunit to start and for your tests to execute successfully. +Service Discovery is necessary for dockerunit to start and for your tests to execute successfully. Usage (set `dockerunit.consul.version` property to the version you intend to use): ```xml @@ -17,12 +38,12 @@ Usage (set `dockerunit.consul.version` property to the version you intend to use Discovery configuration can be specified by means of the following Java annotations: -- `@TCPHealthCheck`: A basic health-check that probes your container to check if it's +- `@TCPHealthCheck`: A basic health-check that probes your container to check if it's able to accept TCP connections. -- `@WebHealthCheck`: Health-check for HTTP/HTTPS services. Consul will consider the health-check as passing only +- `@WebHealthCheck`: Health-check for HTTP/HTTPS services. Consul will consider the health-check as passing only when it returns a 200 HTTP status code. -- `@UseConsulDns`: Injects the Consul container IP as a DNS server for your container(s). This allows -your services to reference other services by using their `dockerunit name`, which is the value +- `@UseConsulDns`: Injects the Consul container IP as a DNS server for your container(s). This allows +your services to reference other services by using their `dockerunit name`, which is the value that you have set in the corresponding `@Named` annotation. The last annotation can be better explained with an example. @@ -30,7 +51,7 @@ The last annotation can be better explained with an example. Say you have two services: `service-a` and `service-b`. Our test only talks to `service-a` which is a client of `service-b`. Both services listen on port `8080`. - + Hereafter the dockerunit descriptors for the two services: ```java @@ -46,8 +67,8 @@ public class DescriptorForA{} @WebHealthCheck(port=8080) public class DescriptorForB{} ``` -- Because `service-a` is using `@UseConsulDns`, it can reference `service-b` +- Because `service-a` is using `@UseConsulDns`, it can reference `service-b` by using the `service-b.service.consul` name. - `service-b` is not declaring any `@PortBinding` because our test does not need to talk to it. -Only `service-a` will talk to it, but it can do it by using the container IP to which -the `service-b.service.consul` name resolves to. +Only `service-a` will talk to it, but it can do it by using the container IP to which +the `service-b.service.consul` name resolves to. From 4b0c9fd093af88903c0009b0440e08f4896450dd Mon Sep 17 00:00:00 2001 From: pnsantos Date: Mon, 15 Jul 2019 22:41:50 +0100 Subject: [PATCH 10/22] Include all XML files in LGTM analysis Signed-off-by: pnsantos Signed-off-by: qzagarese --- .lgtm.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.lgtm.yml b/.lgtm.yml index 4ac96b1..21c370a 100644 --- a/.lgtm.yml +++ b/.lgtm.yml @@ -2,5 +2,6 @@ extraction: java: index: java_version: 8 + xml_mode: ALL maven: version: 3.6.1 From 6d710fb1e23962bc18b21d138659b544094fa6da Mon Sep 17 00:00:00 2001 From: fsorice Date: Tue, 16 Jul 2019 17:36:37 +0100 Subject: [PATCH 11/22] Fix lombok-jackson serialization for ServiceRecord - In the version of lombok 1.16.18 there was an annotation that was used on the created ctors that is @ConstructorProperties. This annotation was used by jackson for serializating correctly the object, but in the new version of lombok, that is 1.18.8 that was not generated anymore. For this reason the serialization of the object ServiceRecord, without an empty ctor, was failing. Thanks to Iker that spotted that during the tests! Signed-off-by: fsorice Signed-off-by: qzagarese --- pom.xml | 2 +- .../discovery/consul/ServiceRecord.java | 130 +++++++++--------- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/pom.xml b/pom.xml index c1b4721..0873b28 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 1.18.8 2.9.8 - 3.1.2 + 3.1.3 4.5.6 4.4.10 diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java b/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java index ab33c93..e6dbc4b 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java @@ -5,77 +5,81 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.experimental.Wither; @Wither @Getter @AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PRIVATE) @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceRecord { - @JsonProperty("ServiceName") - private final String name; - - @JsonProperty("Address") - private final String address; - - @JsonProperty("ServicePort") - private final int port; - - @JsonProperty("ServiceAddress") - private String serviceAddress; - - @JsonProperty("Service") - private final Service service; - - @JsonProperty("Checks") - private final List checks; - - - public String getName() { - return service != null ? service.getName() : name; - } - - public String getAddress() { - return service != null ? service.getAddress() : address; - } - - public int getPort() { - return service != null ? service.getPort() : port; - } - - @Wither - @Getter - @AllArgsConstructor - @JsonIgnoreProperties(ignoreUnknown = true) - public static class Service { - - @JsonProperty("Service") - private final String name; - - @JsonProperty("Address") - private final String address; - - @JsonProperty("Port") - private final int port; - - } - - @Wither - @Getter - @AllArgsConstructor - @JsonIgnoreProperties(ignoreUnknown = true) - public static class Check { - - public static final String PASSING = "passing"; - - @JsonProperty("Name") - private final String name; - - @JsonProperty("Status") - private final String status; - - } + @JsonProperty("ServiceName") + private String name; + + @JsonProperty("Address") + private String address; + + @JsonProperty("ServicePort") + private int port; + + @JsonProperty("ServiceAddress") + private String serviceAddress; + + @JsonProperty("Service") + private Service service; + + @JsonProperty("Checks") + private List checks; + + public String getName() { + return service != null ? service.getName() : name; + } + + public String getAddress() { + return service != null ? service.getAddress() : address; + } + + public int getPort() { + return service != null ? service.getPort() : port; + } + + @Wither + @Getter + @AllArgsConstructor + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Service { + + @JsonProperty("Service") + private String name; + + @JsonProperty("Address") + private String address; + + @JsonProperty("Port") + private int port; + + } + + @Wither + @Getter + @AllArgsConstructor + @NoArgsConstructor(access = AccessLevel.PRIVATE) + @JsonIgnoreProperties(ignoreUnknown = true) + public static class Check { + + public static final String PASSING = "passing"; + + @JsonProperty("Name") + private String name; + + @JsonProperty("Status") + private String status; + + } } From ada4bdb81a7dff22e09cf365cbc2373a5e72aacb Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2019 09:06:59 +0000 Subject: [PATCH 12/22] Bump docker-java from 3.1.3 to 3.1.5 Bumps [docker-java](https://github.com/docker-java/docker-java) from 3.1.3 to 3.1.5. - [Release notes](https://github.com/docker-java/docker-java/releases) - [Changelog](https://github.com/docker-java/docker-java/blob/master/CHANGELOG.md) - [Commits](https://github.com/docker-java/docker-java/compare/3.1.3...3.1.5) Signed-off-by: dependabot-preview[bot] Signed-off-by: qzagarese --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0873b28..1442107 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 1.18.8 2.9.8 - 3.1.3 + 3.1.5 4.5.6 4.4.10 From 7385b517750e1748c0a2725328980cfebdb472f8 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2019 22:57:00 +0000 Subject: [PATCH 13/22] Bump httpcore from 4.4.10 to 4.4.11 Bumps httpcore from 4.4.10 to 4.4.11. Signed-off-by: dependabot-preview[bot] Signed-off-by: qzagarese --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1442107..f8e46c9 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 2.9.8 3.1.5 4.5.6 - 4.4.10 + 4.4.11 From 658126cf4fcb8fe0e93c79912b20c3025a0c3f37 Mon Sep 17 00:00:00 2001 From: Francesco Sorice Date: Thu, 23 Jan 2020 12:18:34 +0000 Subject: [PATCH 14/22] Remove snapshot from dockerunit current version Signed-off-by: fsorice Signed-off-by: qzagarese --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f8e46c9..17d413c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.github.dockerunit dockerunit-parent - 0.1.0-SNAPSHOT + 0.1.0 From f4554c9b7edf9b3a46bc727fcf2f594273e1b02c Mon Sep 17 00:00:00 2001 From: qzagarese Date: Wed, 5 Feb 2020 10:17:42 +0000 Subject: [PATCH 15/22] Fixing README and bumping to 0.2.0-SNAPSHOT Signed-off-by: qzagarese --- README.md | 11 +++++------ pom.xml | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3841644..3e16790 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Usage (set `dockerunit.consul.version` property to the version you intend to use com.github.dockerunit dockerunit-consul - ${dockerunit.consul.version} + ${dockerunit.version} test ``` @@ -44,7 +44,7 @@ able to accept TCP connections. when it returns a 200 HTTP status code. - `@UseConsulDns`: Injects the Consul container IP as a DNS server for your container(s). This allows your services to reference other services by using their `dockerunit name`, which is the value -that you have set in the corresponding `@Named` annotation. +that you have set in the corresponding `@Svc` annotation. The last annotation can be better explained with an example. @@ -55,10 +55,9 @@ Both services listen on port `8080`. Hereafter the dockerunit descriptors for the two services: ```java -@Named("service-a") -@Image("service-a-image") +@Svc(name="service-a", image="service-a-image") @WebHealthCheck(port=8080) -@PortBinding(exposedPort=8080, hostPort=8080) +@PublishPort(host=8080, container=8080) @UseConsulDns public class DescriptorForA{} @@ -69,6 +68,6 @@ public class DescriptorForB{} ``` - Because `service-a` is using `@UseConsulDns`, it can reference `service-b` by using the `service-b.service.consul` name. -- `service-b` is not declaring any `@PortBinding` because our test does not need to talk to it. +- `service-b` is not declaring any `@PublishPort` because our test does not need to talk to it. Only `service-a` will talk to it, but it can do it by using the container IP to which the `service-b.service.consul` name resolves to. diff --git a/pom.xml b/pom.xml index 17d413c..2ad7eb8 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.github.dockerunit dockerunit-parent - 0.1.0 + 0.2.0-SNAPSHOT From 1b56bf589f755c185f1a4f8bcbb84317bec91bca Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2020 05:28:43 +0000 Subject: [PATCH 16/22] Bump lombok from 1.18.8 to 1.18.16 Bumps [lombok](https://github.com/rzwitserloot/lombok) from 1.18.8 to 1.18.16. - [Release notes](https://github.com/rzwitserloot/lombok/releases) - [Changelog](https://github.com/rzwitserloot/lombok/blob/master/doc/changelog.markdown) - [Commits](https://github.com/rzwitserloot/lombok/compare/v1.18.8...v1.18.16) Signed-off-by: dependabot-preview[bot] Signed-off-by: qzagarese --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ad7eb8..1629f6d 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ - 1.18.8 + 1.18.16 2.9.8 3.1.5 4.5.6 From f24378c6bcc0a152bffd5e9efa3cf1a82c52a9a8 Mon Sep 17 00:00:00 2001 From: pnsantos Date: Wed, 11 Nov 2020 12:17:04 +0000 Subject: [PATCH 17/22] Use next-gen circle ci openjdk image Signed-off-by: pnsantos Signed-off-by: qzagarese --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cef158e..d3dd412 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ _anchors: - &mvn-cache-key consul-{{ .Branch }}-{{ checksum "pom.xml" }} - &mvn-cache-key-fallback consul-{{ .Branch }} - - &build-image circleci/openjdk:8u212-jdk-stretch + - &build-image cimg/openjdk:8.0 - &default-env MAVEN_CONFIG_DIR: .circleci/mvn From 046f7ccee5bd233ec1d573042207c7d34214f1e1 Mon Sep 17 00:00:00 2001 From: fsorice Date: Wed, 11 Nov 2020 15:39:50 +0000 Subject: [PATCH 18/22] Minor formatting refactory Signed-off-by: qzagarese --- .../ConsulDiscoveryProviderFactory.java | 8 ++-- .../discovery/consul/ConsulRegistrator.java | 34 +++++++------- .../consul/ConsulServiceFactory.java | 47 +++++++++++-------- .../discovery/consul/ContainerTracker.java | 30 ++++++++---- .../discovery/consul/ContainerUtils.java | 21 +++++---- .../discovery/consul/ServiceRecord.java | 9 ++-- 6 files changed, 84 insertions(+), 65 deletions(-) diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProviderFactory.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProviderFactory.java index 3a3b992..6e65c70 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProviderFactory.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryProviderFactory.java @@ -5,9 +5,9 @@ public class ConsulDiscoveryProviderFactory implements DiscoveryProviderFactory { - @Override - public DiscoveryProvider getProvider() { - return new ConsulDiscoveryProvider(); - } + @Override + public DiscoveryProvider getProvider() { + return new ConsulDiscoveryProvider(); + } } diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulRegistrator.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulRegistrator.java index 1215496..3d21230 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulRegistrator.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulRegistrator.java @@ -1,27 +1,24 @@ package com.github.dockerunit.discovery.consul; +import java.io.UnsupportedEncodingException; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.logging.Logger; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.model.Container; import org.apache.http.HttpResponse; -import org.apache.http.NoHttpResponseException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPut; -import org.apache.http.conn.HttpHostConnectException; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Consumer; -import java.util.function.Supplier; -import java.util.logging.Logger; - public class ConsulRegistrator { public static final String ACCEPT = "Accept"; @@ -41,7 +38,6 @@ public class ConsulRegistrator { private final ObjectWriter objectWriter; private final ConsulServiceFactory svcFactory; - public ConsulRegistrator(DockerClient client, int pollingPeriod, String consulHost, int consulPort) { this.client = client; this.pollingPeriod = pollingPeriod; @@ -65,7 +61,7 @@ private void onDetectHook(Container container) { } private void onDestroyHook(Container container) { - if(container != null && services.containsKey(container.getId())) { + if (container != null && services.containsKey(container.getId())) { deregisterSvc(services.get(container.getId())); trackers.remove(container.getId()); services.remove(container.getId()); @@ -77,7 +73,7 @@ private void registerSvc(ConsulService svc) { try { executePut("/v1/agent/service/register", objectWriter.writeValueAsString(svc), errorMessage, - ex -> { + ex -> { throw new RuntimeException(errorMessage.get(), ex); }); } catch (JsonProcessingException e) { @@ -86,18 +82,22 @@ private void registerSvc(ConsulService svc) { } private void deregisterSvc(ConsulService svc) { - Supplier errorMessage = () ->"Could not deregister container " + svc.getContainerId() + " from Consul."; + Supplier errorMessage = () -> "Could not deregister container " + svc.getContainerId() + + " from Consul."; executePut("/v1/agent/service/deregister/" + svc.getId(), null, errorMessage, ex -> logger.info("Consul has already stopped. Service de-registration aborted.")); } - private void executePut(String endpoint, String body, Supplier errorMessage, Consumer onFailure) { + private void executePut(String endpoint, + String body, + Supplier errorMessage, + Consumer onFailure) { HttpPut put = new HttpPut("http://" + host + ":" + port + endpoint); put.setHeader(ACCEPT, APPLICATION_JSON); put.setHeader(CONTENT_TYPE, APPLICATION_JSON); - if(body != null) { + if (body != null) { try { put.setEntity(new StringEntity(body)); } catch (UnsupportedEncodingException e) { diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulServiceFactory.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulServiceFactory.java index 8b80ba1..fbfc1cc 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulServiceFactory.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulServiceFactory.java @@ -1,18 +1,19 @@ package com.github.dockerunit.discovery.consul; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.command.InspectContainerResponse; -import com.github.dockerunit.discovery.consul.annotation.TCPHealthCheck; -import com.github.dockerunit.discovery.consul.annotation.WebHealthCheck; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.command.InspectContainerResponse; +import com.github.dockerunit.discovery.consul.annotation.TCPHealthCheck; +import com.github.dockerunit.discovery.consul.annotation.WebHealthCheck; + public class ConsulServiceFactory { private static final String SERVICE_NAME_PREFIX = "SERVICE_"; @@ -21,7 +22,8 @@ public class ConsulServiceFactory { + "health-check by using @" + WebHealthCheck.class.getSimpleName() + " or @" + TCPHealthCheck.class.getSimpleName(); - private static final String SVC_HEALTH_CHECK_PORT_NOT_FOUND_MSG = "No health-check port definition detected" + DEFINE_HEALTH_CHECK_MSG; + private static final String SVC_HEALTH_CHECK_PORT_NOT_FOUND_MSG = + "No health-check port definition detected" + DEFINE_HEALTH_CHECK_MSG; private static final String SVC_NAME_NOT_FOUND_ERROR_MSG = "No svc name detected. " + DEFINE_HEALTH_CHECK_MSG; private static final String DOCKERUNIT = "dockerunit"; @@ -42,13 +44,19 @@ public ConsulService createSvc(String containerId) { InspectContainerResponse r = client.inspectContainerCmd(containerId).exec(); Map options = buildKeyValueMap(r.getConfig().getLabels(), r.getConfig().getEnv()); - String svcName = null; + + String svcName; try { - svcName = URLEncoder.encode(findName(options).orElseThrow(() -> new RuntimeException(SVC_NAME_NOT_FOUND_ERROR_MSG)), "UTF-8"); + svcName = URLEncoder.encode( + findName(options).orElseThrow(() -> new RuntimeException(SVC_NAME_NOT_FOUND_ERROR_MSG)), + StandardCharsets.UTF_8.name() + ); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Invalid svc name detected.", e); } - Integer port = extractHealthCheckPort(options).orElseThrow(() -> new RuntimeException(SVC_HEALTH_CHECK_PORT_NOT_FOUND_MSG)); + + Integer port = extractHealthCheckPort(options) + .orElseThrow(() -> new RuntimeException(SVC_HEALTH_CHECK_PORT_NOT_FOUND_MSG)); String address = ContainerUtils.extractBridgeIpAddress(r.getNetworkSettings()) .orElseThrow(() -> new RuntimeException(SVC_ADDRESS_NOT_FOUND_ERROR_MSG)); @@ -63,10 +71,10 @@ public ConsulService createSvc(String containerId) { } private Map buildKeyValueMap(Map labels, String[] env) { - if(env == null) { + if (env == null) { return labels != null ? labels : new HashMap<>(); } - if(labels == null) { + if (labels == null) { return new HashMap<>(); } Map keyValueMap = labels.entrySet() @@ -83,8 +91,9 @@ private ConsulService.ConsulCheck buildCheck(Map options, String ConsulService.ConsulCheck.ConsulCheckBuilder builder = ConsulService.ConsulCheck.builder(); builder.interval(options.get(SERVICE_CHECK_INTERVAL)); builder.http(interpolateCheckScript( - options.getOrDefault(SERVICE_CHECK_HTTP, null), address, port)); - builder.tcp(interpolateCheckScript(options.getOrDefault(SERVICE_CHECK_TCP, null), address,port)); + options.getOrDefault(SERVICE_CHECK_HTTP, null), address, port) + ); + builder.tcp(interpolateCheckScript(options.getOrDefault(SERVICE_CHECK_TCP, null), address, port)); builder.method(options.getOrDefault(SERVICE_CHECK_METHOD, null)); builder.tlsSkipVerify(true); builder.status(options.getOrDefault(SERVICE_CHECK_INITIAL_STATUS, null)); @@ -99,10 +108,10 @@ private String interpolateCheckScript(String script, String address, Integer por private Optional extractHealthCheckPort(Map options) { return options.entrySet().stream() - .filter(kv -> hasServiceName(kv)) + .filter(this::hasServiceName) .findFirst() .map(kv -> extractPortString(kv.getKey())) - .map(port -> asInteger(port)); + .map(this::asInteger); } private Integer asInteger(String port) { @@ -115,9 +124,9 @@ private Integer asInteger(String port) { private Optional findName(Map options) { return options.entrySet().stream() - .filter(kv -> hasServiceName(kv)) - .findFirst() - .map(kv -> kv.getValue()); + .filter(this::hasServiceName) + .findFirst() + .map(Map.Entry::getValue); } private boolean hasServiceName(Map.Entry kv) { @@ -126,7 +135,7 @@ private boolean hasServiceName(Map.Entry kv) { } private String extractPortString(String s) { - if (! (s.lastIndexOf("_") > (s.indexOf("_") + 1))) { + if (!(s.lastIndexOf("_") > (s.indexOf("_") + 1))) { return null; } return s.substring(s.indexOf("_") + 1, s.lastIndexOf("_")); diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ContainerTracker.java b/src/main/java/com/github/dockerunit/discovery/consul/ContainerTracker.java index a58f877..c4948cc 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ContainerTracker.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ContainerTracker.java @@ -1,15 +1,15 @@ package com.github.dockerunit.discovery.consul; -import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.model.Container; - -import java.util.Arrays; +import java.util.Collections; import java.util.Optional; import java.util.Timer; import java.util.TimerTask; import java.util.function.Consumer; import java.util.logging.Logger; +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.api.model.Container; + public class ContainerTracker { private static final Logger logger = Logger.getLogger(ContainerTracker.class.getSimpleName()); @@ -17,11 +17,19 @@ public class ContainerTracker { private final DockerClient client; private final String containerId; private final int pollingPeriod; + private final Consumer onDetect; private final Consumer onDestroy; + private Container latestContainer; - public ContainerTracker(DockerClient client, String containerId, int pollingPeriod, Consumer onDetect, Consumer onDestroy) { + public ContainerTracker( + DockerClient client, + String containerId, + int pollingPeriod, + Consumer onDetect, + Consumer onDestroy + ) { this.client = client; this.containerId = containerId; this.pollingPeriod = pollingPeriod; @@ -37,22 +45,24 @@ public ContainerTracker(DockerClient client, String containerId, int pollingPeri } private void init() { - latestContainer = findContainer().orElseThrow(() -> new RuntimeException("Could not detect container with id: " + containerId)); + latestContainer = findContainer().orElseThrow(() -> new RuntimeException( + "Could not detect container with id: " + containerId)); onDetect.accept(latestContainer); track(); } private Optional findContainer() { - return client.listContainersCmd().withIdFilter(Arrays.asList(containerId)).exec() - .stream() - .findFirst(); + return client.listContainersCmd().withIdFilter(Collections.singletonList(containerId)).exec() + .stream() + .findFirst(); } private void track() { TimerTask repeatedTask = new TimerTask() { public void run() { try { - latestContainer = findContainer().orElseThrow(() -> new RuntimeException("Container " + containerId + " has been removed.")); + latestContainer = findContainer() + .orElseThrow(() -> new RuntimeException("Container " + containerId + " has been removed.")); } catch (Exception e) { this.cancel(); onDestroy.accept(latestContainer); diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ContainerUtils.java b/src/main/java/com/github/dockerunit/discovery/consul/ContainerUtils.java index f59fe35..bcb991d 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ContainerUtils.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ContainerUtils.java @@ -1,20 +1,22 @@ package com.github.dockerunit.discovery.consul; +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; + import com.github.dockerjava.api.model.Container; import com.github.dockerjava.api.model.ContainerNetwork; import com.github.dockerjava.api.model.ContainerNetworkSettings; import com.github.dockerjava.api.model.NetworkSettings; import com.github.dockerunit.core.internal.docker.DefaultDockerClientProvider; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; -import java.util.Arrays; -import java.util.Map; -import java.util.Optional; - +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class ContainerUtils { private static final com.github.dockerjava.api.DockerClient dockerClient = new DefaultDockerClientProvider().getClient(); - public static Optional extractBridgeIpAddress(ContainerNetworkSettings settings) { return extractIp(settings.getNetworks()); } @@ -29,22 +31,20 @@ public static Optional extractMappedPort(int port, NetworkSettings netw .map(Map.Entry::getValue) .filter(bindings -> bindings != null && bindings.length > 0) .findFirst() - .flatMap(bindings -> parsePort(bindings[0].getHostPortSpec())); + .flatMap(bindings -> parsePort(bindings[0].getHostPortSpec())); } public static Container getConsulContainer() { return dockerClient.listContainersCmd().exec().stream() - .filter(c -> isConsul(c)) + .filter(ContainerUtils::isConsul) .findFirst() .orElseThrow(() -> new RuntimeException(("Could not detect the Consul container."))); } - private static boolean isConsul(Container c) { - return Arrays.stream(c.getNames()).anyMatch(s -> s.equals("/" + ConsulDiscoveryConfig.CONSUL_CONTAINER_NAME)); + return Arrays.asList(c.getNames()).contains("/" + ConsulDiscoveryConfig.CONSUL_CONTAINER_NAME); } - private static Optional extractIp(Map networks) { return Optional.ofNullable(networks.entrySet().stream() .filter(network -> "bridge".equals(network.getKey())) @@ -61,4 +61,5 @@ private static Optional parsePort(String s) { return Optional.empty(); } } + } diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java b/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java index e6dbc4b..712d020 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ServiceRecord.java @@ -4,14 +4,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.experimental.Wither; +import lombok.With; -@Wither +@With @Getter @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -48,7 +47,7 @@ public int getPort() { return service != null ? service.getPort() : port; } - @Wither + @With @Getter @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -66,7 +65,7 @@ public static class Service { } - @Wither + @With @Getter @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PRIVATE) From 71dede29bae1077405edaf8fc43ffd58a57881c2 Mon Sep 17 00:00:00 2001 From: fsorice Date: Wed, 11 Nov 2020 15:42:02 +0000 Subject: [PATCH 19/22] Update POM dependencies and bump module version - Updated lombok, http-core, and jackson dependencies; - Bumped the version of the module to `0.1.1`. Signed-off-by: qzagarese --- CHANGELOG.md | 24 ++++++++++++++---------- README.md | 4 ++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f61f3d1..75e1511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,19 @@ and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0 ## Unreleased + +## 0.1.1 [11 Nov 2020] + +### Changed + +- Bumped `lombok` to version `1.8.16`; +- Bumped `jackson` to version `2.11.3`; +- Bumped `httpcore` to version `4.4.13`; +- Introduced new system property called `consul.image` for overriding the default DockerHub Consul image; +- Minor formatting changes. + +## 0.1.0 [01 Mar 2019] + ### Changed - Bump docker-java to 3.1.1 @@ -19,13 +32,4 @@ and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0 - Goodbye to gliderlabs/registrator - Goodbye to `qzagarese` in package names :-) - -## 1.0.1 [01 Mar 2019] - -### Added - -- New boolean flag `-Dconsul.dns.enabled` to disable consul DNS (fixes [#12](https://github.com/qzagarese/dockerunit/issues/12)) - -## 1.0.0 [06 Feb 2019] - -_Initial Release_ +- New boolean flag `-Dconsul.dns.enabled` to disable Consul DNS (fixes [#12](https://github.com/qzagarese/dockerunit/issues/12)) diff --git a/README.md b/README.md index 3e16790..04ffc63 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,7 @@ by using the `service-b.service.consul` name. - `service-b` is not declaring any `@PublishPort` because our test does not need to talk to it. Only `service-a` will talk to it, but it can do it by using the container IP to which the `service-b.service.consul` name resolves to. + +--- +By default, the `dockerunit-consul` module uses Consul Docker image from DockerHub. +To override the default using a different Consul Docker image the System property `consul.image` can be provided. From 50585b22d707fe3488d1eb85f1c205b741a9ebed Mon Sep 17 00:00:00 2001 From: fsorice Date: Wed, 11 Nov 2020 15:43:13 +0000 Subject: [PATCH 20/22] Make consul image configurable using system property Signed-off-by: qzagarese --- CHANGELOG.md | 32 +++++++------ .../discovery/consul/ConsulDescriptor.java | 45 +++++++++++-------- .../consul/ConsulDiscoveryConfig.java | 31 +++++++------ 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e1511..d1a528b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,30 +6,28 @@ and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0 ## Unreleased - -## 0.1.1 [11 Nov 2020] +## 0.1.1 - (11 Nov 2020) ### Changed -- Bumped `lombok` to version `1.8.16`; -- Bumped `jackson` to version `2.11.3`; -- Bumped `httpcore` to version `4.4.13`; -- Introduced new system property called `consul.image` for overriding the default DockerHub Consul image; -- Minor formatting changes. + - Bumped `lombok` to version `1.8.16` + - Bumped `jackson` to version `2.11.3` + - Bumped `httpcore` to version `4.4.13` + - Introduced new system property called `consul.image` for overriding the default DockerHub Consul image + - Minor formatting changes -## 0.1.0 [01 Mar 2019] +## [0.1.0] - (01 Mar 2019) ### Changed -- Bump docker-java to 3.1.1 -- Rewritten discovery to utilise containers internal IPs and ports -- Renamed `@EnableConsul` to `@TCPHealthCheck` and its property `exposedPort` to `port` -- Renamed property `exposedPort` in `@WebHealthCheck` to `port` -- `@UseConsulDns` now sets the Consul container IP (instead of the Docker bridge one) as primary DNS for your containers and this makes it usable on MacOS - + - Bump docker-java to 3.1.1 + - Rewritten discovery to utilise containers internal IPs and ports + - Renamed `@EnableConsul` to `@TCPHealthCheck` and its property `exposedPort` to `port` + - Renamed property `exposedPort` in `@WebHealthCheck` to `port` + - `@UseConsulDns` now sets the Consul container IP (instead of the Docker bridge one) as primary DNS for your containers and this makes it usable on MacOS ### Removed -- Goodbye to gliderlabs/registrator -- Goodbye to `qzagarese` in package names :-) -- New boolean flag `-Dconsul.dns.enabled` to disable Consul DNS (fixes [#12](https://github.com/qzagarese/dockerunit/issues/12)) + - Goodbye to gliderlabs/registrator + - Goodbye to `qzagarese` in package names :-) + - New boolean flag `-Dconsul.dns.enabled` to disable Consul DNS (fixes [#12](https://github.com/qzagarese/dockerunit/issues/12)) diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDescriptor.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDescriptor.java index b42724e..70dea16 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDescriptor.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDescriptor.java @@ -1,5 +1,11 @@ package com.github.dockerunit.discovery.consul; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.logging.Logger; + import com.github.dockerjava.api.command.CreateContainerCmd; import com.github.dockerjava.api.model.ExposedPort; import com.github.dockerjava.api.model.HostConfig; @@ -9,42 +15,37 @@ import com.github.dockerunit.core.annotation.Svc; import com.github.dockerunit.discovery.consul.annotation.UseConsulDns; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Logger; - -import static com.github.dockerunit.discovery.consul.ConsulDiscoveryConfig.CONSUL_DNS_ENABLED_DEFAULT; -import static com.github.dockerunit.discovery.consul.ConsulDiscoveryConfig.CONSUL_DNS_ENABLED_PROPERTY; - -@Svc(name = "consul", image = "consul:1.4.4") +@Svc(name = "consul", image = "") public class ConsulDescriptor { + private static final Logger logger = Logger.getLogger(ConsulDescriptor.class.getSimpleName()); static final int CONSUL_DNS_PORT = 53; static final int CONSUL_PORT = 8500; - private static final Logger logger = Logger.getLogger(ConsulDescriptor.class.getSimpleName()); - - @ContainerBuilder public CreateContainerCmd setup(CreateContainerCmd cmd) { - List ports = new ArrayList<>(Arrays.asList(cmd.getExposedPorts())); + List ports = new ArrayList<>(Arrays.asList(Objects.requireNonNull(cmd.getExposedPorts()))); ExposedPort consulPort = ExposedPort.tcp(CONSUL_PORT); ports.add(consulPort); - - Ports bindings = cmd.getHostConfig().getPortBindings(); + + Ports bindings = Objects.requireNonNull(cmd.getHostConfig()).getPortBindings(); if (bindings == null) { bindings = new Ports(); } - boolean enableDnsFlag = Boolean.parseBoolean(System.getProperty(CONSUL_DNS_ENABLED_PROPERTY, CONSUL_DNS_ENABLED_DEFAULT)); + boolean enableDnsFlag = Boolean.parseBoolean( + System.getProperty( + ConsulDiscoveryConfig.CONSUL_DNS_ENABLED_PROPERTY, + ConsulDiscoveryConfig.CONSUL_DNS_ENABLED_DEFAULT) + ); - if(enableDnsFlag) { + if (enableDnsFlag) { activateDns(ports); } else { - logger.warning("Consul DNS has been disabled. Usages of @" + UseConsulDns.class.getSimpleName() + " will be ignored."); + logger.warning("Consul DNS has been disabled. Usages of @" + UseConsulDns.class.getSimpleName() + + " will be ignored."); } bindings.bind(consulPort, Binding.bindPort(8500)); @@ -53,13 +54,19 @@ public CreateContainerCmd setup(CreateContainerCmd cmd) { return cmd.withHostConfig(hc) .withExposedPorts(ports) + .withImage( + System.getProperty( + ConsulDiscoveryConfig.CONSUL_IMAGE, + ConsulDiscoveryConfig.CONSUL_DEFAULT_IMAGE + ) + ) .withCmd("sh", "-c", "exec consul agent -dev -client=0.0.0.0 -enable-script-checks -dns-port=53"); - } private void activateDns(List ports) { ExposedPort dnsPort = ExposedPort.udp(CONSUL_DNS_PORT); ports.add(dnsPort); } + } diff --git a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryConfig.java b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryConfig.java index 00f91ab..74edba6 100644 --- a/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryConfig.java +++ b/src/main/java/com/github/dockerunit/discovery/consul/ConsulDiscoveryConfig.java @@ -1,21 +1,26 @@ package com.github.dockerunit.discovery.consul; -import com.github.dockerunit.core.annotation.WithSvc; - import static com.github.dockerunit.discovery.consul.ConsulDiscoveryConfig.CONSUL_CONTAINER_NAME; -@WithSvc(svc =ConsulDescriptor.class, containerNamePrefix =CONSUL_CONTAINER_NAME) +import com.github.dockerunit.core.annotation.WithSvc; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@WithSvc(svc = ConsulDescriptor.class, containerNamePrefix = CONSUL_CONTAINER_NAME) public class ConsulDiscoveryConfig { - public static final String DOCKER_BRIDGE_IP_PROPERTY = "docker.bridge.ip"; - public static final String DOCKER_BRIDGE_IP_DEFAULT = "172.17.42.1"; - public static final String DOCKER_HOST_PROPERTY = "docker.host"; - public static final String SERVICE_DISCOVERY_TIMEOUT = "service.discovery.timeout"; - public static final String SERVICE_DISCOVERY_TIMEOUT_DEFAULT = "30"; - public static final String CONSUL_POLLING_PERIOD = "consul.polling.period"; - public static final String CONSUL_POLLING_PERIOD_DEFAULT = "1"; - public static final String CONSUL_DNS_ENABLED_PROPERTY = "consul.dns.enabled"; - public static final String CONSUL_DNS_ENABLED_DEFAULT = "true"; - public static final String CONSUL_CONTAINER_NAME = "consul"; + public static final String DOCKER_BRIDGE_IP_PROPERTY = "docker.bridge.ip"; + public static final String DOCKER_BRIDGE_IP_DEFAULT = "172.17.42.1"; + public static final String DOCKER_HOST_PROPERTY = "docker.host"; + public static final String SERVICE_DISCOVERY_TIMEOUT = "service.discovery.timeout"; + public static final String SERVICE_DISCOVERY_TIMEOUT_DEFAULT = "30"; + public static final String CONSUL_POLLING_PERIOD = "consul.polling.period"; + public static final String CONSUL_POLLING_PERIOD_DEFAULT = "1"; + public static final String CONSUL_DNS_ENABLED_PROPERTY = "consul.dns.enabled"; + public static final String CONSUL_DNS_ENABLED_DEFAULT = "true"; + public static final String CONSUL_CONTAINER_NAME = "consul"; + public static final String CONSUL_IMAGE = "consul.image"; + public static final String CONSUL_DEFAULT_IMAGE = "consul:1.4.4"; } From 664fc6e5a34ae2cd3bd620a466ca23ee29b9006f Mon Sep 17 00:00:00 2001 From: Quirino Zagarese Date: Wed, 19 Jun 2019 18:56:02 +0100 Subject: [PATCH 21/22] [ISSUE-10] Including container ip in service instance at discovery time Signed-off-by: qzagarese --- pom.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 1629f6d..cad1901 100644 --- a/pom.xml +++ b/pom.xml @@ -24,10 +24,10 @@ 1.18.16 - 2.9.8 - 3.1.5 - 4.5.6 - 4.4.11 + 2.11.3 + 3.2.7 + 4.5.12 + 4.4.13 @@ -68,7 +68,12 @@ com.github.docker-java - docker-java + docker-java-api + ${docker-java.version} + + + com.github.docker-java + docker-java-core ${docker-java.version} From 6358372022f0669c2dd2cc114c8e519a2610565a Mon Sep 17 00:00:00 2001 From: qzagarese Date: Mon, 25 Jan 2021 11:33:53 +0000 Subject: [PATCH 22/22] [ISSUE-10] Fixing dependencies scope Signed-off-by: qzagarese --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index cad1901..4931388 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ com.github.docker-java docker-java-core ${docker-java.version} + runtime org.apache.httpcomponents