Skip to content

Commit

Permalink
Merge branch 'MightyMoud:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pythoninthegrass authored Sep 23, 2024
2 parents b3fcba5 + 88f7fe8 commit 7fcf887
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ to quickly create a Cobra application.`,
if utils.FileExists(fmt.Sprintf("./%s", envFileName)) {
hasEnvFile = true
pterm.Info.Printfln("Env file detected - Loading env vars from %s", envFileName)
res := utils.HandleEnvFile(envFileName, envVariables, dockerEnvProperty, &envFileChecksum)
res := utils.HandleEnvFile(envFileName, envVariables, &dockerEnvProperty, &envFileChecksum)
fmt.Println(res)
fmt.Println(dockerEnvProperty)
defer os.Remove("encrypted.env")
Expand Down
10 changes: 7 additions & 3 deletions cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var launchCmd = &cobra.Command{
os.Exit(1)
}

if utils.FileExists("./sidekick.yml") {
pterm.Error.Println("Sidekick config exits in this project.")
pterm.Info.Println("You can deploy a new version of your application with Sidekick deploy.")
os.Exit(1)
}

if utils.FileExists("./Dockerfile") {
pterm.Info.Println("Dockerfile detected - scanning file for details")
} else {
Expand Down Expand Up @@ -93,13 +99,11 @@ var launchCmd = &cobra.Command{
if utils.FileExists(fmt.Sprintf("./%s", envFileName)) {
hasEnvFile = true
pterm.Info.Printfln("Env file detected - Loading env vars from %s", envFileName)
utils.HandleEnvFile(envFileName, envVariables, dockerEnvProperty, &envFileChecksum)
utils.HandleEnvFile(envFileName, envVariables, &dockerEnvProperty, &envFileChecksum)
defer os.Remove("encrypted.env")
} else {
pterm.Info.Println("No env file detected - Skipping env parsing")
}
fmt.Println("Env is:")
fmt.Println(dockerEnvProperty)

// make a docker service
imageName := appName
Expand Down
2 changes: 1 addition & 1 deletion cmd/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ to quickly create a Cobra application.`,
dockerEnvProperty := []string{}
envFileChecksum := ""
if appConfig.Env.File != "" {
envErr := utils.HandleEnvFile(appConfig.Env.File, envVariables, dockerEnvProperty, &envFileChecksum)
envErr := utils.HandleEnvFile(appConfig.Env.File, envVariables, &dockerEnvProperty, &envFileChecksum)
if envErr != nil {
panic(envErr)
}
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func LoadAppConfig() (SidekickAppConfig, error) {
return appConfigFile, nil
}

func HandleEnvFile(envFileName string, envVariables []string, dockerEnvProperty []string, envFileChecksum *string) error {
func HandleEnvFile(envFileName string, envVariables []string, dockerEnvProperty *[]string, envFileChecksum *string) error {
envFileContent, envFileErr := os.ReadFile(fmt.Sprintf("./%s", envFileName))
if envFileErr != nil {
pterm.Error.Println("Unable to process your env file")
Expand All @@ -290,7 +290,7 @@ func HandleEnvFile(envFileName string, envVariables []string, dockerEnvProperty
}

for _, envVar := range envVariables {
dockerEnvProperty = append(dockerEnvProperty, fmt.Sprintf("%s=${%s}", envVar, envVar))
*dockerEnvProperty = append(*dockerEnvProperty, fmt.Sprintf("%s=${%s}", envVar, envVar))
}
// calculate and store the hash of env file to re-encrypt later on when changed
*envFileChecksum = fmt.Sprintf("%x", md5.Sum(envFileContent))
Expand Down

0 comments on commit 7fcf887

Please sign in to comment.