refactor: move herokuish app cache from the filesystem into a docker volume

This simplifies cache referencing and also paves the way for removing more from the app git directory.

Refs #1558
This commit is contained in:
Jose Diaz-Gonzalez
2022-11-28 02:24:27 -05:00
parent ce0177967d
commit 40b20e0c08
13 changed files with 126 additions and 50 deletions

View File

@@ -203,7 +203,7 @@ func DockerCleanup(appName string, forceCleanup bool) error {
containerIDs := append(exitedContainerIDs, deadContainerIDs...)
if len(containerIDs) > 0 {
removeContainers(containerIDs)
DockerRemoveContainers(containerIDs)
}
// delete dangling images
@@ -351,21 +351,18 @@ func VerifyImage(image string) bool {
return imageCmd.Execute()
}
func listContainers(status string, appName string) ([]string, error) {
// DockerFilterContainers returns a slice of container IDs based on the passed in filters
func DockerFilterContainers(filters []string) ([]string, error) {
command := []string{
DockerBin(),
"container",
"list",
"--quiet",
"--all",
"--filter",
fmt.Sprintf("status=%v", status),
"--filter",
fmt.Sprintf("label=%v", os.Getenv("DOKKU_CONTAINER_LABEL")),
}
if appName != "" {
command = append(command, []string{"--filter", fmt.Sprintf("label=com.dokku.app-name=%v", appName)}...)
for _, filter := range filters {
command = append(command, "--filter", filter)
}
var stderr bytes.Buffer
@@ -382,6 +379,18 @@ func listContainers(status string, appName string) ([]string, error) {
return output, nil
}
func listContainers(status string, appName string) ([]string, error) {
filters := []string{
fmt.Sprintf("status=%v", status),
fmt.Sprintf("label=%v", os.Getenv("DOKKU_CONTAINER_LABEL")),
}
if appName != "" {
filters = append(filters, fmt.Sprintf("label=com.dokku.app-name=%v", appName))
}
return DockerFilterContainers(filters)
}
func pruneUnusedImages(appName string) {
command := []string{
DockerBin(),
@@ -400,7 +409,8 @@ func pruneUnusedImages(appName string) {
pruneCmd.Execute()
}
func removeContainers(containerIDs []string) {
// DockerRemoveContainers will call `docker container rm` on the specified containers
func DockerRemoveContainers(containerIDs []string) {
command := []string{
DockerBin(),
"container",