Skip to content

Instantly share code, notes, and snippets.

@angrycub
Last active September 14, 2017 21:23
Show Gist options
  • Save angrycub/12fe330391f2a74d558a410f5531a8c0 to your computer and use it in GitHub Desktop.
Save angrycub/12fe330391f2a74d558a410f5531a8c0 to your computer and use it in GitHub Desktop.
Nomad Job File for http-echo based on Windows Nano Server

This is gist can be used to create a Windows Nano Server docker container that will run the http-echo sample application

FROM microsoft/nanoserver
ENV HTTP_ECHO_DOWNLOAD_URL "https://github.com/hashicorp/http-echo/releases/download/v0.2.3/http-echo_0.2.3_windows_amd64.zip"
ENV HTTP_ECHO_PORT 8080
ENV HTTP_ECHO_STRING "Hello World"
RUN powershell.exe -Command ; \
$handler = New-Object System.Net.Http.HttpClientHandler ; \
$client = New-Object System.Net.Http.HttpClient($handler) ; \
$client.Timeout = New-Object System.TimeSpan(0,30,0) ; \
$cancelTokenSource = [System.Threading.CancellationTokenSource]::new() ; \
$responseMsg = $client.GetAsync([System.Uri]::new('%HTTP_ECHO_DOWNLOAD_URL%'), $cancelTokenSource.Token) ; \
$responseMsg.Wait() ; \
$downloadedFileStream = [System.IO.FileStream]::new('c:\http_echo.zip', [System.IO.FileMode]::Create, [System.IO.FileAcc
ess]::Write) ; \
$response = $responseMsg.Result ; \
$copyStreamOp = $response.Content.CopyToAsync($downloadedFileStream) ; \
$copyStreamOp.Wait() ; \
$downloadedFileStream.Close() ; \
[System.IO.compression.ZipFile]::ExtractToDirectory('c:\http_echo.zip','c:\') ; \
Remove-Item c:\http_echo.zip -Force ; \
Rename-Item c:\http-echo c:\http-echo.exe -Force
CMD c:\http-echo.exe -listen=:%HTTP_ECHO_PORT% -text="%HTTP_ECHO_STRING%"
job "example-job" {
constraint {
attribute = "${attr.kernel.name}"
operator = "="
value = "windows"
}
datacenters = ["dc1"]
type = "service"
update {
max_parallel = 1
min_healthy_time = "10s"
healthy_deadline = "3m"
auto_revert = true
canary = 0
}
group "example-group" {
count = 1
restart {
attempts = 10
interval = "5m"
delay = "25s"
mode = "delay"
}
task "example-task" {
driver = "docker"
config {
image = "voiselle/http-echo-win:latest"
port_map {
http = 8080
}
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
port "http" {}
}
}
service {
name = "global-example-check"
tags = ["global", "http-echo"]
address_mode = "host"
port = "http"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment