forked from toolshed/abra
feat: recipe sync
This commit is contained in:
@ -271,15 +271,59 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync
|
||||
}
|
||||
|
||||
var recipeSyncCommand = &cli.Command{
|
||||
Name: "sync",
|
||||
Usage: "Generate recipe labels and publish tags",
|
||||
Name: "sync",
|
||||
Usage: "Generate recipe labels",
|
||||
Description: `
|
||||
This command will generate labels for each service which correspond to the
|
||||
following format:
|
||||
|
||||
coop-cloud.${STACK_NAME}.${SERVICE_NAME}.version=${IMAGE_TAG}-${IMAGE_DIGEST}
|
||||
|
||||
The <recipe> configuration will be updated on the local file system. These
|
||||
labels are consumed by abra in other command invocations and used to determine
|
||||
the versioning metadata of up-and-running containers are.
|
||||
`,
|
||||
ArgsUsage: "<recipe>",
|
||||
Action: func(c *cli.Context) error {
|
||||
recipe := c.Args().First()
|
||||
if recipe == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
||||
}
|
||||
// TODO: part 2 of https://git.coopcloud.tech/coop-cloud/go-abra/issues/39#issuecomment-8066
|
||||
|
||||
compose, err := config.GetAppComposeFiles(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
hasAppService := false
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
hasAppService = true
|
||||
}
|
||||
}
|
||||
|
||||
if !hasAppService {
|
||||
logrus.Fatal(fmt.Sprintf("No 'app' service defined in '%s', cannot proceed", recipe))
|
||||
}
|
||||
|
||||
for _, service := range compose.Services {
|
||||
img, _ := reference.ParseNormalizedNamed(service.Image)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
digest, err := client.GetTagDigest(img)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
tag := img.(reference.NamedTagged).Tag()
|
||||
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s-%s", service.Name, tag, digest)
|
||||
if err := config.UpdateAppComposeLabel(recipe, service.Name, label); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user