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:
sirkrypt0
2021-07-16 09:19:42 +02:00
parent 2f1383b743
commit 8b26ecbe5f
66 changed files with 95 additions and 95 deletions

View 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

View 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