Restructure project
We previously didn't really had any structure in our project apart from creating a new folder for each package in our project root. Now that we have accumulated some packages, we use the well-known Golang project layout in order to clearly communicate our intent with packages. See https://github.com/golang-standards/project-layout
This commit is contained in:
76
deploy/api.tpl.nomad
Normal file
76
deploy/api.tpl.nomad
Normal file
@ -0,0 +1,76 @@
|
||||
job "${NOMAD_SLUG}" {
|
||||
datacenters = ["dc1"]
|
||||
namespace = "${NOMAD_NAMESPACE}"
|
||||
|
||||
group "api" {
|
||||
count = 1
|
||||
|
||||
update {
|
||||
// https://learn.hashicorp.com/tutorials/nomad/job-rolling-update
|
||||
max_parallel = 1
|
||||
min_healthy_time = "30s"
|
||||
healthy_deadline = "5m"
|
||||
progress_deadline = "10m"
|
||||
auto_revert = true
|
||||
}
|
||||
|
||||
// Don't allow rescheduling to fail deployment and pipeline if task fails
|
||||
reschedule {
|
||||
attempts = 0
|
||||
unlimited = false
|
||||
}
|
||||
|
||||
// No restarts to immediately fail the deployment and pipeline on first task fail
|
||||
restart {
|
||||
attempts = 0
|
||||
}
|
||||
|
||||
network {
|
||||
mode = "bridge"
|
||||
|
||||
port "http" {
|
||||
to = 7200
|
||||
}
|
||||
}
|
||||
|
||||
service {
|
||||
# urlprefix- tag allows Fabio to discover this service and proxy traffic correctly
|
||||
tags = ["urlprefix-${HOSTNAME}:80/"]
|
||||
name = "${NOMAD_SLUG}"
|
||||
port = "http"
|
||||
|
||||
// Health check to let Consul know we are alive
|
||||
check {
|
||||
name = "health-check"
|
||||
type = "http"
|
||||
port = "http"
|
||||
path = "/api/v1/health"
|
||||
interval = "10s"
|
||||
timeout = "2s"
|
||||
check_restart {
|
||||
limit = 3 // auto-restart task when health check fails 3x in a row
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
task "api" {
|
||||
driver = "docker"
|
||||
|
||||
config {
|
||||
image = "${IMAGE_NAME_ENV}"
|
||||
}
|
||||
|
||||
env {
|
||||
POSEIDON_SERVER_ADDRESS = "${POSEIDON_LISTEN_ADDRESS}"
|
||||
POSEIDON_NOMAD_ADDRESS = "${NOMAD_SERVER_HOST}"
|
||||
POSEIDON_NOMAD_NAMESPACE = "${NOMAD_NAMESPACE}"
|
||||
}
|
||||
|
||||
resources {
|
||||
memory = "100" // 100 MB RAM
|
||||
cpu = "100" // 100 MHz
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
77
deploy/demo-job.tpl.nomad
Normal file
77
deploy/demo-job.tpl.nomad
Normal file
@ -0,0 +1,77 @@
|
||||
// This job is used by the e2e tests as a demo job.
|
||||
|
||||
job "template-0" {
|
||||
datacenters = ["dc1"]
|
||||
type = "batch"
|
||||
namespace = "${NOMAD_NAMESPACE}"
|
||||
|
||||
group "default-group" {
|
||||
ephemeral_disk {
|
||||
migrate = false
|
||||
size = 10
|
||||
sticky = false
|
||||
}
|
||||
count = 1
|
||||
scaling {
|
||||
enabled = true
|
||||
max = 300
|
||||
}
|
||||
spread {
|
||||
// see https://www.nomadproject.io/docs/job-specification/spread#even-spread-across-data-center
|
||||
// This spreads the load evenly amongst our nodes
|
||||
attribute = "${node.unique.name}"
|
||||
weight = 100
|
||||
}
|
||||
|
||||
task "default-task" {
|
||||
driver = "docker"
|
||||
kill_timeout = "0s"
|
||||
kill_signal = "SIGKILL"
|
||||
|
||||
config {
|
||||
image = "openhpi/co_execenv_python:3.8"
|
||||
command = "sleep"
|
||||
args = ["infinity"]
|
||||
}
|
||||
|
||||
logs {
|
||||
max_files = 1
|
||||
max_file_size = 1
|
||||
}
|
||||
|
||||
resources {
|
||||
cpu = 40
|
||||
memory = 40
|
||||
}
|
||||
|
||||
restart {
|
||||
delay = "0s"
|
||||
}
|
||||
}
|
||||
}
|
||||
group "config" {
|
||||
// We want to store whether a task is in use in order to recover from a downtime.
|
||||
// Without a separate config task, marking a task as used would result in a restart of that task,
|
||||
// as the meta information is passed to the container as environment variables.
|
||||
count = 0
|
||||
task "config" {
|
||||
driver = "exec"
|
||||
config {
|
||||
command = "true"
|
||||
}
|
||||
logs {
|
||||
max_files = 1
|
||||
max_file_size = 1
|
||||
}
|
||||
resources {
|
||||
// minimum values
|
||||
cpu = 1
|
||||
memory = 10
|
||||
}
|
||||
}
|
||||
meta {
|
||||
used = "false"
|
||||
prewarmingPoolSize = "0"
|
||||
}
|
||||
}
|
||||
}
|
3
deploy/docker-make/Dockerfile
Normal file
3
deploy/docker-make/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
||||
FROM docker:latest
|
||||
|
||||
RUN apk update && apk add make
|
37
deploy/nomad-ci/Dockerfile
Normal file
37
deploy/nomad-ci/Dockerfile
Normal file
@ -0,0 +1,37 @@
|
||||
# Simple image containing the Nomad binary to deploy Nomad jobs
|
||||
|
||||
FROM golang:latest
|
||||
|
||||
# Install prerequisites, gettext contains envsubst used in the CI
|
||||
RUN apt-get update && \
|
||||
apt install -y \
|
||||
unzip \
|
||||
wget \
|
||||
gettext \
|
||||
apt-transport-https \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release && \
|
||||
apt-get clean && \
|
||||
rm -rf /var/lib/apt/lists
|
||||
|
||||
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
||||
RUN echo \
|
||||
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
|
||||
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
RUN apt-get update && \
|
||||
apt-get install -y docker-ce docker-ce-cli containerd.io && \
|
||||
rm -rf /var/lib/apt/lists
|
||||
|
||||
# Download Nomad
|
||||
RUN wget "https://releases.hashicorp.com/nomad/1.1.1/nomad_1.1.1_linux_amd64.zip" && \
|
||||
wget "https://releases.hashicorp.com/nomad/1.1.1/nomad_1.1.1_SHA256SUMS" && \
|
||||
grep "nomad_1.1.1_linux_amd64.zip" nomad_1.1.1_SHA256SUMS | sha256sum -c - && \
|
||||
unzip nomad_1.1.1_linux_amd64.zip
|
||||
|
||||
# Install Nomad
|
||||
RUN mv nomad /usr/sbin/ && nomad -version
|
||||
|
||||
COPY nomad-run-and-wait /usr/sbin/
|
||||
RUN chmod +x /usr/sbin/nomad-run-and-wait
|
48
deploy/nomad-ci/nomad-run-and-wait
Normal file
48
deploy/nomad-ci/nomad-run-and-wait
Normal file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script that runs a Nomad job and watches the deployment status until it finished running
|
||||
# See https://github.com/hashicorp/nomad/issues/6818
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: $0 <path/to/job.nomad>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
output=$(nomad run $1 2>&1)
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo $output
|
||||
exit 1
|
||||
fi
|
||||
|
||||
deployment=$(grep -oP "(?<=Evaluation within deployment: \").*(?=\")" <<<$output)
|
||||
|
||||
echo "Monitoring deployment $deployment"
|
||||
|
||||
timeout=300
|
||||
sleepDuration=4
|
||||
iterations=$((timeout / sleepDuration))
|
||||
|
||||
for i in $(seq $iterations); do
|
||||
if [[ $i -eq $iterations ]]; then
|
||||
# timeout reached, fail deployment and exit
|
||||
nomad deployment fail $deployment
|
||||
exit 1
|
||||
fi
|
||||
output=$(nomad deployment status $deployment 2>&1)
|
||||
grep -E "Status" <<<$output
|
||||
running=$(grep -E "Status.*=.*running" <<<$output)
|
||||
if [[ -z "$running" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep $sleepDuration
|
||||
done
|
||||
|
||||
echo "#######"
|
||||
echo "$output"
|
||||
failed=$(grep -E "Status.*=.*failed" <<<$output)
|
||||
if [[ -n "$failed" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
14
deploy/nomad-run-env-job.sh
Executable file
14
deploy/nomad-run-env-job.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script substitutes environment variables in the given Nomad job and runs it afterwards.
|
||||
|
||||
if [[ "$#" -ne 2 ]]; then
|
||||
echo "Usage: $0 path/to/infile path/to/outfile"
|
||||
fi
|
||||
|
||||
envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < $1 > $2
|
||||
nomad validate $2
|
||||
# nomad plan returns 1 if allocations are created or destroyed which is what we want here
|
||||
# https://www.nomadproject.io/docs/commands/job/plan#usage
|
||||
nomad plan $2 || [ $? == 1 ]
|
||||
nomad run $2
|
8
deploy/poseidon/Dockerfile
Normal file
8
deploy/poseidon/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN adduser --disabled-password api
|
||||
USER api
|
||||
COPY poseidon /home/api/
|
||||
|
||||
EXPOSE 7200
|
||||
CMD ["/home/api/poseidon"]
|
Reference in New Issue
Block a user