Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

#121 - Added support for specifying full binary url by using CONSUL_B… #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down