Allow using a local Docker image, e.g., for tests
This commit is contained in:

committed by
Sebastian Serth

parent
15b9117382
commit
7454e577e4
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -120,6 +120,7 @@ jobs:
|
|||||||
POSEIDON_AWS_ENABLED: true
|
POSEIDON_AWS_ENABLED: true
|
||||||
POSEIDON_AWS_ENDPOINT: ${{ secrets.POSEIDON_AWS_ENDPOINT }}
|
POSEIDON_AWS_ENDPOINT: ${{ secrets.POSEIDON_AWS_ENDPOINT }}
|
||||||
POSEIDON_AWS_FUNCTIONS: ${{ secrets.POSEIDON_AWS_FUNCTIONS }}
|
POSEIDON_AWS_FUNCTIONS: ${{ secrets.POSEIDON_AWS_FUNCTIONS }}
|
||||||
|
POSEIDON_NOMAD_DISABLEFORCEPULL: true
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -42,6 +42,8 @@ nomad:
|
|||||||
keyfile: ./poseidon.key
|
keyfile: ./poseidon.key
|
||||||
# Nomad namespace to use. If unset, 'default' is used
|
# Nomad namespace to use. If unset, 'default' is used
|
||||||
namespace: poseidon
|
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:
|
aws:
|
||||||
# Specifies whether AWS should be used as executor.
|
# Specifies whether AWS should be used as executor.
|
||||||
|
@ -42,7 +42,8 @@ var (
|
|||||||
CertFile: "",
|
CertFile: "",
|
||||||
KeyFile: "",
|
KeyFile: "",
|
||||||
},
|
},
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
|
DisableForcePull: false,
|
||||||
},
|
},
|
||||||
AWS: AWS{
|
AWS: AWS{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
@ -88,12 +89,13 @@ func (s *server) URL() *url.URL {
|
|||||||
|
|
||||||
// Nomad configures the used Nomad cluster.
|
// Nomad configures the used Nomad cluster.
|
||||||
type Nomad struct {
|
type Nomad struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
Address string
|
Address string
|
||||||
Port int
|
Port int
|
||||||
Token string
|
Token string
|
||||||
TLS TLS
|
TLS TLS
|
||||||
Namespace string
|
Namespace string
|
||||||
|
DisableForcePull bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL returns the URL for the configured Nomad cluster.
|
// URL returns the URL for the configured Nomad cluster.
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
nomadApi "github.com/hashicorp/nomad/api"
|
nomadApi "github.com/hashicorp/nomad/api"
|
||||||
|
"github.com/openHPI/poseidon/internal/config"
|
||||||
"github.com/openHPI/poseidon/pkg/dto"
|
"github.com/openHPI/poseidon/pkg/dto"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -146,7 +147,11 @@ func FindAndValidateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task {
|
|||||||
func SetForcePullFlag(job *nomadApi.Job, value bool) {
|
func SetForcePullFlag(job *nomadApi.Job, value bool) {
|
||||||
taskGroup := FindAndValidateDefaultTaskGroup(job)
|
taskGroup := FindAndValidateDefaultTaskGroup(job)
|
||||||
task := FindAndValidateDefaultTask(taskGroup)
|
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.
|
// IsEnvironmentTemplateID checks if the passed job id belongs to a template job.
|
||||||
|
@ -2,6 +2,7 @@ package nomad
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
nomadApi "github.com/hashicorp/nomad/api"
|
nomadApi "github.com/hashicorp/nomad/api"
|
||||||
|
"github.com/openHPI/poseidon/internal/config"
|
||||||
"github.com/openHPI/poseidon/pkg/dto"
|
"github.com/openHPI/poseidon/pkg/dto"
|
||||||
"github.com/openHPI/poseidon/tests/helpers"
|
"github.com/openHPI/poseidon/tests/helpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestIsEnvironmentTemplateID(t *testing.T) {
|
||||||
assert.True(t, IsEnvironmentTemplateID("template-42"))
|
assert.True(t, IsEnvironmentTemplateID("template-42"))
|
||||||
assert.False(t, IsEnvironmentTemplateID("template-42-100"))
|
assert.False(t, IsEnvironmentTemplateID("template-42-100"))
|
||||||
|
Reference in New Issue
Block a user