From a222a82d33b18dcf6dd30a655fbbd177449c7bc3 Mon Sep 17 00:00:00 2001 From: blondacz Date: Wed, 15 Jun 2022 13:03:36 +0100 Subject: [PATCH] #121 - Added support for specifying full binary url by using CONSUL_BINARY_URL environment variable/system property --- README.md | 10 ++++++++-- .../infrastructure/HttpBinaryRepository.groovy | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b8b068f..d7ec20e 100644 --- a/README.md +++ b/README.md @@ -195,14 +195,20 @@ ConsulProcess consul = ConsulStarterBuilder.consulStarter().withCustomConfig(cus Given JSON configuration will be saved in addition configuration file `extra_config.json` and processed after base configuration (with highest priority). -### Changing download directory +### Changing download location -An environment variable can be set to change the consul CDN. +An environment variable (or system property) can be set to change the consul CDN. Reminder of the download url is calculated from OS, architecture and version automatically. ```bash # default export CONSUL_BINARY_CDN=https://releases.hashicorp.com/consul/ ``` + +Or a full path can be specified using following environment variable (or system property of the same name) +```bash +export CONSUL_BINARY_URL=https://releases.hashicorp.com/consul/1.12.2/consul_1.12.2_linux_amd64.zip +``` + Proxy can be used if necessary. ``` https.proxyHost=localhost diff --git a/src/main/groovy/com/pszymczyk/consul/infrastructure/HttpBinaryRepository.groovy b/src/main/groovy/com/pszymczyk/consul/infrastructure/HttpBinaryRepository.groovy index fe4dafd..2f8a7b5 100644 --- a/src/main/groovy/com/pszymczyk/consul/infrastructure/HttpBinaryRepository.groovy +++ b/src/main/groovy/com/pszymczyk/consul/infrastructure/HttpBinaryRepository.groovy @@ -2,6 +2,7 @@ package com.pszymczyk.consul.infrastructure class HttpBinaryRepository { + public static final String CONSUL_BINARY_URL = "CONSUL_BINARY_URL" public static final String CONSUL_BINARY_CDN = "CONSUL_BINARY_CDN" public static final String CONSUL_DEFAULT_CDN = "https://releases.hashicorp.com/consul/" private HttpsProtocolsSetter httpsProtocolsSetter @@ -12,11 +13,16 @@ class HttpBinaryRepository { File getConsulBinaryArchive(String version, File file) { httpsProtocolsSetter.setRequiredTls(System.getProperty("java.version"), System.getProperty("https.protocols")) - String os = OsResolver.resolve() - String cdn = System.getenv(CONSUL_BINARY_CDN) != null ? System.getenv(CONSUL_BINARY_CDN) - : System.getProperty(CONSUL_BINARY_CDN) != null ? System.getProperty(CONSUL_BINARY_CDN) : CONSUL_DEFAULT_CDN; - String ARCH = ( (System.getProperty('os.arch')).equals("aarch64") == true ? "arm64" : "amd64" ) - String url = "${cdn}${version}/consul_${version}_${os}_${ARCH}.zip" + String url = System.getenv(CONSUL_BINARY_URL) ?: System.getProperty(CONSUL_BINARY_URL) + + if (url == null) { + String os = OsResolver.resolve() + String cdn = System.getenv(CONSUL_BINARY_CDN) != null ? System.getenv(CONSUL_BINARY_CDN) + : System.getProperty(CONSUL_BINARY_CDN) != null ? System.getProperty(CONSUL_BINARY_CDN) : CONSUL_DEFAULT_CDN; + String ARCH = (System.getProperty('os.arch')) == "aarch64" ? "arm64" : "amd64" + url = "${cdn}${version}/consul_${version}_${os}_${ARCH}.zip" + } + OutputStream outputStream = file.newOutputStream() outputStream << new URL(url).openStream() outputStream.close()