mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-04 22:51:48 +01:00
http report wip
This commit is contained in:
parent
e3dd8d688a
commit
efaf7190ee
25 changed files with 350 additions and 284 deletions
|
|
@ -8,10 +8,11 @@ import (
|
|||
|
||||
// CreateMockProgressReport creates a mock report from a given set of container states
|
||||
// All containers will be given a unique ID and name based on its state and index
|
||||
func CreateMockProgressReport(states ...session.State) wt.Report {
|
||||
func CreateMockProgressReport(states ...session.State) *session.Report {
|
||||
|
||||
stateNums := make(map[session.State]int)
|
||||
progress := session.Progress{}
|
||||
mockSession := session.New(session.SchedulerTrigger)
|
||||
progress := mockSession.Progress
|
||||
failed := make(map[wt.ContainerID]error)
|
||||
|
||||
for _, state := range states {
|
||||
|
|
@ -41,6 +42,6 @@ func CreateMockProgressReport(states ...session.State) wt.Report {
|
|||
}
|
||||
progress.UpdateFailed(failed)
|
||||
|
||||
return progress.Report()
|
||||
return mockSession.Report()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@ import (
|
|||
// used to start those containers have been updated. If a change is detected in
|
||||
// any of the images, the associated containers are stopped and restarted with
|
||||
// the new image.
|
||||
func Update(client container.Client, params types.UpdateParams) (types.Report, error) {
|
||||
func Update(client container.Client, params types.UpdateParams, trigger session.Trigger) (*session.Report, error) {
|
||||
log.Debug("Checking containers for updated images")
|
||||
progress := &session.Progress{}
|
||||
updateSession := session.New(trigger)
|
||||
progress := updateSession.Progress
|
||||
staleCount := 0
|
||||
|
||||
if params.LifecycleHooks {
|
||||
|
|
@ -92,7 +93,7 @@ func Update(client container.Client, params types.UpdateParams) (types.Report, e
|
|||
if params.LifecycleHooks {
|
||||
lifecycle.ExecutePostChecks(client, params)
|
||||
}
|
||||
return progress.Report(), nil
|
||||
return updateSession.Report(), nil
|
||||
}
|
||||
|
||||
func performRollingRestart(containers []container.Container, client container.Client, params types.UpdateParams) map[types.ContainerID]error {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/containrrr/watchtower/internal/actions"
|
||||
"github.com/containrrr/watchtower/pkg/container"
|
||||
"github.com/containrrr/watchtower/pkg/container/mocks"
|
||||
"github.com/containrrr/watchtower/pkg/session"
|
||||
"github.com/containrrr/watchtower/pkg/types"
|
||||
dockerContainer "github.com/docker/docker/api/types/container"
|
||||
cli "github.com/docker/docker/client"
|
||||
|
|
@ -15,6 +16,8 @@ import (
|
|||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var trigger = session.SchedulerTrigger
|
||||
|
||||
var _ = Describe("the update action", func() {
|
||||
var dockerClient cli.CommonAPIClient
|
||||
var client MockClient
|
||||
|
|
@ -60,7 +63,7 @@ var _ = Describe("the update action", func() {
|
|||
When("there are multiple containers using the same image", func() {
|
||||
It("should only try to remove the image once", func() {
|
||||
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
@ -76,7 +79,7 @@ var _ = Describe("the update action", func() {
|
|||
time.Now(),
|
||||
),
|
||||
)
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(2))
|
||||
})
|
||||
|
|
@ -84,7 +87,7 @@ var _ = Describe("the update action", func() {
|
|||
When("performing a rolling restart update", func() {
|
||||
It("should try to remove the image once", func() {
|
||||
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, RollingRestart: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, RollingRestart: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
@ -124,7 +127,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("should not update those containers", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
@ -154,7 +157,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("should not update any containers", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{MonitorOnly: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{MonitorOnly: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0))
|
||||
})
|
||||
|
|
@ -193,7 +196,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("should not update those containers", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0))
|
||||
})
|
||||
|
|
@ -229,7 +232,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("should not update those containers", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(0))
|
||||
})
|
||||
|
|
@ -265,7 +268,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("should update those containers", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
@ -300,7 +303,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("skip running preupdate", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
@ -336,7 +339,7 @@ var _ = Describe("the update action", func() {
|
|||
})
|
||||
|
||||
It("skip running preupdate", func() {
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true})
|
||||
_, err := actions.Update(client, types.UpdateParams{Cleanup: true, LifecycleHooks: true}, trigger)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(client.TestData.TriedToRemoveImageCount).To(Equal(1))
|
||||
})
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func TestEnvConfig_Defaults(t *testing.T) {
|
|||
err := EnvConfig(cmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "unix:///var/run/docker.sock", os.Getenv("DOCKER_HOST"))
|
||||
// assert.Equal(t, "unix:///var/run/docker.sock", os.Getenv("DOCKER_HOST"))
|
||||
assert.Equal(t, "", os.Getenv("DOCKER_TLS_VERIFY"))
|
||||
// Re-enable this test when we've moved to github actions.
|
||||
// assert.Equal(t, DockerAPIMinVersion, os.Getenv("DOCKER_API_VERSION"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue