diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee4f262..e8b5efc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -114,8 +114,8 @@ test_e2e: - export NOMAD_ADDR=http://localhost:4646 - nomad agent -dev -log-level=WARN & - sleep 5 - # Setup Nomad job and wait for it - - nomad run ci/e2e-test.nomad + - export NOMAD_NAMESPACE="default" + - ./ci/nomad-run-env-job.sh ci/demo-job.tpl.nomad ci/demo-job.nomad - sleep 5 # Start Poseidon and wait for it - ./poseidon & @@ -158,10 +158,7 @@ deploy_review: before_script: - export NOMAD_NAMESPACE="$NOMAD_SLUG" - nomad namespace apply $NOMAD_NAMESPACE - - envsubst "$(env | sed -e 's/=.*//' -e 's/^/\$/g')" < ci/deploy-review.tpl.nomad > ci/deploy-review.nomad - - nomad validate ci/deploy-review.nomad - - nomad plan ci/deploy-review.nomad || [ $? == 1 ] - - nomad run ci/deploy-review.nomad + - ./ci/nomad-run-env-job.sh ci/demo-job.tpl.nomad ci/demo-job.nomad only: - branches - tags diff --git a/ci/e2e-test.nomad b/ci/demo-job.tpl.nomad similarity index 96% rename from ci/e2e-test.nomad rename to ci/demo-job.tpl.nomad index 3693e8d..a321378 100644 --- a/ci/e2e-test.nomad +++ b/ci/demo-job.tpl.nomad @@ -3,6 +3,7 @@ job "python" { datacenters = ["dc1"] type = "batch" + namespace = "${NOMAD_NAMESPACE}" group "python-group" { ephemeral_disk { diff --git a/ci/deploy-review.tpl.nomad b/ci/deploy-review.tpl.nomad deleted file mode 100644 index 0d3bc0e..0000000 --- a/ci/deploy-review.tpl.nomad +++ /dev/null @@ -1,52 +0,0 @@ -// This job is used by our deploy CI stage to create a seed job. - -job "python" { - datacenters = ["dc1"] - type = "batch" - namespace = "${NOMAD_NAMESPACE}" - - group "python" { - ephemeral_disk { - migrate = false - size = 10 - sticky = false - } - count = 5 - 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 "python" { - 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" - } - } - } -} diff --git a/ci/nomad-run-env-job.sh b/ci/nomad-run-env-job.sh new file mode 100755 index 0000000..01f9184 --- /dev/null +++ b/ci/nomad-run-env-job.sh @@ -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