Remove images from earlier deploys after a successful deploy (closes #216)
Check / check (pull_request) Skipped
Check / check (pull_request) Skipped
After a successful deploy, upaas now removes the app's images other than the one the running container uses and the previous one, which rollback starts. Removing an image also removes the untagged images it was built on unless another image still needs them. Images left by other stages of a multi-stage build are not tied to the app and stay. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package deploy_test
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"sneak.berlin/go/upaas/internal/docker"
|
||||
"sneak.berlin/go/upaas/internal/models"
|
||||
"sneak.berlin/go/upaas/internal/service/deploy"
|
||||
)
|
||||
|
||||
const currentImage = "sha256:current"
|
||||
|
||||
func TestUnusedImages_KeepsCurrentAndRollbackImage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
app := &models.App{
|
||||
ImageID: sql.NullString{String: currentImage, Valid: true},
|
||||
PreviousImageID: sql.NullString{String: "sha256:previous", Valid: true},
|
||||
}
|
||||
images := []docker.ImageID{
|
||||
"sha256:oldest",
|
||||
"sha256:previous",
|
||||
"sha256:older",
|
||||
currentImage,
|
||||
}
|
||||
|
||||
assert.Equal(t,
|
||||
[]docker.ImageID{"sha256:oldest", "sha256:older"},
|
||||
deploy.UnusedImages(images, app),
|
||||
)
|
||||
}
|
||||
|
||||
func TestUnusedImages_FirstDeployHasNoRollbackImage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
app := &models.App{
|
||||
ImageID: sql.NullString{String: currentImage, Valid: true},
|
||||
}
|
||||
images := []docker.ImageID{currentImage, "sha256:failed"}
|
||||
|
||||
assert.Equal(t,
|
||||
[]docker.ImageID{"sha256:failed"},
|
||||
deploy.UnusedImages(images, app),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user