-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generator pass to add Watchtower (#247)
* Add new pass to add Watchtower to the stack * Fix tests * Add test for GetAllLabels * Extend * Fix bug * Extend * Fix bug * Fix test * Optimize service tester script * Add more tests * Fix React template
- Loading branch information
1 parent
0a294f6
commit d252645
Showing
19 changed files
with
473 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package pass | ||
|
||
import ( | ||
"compose-generator/model" | ||
|
||
"github.com/compose-spec/compose-go/types" | ||
) | ||
|
||
func GenerateAddWatchtower( | ||
project *model.CGProject, | ||
selectedTemplates *model.SelectedTemplates, | ||
config *model.GenerateConfig, | ||
) { | ||
// Ask the user if watchtower should be added to the project | ||
pel() | ||
templates := selectedTemplates.GetAllRef() | ||
addWatchtower := false | ||
if config == nil || !config.FromFile { | ||
addWatchtower = yesNoQuestion("Do you want to add Watchtower to check for new image versions?", false) | ||
} | ||
if addWatchtower { | ||
infoLogger.Println("Adding Watchtower to the project ...") | ||
// Ask which services should be equipped with image update detection | ||
allLabels := []string{} | ||
preselectedLabels := []string{} | ||
for _, template := range templates { | ||
allLabels = append(allLabels, template.Label) | ||
if template.AutoUpdated { | ||
preselectedLabels = append(preselectedLabels, template.Label) | ||
template.AutoUpdated = false | ||
} | ||
} | ||
// Ask the user which of the services should be auto-updated | ||
selectedIndices := multiSelectMenuQuestionIndex("For which services do you want to add Watchtower?", allLabels, preselectedLabels) | ||
for _, i := range selectedIndices { | ||
template := templates[i] | ||
template.AutoUpdated = true | ||
} | ||
|
||
// Add watchtower service | ||
project.Composition.Services = append(project.Composition.Services, types.ServiceConfig{ | ||
Name: "companion-watchtower", | ||
Image: "containrrr/watchtower:latest", | ||
Restart: types.RestartPolicyUnlessStopped, | ||
Volumes: []types.ServiceVolumeConfig{ | ||
{ | ||
Type: types.VolumeTypeBind, | ||
Source: "/var/run/docker.sock", | ||
Target: "/var/run/docker.sock", | ||
}, | ||
}, | ||
DependsOn: types.DependsOnConfig{ | ||
model.TemplateTypeFrontend: types.ServiceDependency{}, | ||
model.TemplateTypeBackend: types.ServiceDependency{}, | ||
model.TemplateTypeDatabase: types.ServiceDependency{}, | ||
model.TemplateTypeDbAdmin: types.ServiceDependency{}, | ||
model.TemplateTypeProxy: types.ServiceDependency{}, | ||
model.TemplateTypeTlsHelper: types.ServiceDependency{}, | ||
}, | ||
Command: types.ShellCommand{"--interval", "30"}, | ||
}) | ||
infoLogger.Println("Adding Watchtower to the project .. (done)") | ||
} else { | ||
// Remove all auto-updated flags | ||
for _, template := range templates { | ||
template.AutoUpdated = false | ||
} | ||
} | ||
} |
Oops, something went wrong.