feat(discovery): add Image and ServiceID fields to Job for swarm support
This commit is contained in:
@@ -15,6 +15,12 @@ type Job struct {
|
|||||||
Service string
|
Service string
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
ConfigFiles []string
|
ConfigFiles []string
|
||||||
|
// Image is the full image reference the update request asked for.
|
||||||
|
// Compose jobs ignore it (compose.yml already pins the reference to
|
||||||
|
// pull); Swarm jobs need it to know what to set on the service spec.
|
||||||
|
Image string
|
||||||
|
// ServiceID is the Swarm service ID. Empty for Compose jobs.
|
||||||
|
ServiceID string
|
||||||
// Refused is true when the WorkingDir falls outside STACKS_ROOT.
|
// Refused is true when the WorkingDir falls outside STACKS_ROOT.
|
||||||
// The job is returned so the caller can surface a per-job "refused"
|
// The job is returned so the caller can surface a per-job "refused"
|
||||||
// result, but it MUST NOT be executed.
|
// result, but it MUST NOT be executed.
|
||||||
@@ -74,6 +80,7 @@ func (d *Discovery) FindJobs(ctx context.Context, image string) ([]Job, error) {
|
|||||||
Service: cl.Service,
|
Service: cl.Service,
|
||||||
WorkingDir: cl.WorkingDir,
|
WorkingDir: cl.WorkingDir,
|
||||||
ConfigFiles: cl.ConfigFiles,
|
ConfigFiles: cl.ConfigFiles,
|
||||||
|
Image: image,
|
||||||
Refused: refused,
|
Refused: refused,
|
||||||
RefusedReason: reason,
|
RefusedReason: reason,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -153,3 +153,20 @@ func TestFindJobs_NonComposeContainerIsSkipped(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, jobs)
|
require.Empty(t, jobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFindJobs_PopulatesImageField(t *testing.T) {
|
||||||
|
fake := &fakeDockerClient{containers: []types.Container{
|
||||||
|
mkContainer("registry.example.com/myapp:v1", mkComposeLabels(
|
||||||
|
"myapp-prod", "web",
|
||||||
|
"/home/shcizo/self-hosted/myapp-prod",
|
||||||
|
"/home/shcizo/self-hosted/myapp-prod/docker-compose.yml",
|
||||||
|
true,
|
||||||
|
)),
|
||||||
|
}}
|
||||||
|
d := discovery.New(fake, "/home/shcizo/self-hosted", "se.shcizo.auto-update")
|
||||||
|
jobs, err := d.FindJobs(context.Background(), "registry.example.com/myapp")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, jobs, 1)
|
||||||
|
require.Equal(t, "registry.example.com/myapp", jobs[0].Image)
|
||||||
|
require.Empty(t, jobs[0].ServiceID)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user