fix: pass sample env when loading recipe

Closes coop-cloud/organising#176.
This commit is contained in:
decentral1se 2021-10-02 23:00:09 +02:00
parent 46e67fa420
commit 8cc0a350e6
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 22 additions and 8 deletions

View File

@ -3,18 +3,20 @@ package compose
import (
"fmt"
"io/ioutil"
"path"
"path/filepath"
"strings"
"coopcloud.tech/abra/pkg/client/stack"
loader "coopcloud.tech/abra/pkg/client/stack"
"coopcloud.tech/abra/pkg/config"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/distribution/reference"
"github.com/sirupsen/logrus"
)
// UpdateTag updates an image tag in-place on file system local compose files.
func UpdateTag(pattern, image, tag string) error {
func UpdateTag(pattern, image, tag, recipeName string) error {
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return err
@ -24,8 +26,14 @@ func UpdateTag(pattern, image, tag string) error {
for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}}
emptyEnv := make(map[string]string)
compose, err := loader.LoadComposefile(opts, emptyEnv)
envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample")
sampleEnv, err := config.ReadEnv(envSamplePath)
if err != nil {
return err
}
compose, err := loader.LoadComposefile(opts, sampleEnv)
if err != nil {
return err
}
@ -74,7 +82,7 @@ func UpdateTag(pattern, image, tag string) error {
}
// UpdateLabel updates a label in-place on file system local compose files.
func UpdateLabel(pattern, serviceName, label string) error {
func UpdateLabel(pattern, serviceName, label, recipeName string) error {
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return err
@ -84,8 +92,14 @@ func UpdateLabel(pattern, serviceName, label string) error {
for _, composeFile := range composeFiles {
opts := stack.Deploy{Composefiles: []string{composeFile}}
emptyEnv := make(map[string]string)
compose, err := loader.LoadComposefile(opts, emptyEnv)
envSamplePath := path.Join(config.ABRA_DIR, "apps", recipeName, ".env.sample")
sampleEnv, err := config.ReadEnv(envSamplePath)
if err != nil {
return err
}
compose, err := loader.LoadComposefile(opts, sampleEnv)
if err != nil {
return err
}

View File

@ -26,7 +26,7 @@ type Recipe struct {
// UpdateLabel updates a recipe label
func (r Recipe) UpdateLabel(serviceName, label string) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
if err := compose.UpdateLabel(pattern, serviceName, label); err != nil {
if err := compose.UpdateLabel(pattern, serviceName, label, r.Name); err != nil {
return err
}
return nil
@ -35,7 +35,7 @@ func (r Recipe) UpdateLabel(serviceName, label string) error {
// UpdateTag updates a recipe tag
func (r Recipe) UpdateTag(image, tag string) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
if err := compose.UpdateTag(pattern, image, tag); err != nil {
if err := compose.UpdateTag(pattern, image, tag, r.Name); err != nil {
return err
}
return nil