forked from hashicorp/consul
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONSUL-190] Support consul windows compilation in Docker (#14)
- Loading branch information
1 parent
5bb8de0
commit 93b3f0c
Showing
7 changed files
with
215 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/dumb-init /bin/sh | ||
set -e | ||
|
||
# Note above that we run dumb-init as PID 1 in order to reap zombie processes | ||
# as well as forward signals to all processes in its session. Normally, sh | ||
# wouldn't do either of these functions so we'd leak zombies as well as do | ||
# unclean termination of all our sub-processes. | ||
# As of docker 1.13, using docker run --init achieves the same outcome. | ||
|
||
# You can set CONSUL_BIND_INTERFACE to the name of the interface you'd like to | ||
# bind to and this will look up the IP and pass the proper -bind= option along | ||
# to Consul. | ||
CONSUL_BIND= | ||
if [ -n "$CONSUL_BIND_INTERFACE" ]; then | ||
CONSUL_BIND_ADDRESS=$(ip -o -4 addr list $CONSUL_BIND_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1) | ||
if [ -z "$CONSUL_BIND_ADDRESS" ]; then | ||
echo "Could not find IP for interface '$CONSUL_BIND_INTERFACE', exiting" | ||
exit 1 | ||
fi | ||
|
||
CONSUL_BIND="-bind=$CONSUL_BIND_ADDRESS" | ||
echo "==> Found address '$CONSUL_BIND_ADDRESS' for interface '$CONSUL_BIND_INTERFACE', setting bind option..." | ||
fi | ||
|
||
# You can set CONSUL_CLIENT_INTERFACE to the name of the interface you'd like to | ||
# bind client intefaces (HTTP, DNS, and RPC) to and this will look up the IP and | ||
# pass the proper -client= option along to Consul. | ||
CONSUL_CLIENT= | ||
if [ -n "$CONSUL_CLIENT_INTERFACE" ]; then | ||
CONSUL_CLIENT_ADDRESS=$(ip -o -4 addr list $CONSUL_CLIENT_INTERFACE | head -n1 | awk '{print $4}' | cut -d/ -f1) | ||
if [ -z "$CONSUL_CLIENT_ADDRESS" ]; then | ||
echo "Could not find IP for interface '$CONSUL_CLIENT_INTERFACE', exiting" | ||
exit 1 | ||
fi | ||
|
||
CONSUL_CLIENT="-client=$CONSUL_CLIENT_ADDRESS" | ||
echo "==> Found address '$CONSUL_CLIENT_ADDRESS' for interface '$CONSUL_CLIENT_INTERFACE', setting client option..." | ||
fi | ||
|
||
# CONSUL_DATA_DIR is exposed as a volume for possible persistent storage. The | ||
# CONSUL_CONFIG_DIR isn't exposed as a volume but you can compose additional | ||
# config files in there if you use this image as a base, or use CONSUL_LOCAL_CONFIG | ||
# below. | ||
CONSUL_DATA_DIR=C:\\consul\\data | ||
CONSUL_CONFIG_DIR=C:\\consul\\config | ||
|
||
# You can also set the CONSUL_LOCAL_CONFIG environemnt variable to pass some | ||
# Consul configuration JSON without having to bind any volumes. | ||
if [ -n "$CONSUL_LOCAL_CONFIG" ]; then | ||
echo "$CONSUL_LOCAL_CONFIG" > "$CONSUL_CONFIG_DIR/local.json" | ||
fi | ||
|
||
# If the user is trying to run Consul directly with some arguments, then | ||
# pass them to Consul. | ||
if [ "${1:0:1}" = '-' ]; then | ||
set -- consul "$@" | ||
fi | ||
|
||
# Look for Consul subcommands. | ||
if [ "$1" = 'agent' ]; then | ||
shift | ||
set -- consul agent \ | ||
-data-dir="$CONSUL_DATA_DIR" \ | ||
-config-dir="$CONSUL_CONFIG_DIR" \ | ||
$CONSUL_BIND \ | ||
$CONSUL_CLIENT \ | ||
"$@" | ||
elif [ "$1" = 'version' ]; then | ||
# This needs a special case because there's no help output. | ||
set -- consul "$@" | ||
elif consul --help "$1" 2>&1 | grep -q "consul $1"; then | ||
# We can't use the return code to check for the existence of a subcommand, so | ||
# we have to use grep to look for a pattern in the help output. | ||
set -- consul "$@" | ||
fi | ||
|
||
# NOTE: Unlike in the regular Consul Docker image, we don't have code here | ||
# for changing data-dir directory ownership or using su-exec because OpenShift | ||
# won't run this container as root and so we can't change data dir ownership, | ||
# and there's no need to use su-exec. | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
ARG CONSUL_IMAGE_VERSION=1.12.0 | ||
FROM mcr.microsoft.com/windows/servercore:1809 | ||
|
||
ENV VERSION=1.12.0 | ||
|
||
LABEL org.opencontainers.image.authors="Consul Team <[email protected]>" \ | ||
org.opencontainers.image.url="https://www.consul.io/" \ | ||
org.opencontainers.image.documentation="https://www.consul.io/docs" \ | ||
org.opencontainers.image.source="https://github.com/hashicorp/consul" \ | ||
org.opencontainers.image.version=$VERSION \ | ||
org.opencontainers.image.vendor="HashiCorp" \ | ||
org.opencontainers.image.title="consul" \ | ||
org.opencontainers.image.description="Consul is a datacenter runtime that provides service discovery, configuration, and orchestration." | ||
|
||
RUN ["powershell", "Set-ExecutionPolicy", "Bypass", "-Scope", "Process", "-Force;"] | ||
RUN ["powershell", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"] | ||
|
||
|
@@ -10,14 +20,29 @@ RUN mkdir C:\\consul | |
RUN mkdir C:\\consul\\data | ||
RUN mkdir C:\\consul\\config | ||
|
||
|
||
# Server RPC is used for communication between Consul clients and servers for internal | ||
# request forwarding. | ||
EXPOSE 8300 | ||
|
||
# Serf LAN and WAN (WAN is used only by Consul servers) are used for gossip between | ||
# Consul agents. LAN is within the datacenter and WAN is between just the Consul | ||
# servers in all datacenters. | ||
EXPOSE 8301 8301/udp 8302 8302/udp | ||
EXPOSE 8500 8600 8600/udp | ||
|
||
ENV CONSUL_VERSION=1.12.0 | ||
ENV CONSUL_URL=https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_windows_amd64.zip | ||
# HTTP and DNS (both TCP and UDP) are the primary interfaces that applications | ||
# use to interact with Consul. | ||
EXPOSE 8500 8600 8600/udp | ||
|
||
ENV CONSUL_URL=https://releases.hashicorp.com/consul/${VERSION}/consul_${VERSION}_windows_amd64.zip | ||
RUN curl %CONSUL_URL% -L -o consul.zip | ||
RUN tar -xf consul.zip -C consul | ||
|
||
ENV PATH C:\\Program Files\\Git\\bin;C:\\consul;%PATH% | ||
|
||
COPY .release/docker/docker-entrypoint-windows.sh C:\\docker-entrypoint-windows.sh | ||
ENTRYPOINT ["bash.exe", "docker-entrypoint-windows.sh"] | ||
|
||
# By default you'll get an insecure single-node development server that stores | ||
# everything in RAM, exposes a web UI and HTTP endpoints, and bootstraps itself. | ||
# Don't use this configuration for production. | ||
CMD ["agent", "-dev", "-client", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ARG CONSUL_IMAGE_VERSION=latest | ||
FROM windows/consul:${CONSUL_IMAGE_VERSION} | ||
COPY dist/ C:\\consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
cd ../ | ||
rm -rf dist | ||
|
||
export GOOS=windows GOARCH=amd64 | ||
CONSUL_VERSION=1.12.0 | ||
CONSUL_BUILDDATE=$(date +"%Y-%m-%dT%H:%M:%SZ") | ||
GIT_IMPORT=github.com/hashicorp/consul/version | ||
GOLDFLAGS=" -X $GIT_IMPORT.Version=$CONSUL_VERSION -X $GIT_IMPORT.VersionPrerelease=local -X $GIT_IMPORT.BuildDate=$CONSUL_BUILDDATE " | ||
|
||
go build -ldflags "$GOLDFLAGS" -o ./dist/ . | ||
|
||
docker build -t windows/consul-dev -f ./build-support-windows/Dockerfile-consul-dev-windows . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.