Skip to content

Commit

Permalink
[CONSUL-441] Update windows dockerfile with version (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezfepo authored and joselo85 committed Dec 21, 2022
1 parent 85e9033 commit 0a01500
Show file tree
Hide file tree
Showing 20 changed files with 300 additions and 269 deletions.
7 changes: 4 additions & 3 deletions Dockerfile-windows
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM mcr.microsoft.com/windows/servercore:1809
ENV VERSION=1.12.0
FROM docker.mirror.hashicorp.services/windows/servercore:1809
ARG VERSION=1.13.1

LABEL org.opencontainers.image.authors="Consul Team <consul@hashicorp.com>" \
org.opencontainers.image.url="https://www.consul.io/" \
Expand All @@ -8,7 +8,8 @@ LABEL org.opencontainers.image.authors="Consul Team <consul@hashicorp.com>" \
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."
org.opencontainers.image.description="Consul is a datacenter runtime that provides service discovery, configuration, and orchestration." \
version=${VERSION}

RUN ["powershell", "Set-ExecutionPolicy", "Bypass", "-Scope", "Process", "-Force;"]
RUN ["powershell", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"]
Expand Down
52 changes: 31 additions & 21 deletions build-support-windows/BUILD-IMAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
## Index

- [About](#about-this-file)
- [Consul-windows](#consul-windows)
- [Dockerfile-consul-local-windows](#dockerfile-consul-local-windows)
- [Consul Windows](#consul-windows)
- [Consul Windows Local](#consul-windows-local)
- [Consul Windows Dev](#consul-windows-dev)
- [Dockerfile-openzipkin-windows](#dockerfile-openzipkin-windows)
- [Build images](#build-images)

## About this File

In this file you will find which Docker images that need to be pre-built to run the Envoy integration tests on Windows, as well as information on how to run each of these files individually for testing purposes.

## Consul-windows
## Consul Windows

The required Consul image is built from the "Dockerfile-windows" file located at the root of the project.
The Windos/Consul:_{VERSION}_ image is built from the "Dockerfile-windows" file located at the root of the project.
To do this, the official [windows/servercore image](https://hub.docker.com/_/microsoft-windows-servercore) is used as base image.
To build the image, use the following command:

```shell
docker build -t windows/consul -f Dockerfile-windows .
docker build -t windows/consul -f Dockerfile-windows . --build-arg VERSION=${VERSION}
```

You can test the built file by running the following command:
Expand All @@ -30,22 +30,42 @@ docker run --rm -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8500:8500 -p 8600:8600

If everything works properly you should openning the browser and check the Consul UI running on: `http://localhost:8500`

## Dockerfile-consul-local-windows
## Consul Windows Local

The Consul:local custom image deployed in the "Dockerfile-consul-local-windows" DockerFile is generated by the shell script of the same name.
When executing it, the compilation of Consul is carried out and it is saved in the _"dist"_ directory, this file is then copied to a container created from the _"windows/consul"_ image.
The Windows/Consul:_{VERSION}_-local custom image deployed in the "Dockerfile-consul-local-windows" DockerFile is built from the selected by the shell script _build-consul-local-images.sh_.
When executing it, all the tools required to run the Windows Connect Envoy Integration Tests will be added to the image.
It is necessary that the _"windows/consul"_ image has been built first.

To build this image you need to run the following command on your terminal:

```shell
./Dockerfile-consul-local-windows.sh
./build-consul-local-images.sh
```

You can test the built file by running the following command:

```shell
docker run --rm -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8500:8500 -p 8600:8600 --name consul-local --hostname "consul-primary-server" --network-alias "consul-primary-server" windows/consul:local agent -dev -datacenter "primary" -grpc-port -1 -client "0.0.0.0" -bind "0.0.0.0"
docker run --rm -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8500:8500 -p 8600:8600 --name consul-local --hostname "consul-primary-server" --network-alias "consul-primary-server" windows/consul:_{VERSION}_-local agent -dev -datacenter "primary" -grpc-port -1 -client "0.0.0.0" -bind "0.0.0.0"
```

If everything works properly you should openning the browser and check the Consul UI running on: `http://localhost:8500`

## Consul Windows Dev

The Windows/Consul:_{VERSION}_-dev custom image deployed in the "Dockerfile-consul-dev-windows" DockerFile is generated by the shell script named _build-consul-dev-image.sh_.
When executing it, the compilation of Consul is carried out and it is saved in the _"dist"_ directory, this file is then copied to the _"windows/consul:_{VERSION}_-dev"_ image.
It is necessary that the _"windows/consul"_ image has been built first.

To build this image you need to run the following command on your terminal:

```shell
./build-consul-dev-image.sh
```

You can test the built file by running the following command:

```shell
docker run --rm -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8500:8500 -p 8600:8600 --name consul-local --hostname "consul-primary-server" --network-alias "consul-primary-server" windows/consul:_{VERSION}_-dev agent -dev -datacenter "primary" -grpc-port -1 -client "0.0.0.0" -bind "0.0.0.0"
```

If everything works properly you should openning the browser and check the Consul UI running on: `http://localhost:8500`
Expand Down Expand Up @@ -74,16 +94,6 @@ If everything works as it should, you will see the zipkin logo being displayed,
20XX-XX-XX XX:XX:XX.XXX INFO [/] 1252 --- [oss-http-*:9411] c.l.a.s.Server : Serving HTTP at /[0:0:0:0:0:0:0:0]:9411 - http://127.0.0.1:9411/
```

## Build images

To build the images, it is necessary to open a Git bash terminal and run

```shell
./build-images.sh
```

---

# Testing

During development, it may be more convenient to check your work-in-progress by running only the tests which you expect to be affected by your changes, as the full test suite can take several minutes to execute. [Go's built-in test tool](https://golang.org/pkg/cmd/go/internal/test/) allows specifying a list of packages to test and the `-run` option to only include test names matching a regular expression.
Expand Down
4 changes: 4 additions & 0 deletions build-support-windows/Dockerfile-consul-dev-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG VERSION=1.13.1

FROM windows/consul:${VERSION}-local
COPY dist/ C:\\consul
19 changes: 7 additions & 12 deletions build-support-windows/Dockerfile-consul-local-windows
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
ARG ENVOY_VERSION=v1.19.5
ARG CONSUL_IMAGE_VERSION=latest
ARG VERSION=1.13.1

FROM envoyproxy/envoy-windows:${ENVOY_VERSION} as envoy
FROM windows/consul:${CONSUL_IMAGE_VERSION}
COPY dist/ C:\\consul
FROM windows/test-sds-server as test-sds-server
FROM windows/consul:${VERSION}

# Fortio binary downloaded
RUN mkdir fortio
ENV FORTIO_URL=https://github.com/fortio/fortio/releases/download/v1.33.0/fortio_win_1.33.0.zip
RUN curl %FORTIO_URL% -L -o fortio.zip
RUN tar -xf fortio.zip -C fortio

# Copy envoy.exe from FROM envoyproxy/envoy-windows:${ENVOY_VERSION}
COPY --from=envoy ["C:/Program Files/envoy/", "C:/envoy/"]

RUN choco install openssl -yf
RUN choco install jq -yf
RUN choco install netcat -yf
Expand All @@ -31,15 +26,15 @@ RUN curl %JAEGER_URL% -L -o jaeger.tar.gz
RUN mkdir jaeger
RUN tar -xf jaeger.tar.gz -C jaeger --strip-components=1

# Copy test-sds-server binary and certs
COPY --from=test-sds-server ["C:/go/src/", "C:/test-sds-server/"]

# Install Socat
ENV SOCAT_URL=https://github.com/tech128/socat-1.7.3.0-windows/archive/refs/heads/master.zip
RUN curl %SOCAT_URL% -L -o socat.zip
RUN mkdir socat
RUN tar -xf socat.zip -C socat --strip-components=1

# Copy test-sds-server binary and certs
COPY --from=test-sds-server ["C:/go/src/", "C:/test-sds-server/"]

EXPOSE 8300
EXPOSE 8301 8301/udp 8302 8302/udp
EXPOSE 8500 8600 8600/udp
Expand All @@ -49,4 +44,4 @@ EXPOSE 19000 19001 19002 19003 19004
EXPOSE 21000 21001 21002 21003 21004
EXPOSE 5000 1234 2345

RUN SETX /M path "%PATH%;C:\consul;C:\envoy;C:\fortio;C:\jaeger;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\OpenSSL-Win64\bin;C:\bats\bin\;C:\ProgramData\chocolatey\lib\jq\tools;C:\socat;"
RUN SETX /M path "%PATH%;C:\consul;C:\fortio;C:\jaeger;C:\Program Files\Git\bin;C:\Program Files\Git\usr\bin;C:\Program Files\OpenSSL-Win64\bin;C:\bats\bin\;C:\ProgramData\chocolatey\lib\jq\tools;C:\socat;"
14 changes: 0 additions & 14 deletions build-support-windows/Dockerfile-consul-local-windows.sh

This file was deleted.

2 changes: 1 addition & 1 deletion build-support-windows/Dockerfile-openzipkin-windows
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:jdk-windowsservercore
FROM docker.mirror.hashicorp.services/windows/openjdk:1809

RUN curl.exe -sSL 'https://search.maven.org/remote_content?g=io.zipkin&a=zipkin-server&v=LATEST&c=exec' -o zipkin.jar

Expand Down
14 changes: 14 additions & 0 deletions build-support-windows/build-consul-dev-image.sh
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
VERSION=1.13.1
CONSUL_BUILDDATE=$(date +"%Y-%m-%dT%H:%M:%SZ")
GIT_IMPORT=github.com/hashicorp/consul/version
GOLDFLAGS=" -X $GIT_IMPORT.Version=$VERSION -X $GIT_IMPORT.VersionPrerelease=dev -X $GIT_IMPORT.BuildDate=$CONSUL_BUILDDATE "

go build -ldflags "$GOLDFLAGS" -o ./dist/ .

docker build -t windows/consul:${VERSION}-dev -f ./build-support-windows/Dockerfile-consul-dev-windows . --build-arg VERSION=${VERSION}
80 changes: 80 additions & 0 deletions build-support-windows/build-consul-local-images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

readonly HASHICORP_DOCKER_PROXY="docker.mirror.hashicorp.services"

# Build Consul Version 1.13.1 / 1.12.4 / 1.11.8
VERSION=${VERSION:-"1.13.1"}
export VERSION

echo "Building Images"


# Pull Windows Servercore image
echo " "
echo "Pull Windows Servercore image"
docker pull mcr.microsoft.com/windows/servercore:1809
# Tag Windows Servercore image
echo " "
echo "Tag Windows Servercore image"
docker tag mcr.microsoft.com/windows/servercore:1809 "${HASHICORP_DOCKER_PROXY}/windows/servercore:1809"


# Pull Windows Nanoserver image
echo " "
echo "Pull Windows Nanoserver image"
docker pull mcr.microsoft.com/windows/nanoserver:1809
# Tag Windows Nanoserver image
echo " "
echo "Tag Windows Nanoserver image"
docker tag mcr.microsoft.com/windows/nanoserver:1809 "${HASHICORP_DOCKER_PROXY}/windows/nanoserver:1809"


# Pull Windows OpenJDK image
echo " "
echo "Pull Windows OpenJDK image"
docker pull openjdk:windowsservercore-1809
# Tag Windows OpenJDK image
echo " "
echo "Tag Windows OpenJDK image"
docker tag openjdk:windowsservercore-1809 "${HASHICORP_DOCKER_PROXY}/windows/openjdk:1809"

# Pull Windows Golang image
echo " "
echo "Pull Windows Golang image"
docker pull golang:1.18.1-nanoserver-1809
# Tag Windows Golang image
echo " "
echo "Tag Windows Golang image"
docker tag golang:1.18.1-nanoserver-1809 "${HASHICORP_DOCKER_PROXY}/windows/golang:1809"


# Pull Kubernetes/pause image
echo " "
echo "Pull Kubernetes/pause image"
docker pull mcr.microsoft.com/oss/kubernetes/pause:3.6
# Tag Kubernetes/pause image
echo " "
echo "Tag Kubernetes/pause image"
docker tag mcr.microsoft.com/oss/kubernetes/pause:3.6 "${HASHICORP_DOCKER_PROXY}/windows/kubernetes/pause"


# Build Windows Openzipkin Image
docker build -t "${HASHICORP_DOCKER_PROXY}/windows/openzipkin" -f Dockerfile-openzipkin-windows .


# Build Windows Test sds server Image
./build-test-sds-server-image.sh


# Build windows/consul:${VERSION} Image
echo " "
echo "Build windows/consul:${VERSION} Image"
docker build -t "windows/consul:${VERSION}" -f ../Dockerfile-windows ../ --build-arg VERSION=${VERSION}


# Build windows/consul:${VERSION}-local Image
echo " "
echo "Build windows/consul:${VERSION}-local Image"
docker build -t windows/consul:${VERSION}-local -f ./Dockerfile-consul-local-windows . --build-arg VERSION=${VERSION}

echo "Building Complete!"
42 changes: 0 additions & 42 deletions build-support-windows/build-images.sh

This file was deleted.

5 changes: 5 additions & 0 deletions build-support-windows/build-test-sds-server-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd ../test/integration/connect/envoy

docker build -t windows/test-sds-server -f ./Dockerfile-test-sds-server-windows test-sds-server

0 comments on commit 0a01500

Please sign in to comment.