diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d2b808..eb5bda1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,6 +120,7 @@ jobs: POSEIDON_AWS_ENABLED: true POSEIDON_AWS_ENDPOINT: ${{ secrets.POSEIDON_AWS_ENDPOINT }} POSEIDON_AWS_FUNCTIONS: ${{ secrets.POSEIDON_AWS_FUNCTIONS }} + POSEIDON_NOMAD_DISABLEFORCEPULL: true steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/configuration.example.yaml b/configuration.example.yaml index b3d0097..a951146 100644 --- a/configuration.example.yaml +++ b/configuration.example.yaml @@ -42,6 +42,8 @@ nomad: keyfile: ./poseidon.key # Nomad namespace to use. If unset, 'default' is used namespace: poseidon + # Prefer local Docker images over pulling them from a registry. Images with the `latest` tag will always be force pulled by Nomad regardless of this configuration. + disableforcepull: true aws: # Specifies whether AWS should be used as executor. diff --git a/internal/config/config.go b/internal/config/config.go index 6baa8e8..64a3f54 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -42,7 +42,8 @@ var ( CertFile: "", KeyFile: "", }, - Namespace: "default", + Namespace: "default", + DisableForcePull: false, }, AWS: AWS{ Enabled: false, @@ -88,12 +89,13 @@ func (s *server) URL() *url.URL { // Nomad configures the used Nomad cluster. type Nomad struct { - Enabled bool - Address string - Port int - Token string - TLS TLS - Namespace string + Enabled bool + Address string + Port int + Token string + TLS TLS + Namespace string + DisableForcePull bool } // URL returns the URL for the configured Nomad cluster. diff --git a/internal/nomad/job.go b/internal/nomad/job.go index 6bdfeda..e65e187 100644 --- a/internal/nomad/job.go +++ b/internal/nomad/job.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" nomadApi "github.com/hashicorp/nomad/api" + "github.com/openHPI/poseidon/internal/config" "github.com/openHPI/poseidon/pkg/dto" "strconv" "strings" @@ -146,7 +147,11 @@ func FindAndValidateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task { func SetForcePullFlag(job *nomadApi.Job, value bool) { taskGroup := FindAndValidateDefaultTaskGroup(job) task := FindAndValidateDefaultTask(taskGroup) - task.Config["force_pull"] = value + if config.Config.Nomad.DisableForcePull { + task.Config["force_pull"] = false + } else { + task.Config["force_pull"] = value + } } // IsEnvironmentTemplateID checks if the passed job id belongs to a template job. diff --git a/internal/nomad/job_test.go b/internal/nomad/job_test.go index 86f9863..f6ddc9f 100644 --- a/internal/nomad/job_test.go +++ b/internal/nomad/job_test.go @@ -2,6 +2,7 @@ package nomad import ( nomadApi "github.com/hashicorp/nomad/api" + "github.com/openHPI/poseidon/internal/config" "github.com/openHPI/poseidon/pkg/dto" "github.com/openHPI/poseidon/tests/helpers" "github.com/stretchr/testify/assert" @@ -96,6 +97,27 @@ func TestFindOrCreateTask(t *testing.T) { }) } +func TestSetForcePullFlag(t *testing.T) { + _, job := helpers.CreateTemplateJob() + taskGroup := FindAndValidateDefaultTaskGroup(job) + task := FindAndValidateDefaultTask(taskGroup) + + t.Run("Ignoring passed value if DisableForcePull", func(t *testing.T) { + config.Config.Nomad.DisableForcePull = true + SetForcePullFlag(job, true) + assert.Equal(t, false, task.Config["force_pull"]) + }) + + t.Run("Using passed value if not DisableForcePull", func(t *testing.T) { + config.Config.Nomad.DisableForcePull = false + SetForcePullFlag(job, true) + assert.Equal(t, true, task.Config["force_pull"]) + + SetForcePullFlag(job, false) + assert.Equal(t, false, task.Config["force_pull"]) + }) +} + func TestIsEnvironmentTemplateID(t *testing.T) { assert.True(t, IsEnvironmentTemplateID("template-42")) assert.False(t, IsEnvironmentTemplateID("template-42-100"))