Skip to content

Commit

Permalink
Fix: issues with env file encryption leading to failed launch/depoloy
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyMoud committed Oct 13, 2024
1 parent 9ba6ed5 commit 3ecc864
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Run sidekick launch`)
envCmd := exec.Command("sh", "-s", "-", viper.Get("publicKey").(string), fmt.Sprintf("./%s", appConfig.Env.File))
envCmd.Stdin = strings.NewReader(utils.EnvEncryptionScript)
if envCmdErr := envCmd.Run(); envCmdErr != nil {
panic(envCmdErr)
pterm.Error.Printfln("Something went wrong handling your env file: %s", envCmdErr)
os.Exit(1)
}
encryptSync := exec.Command("rsync", "encrypted.env", fmt.Sprintf("%s@%s:%s", "sidekick", viper.Get("serverAddress").(string), fmt.Sprintf("./%s", appConfig.Name)))
encryptSync.Run()
Expand Down
24 changes: 21 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"strings"

"github.com/mightymoud/sidekick/render"
Expand Down Expand Up @@ -129,7 +130,8 @@ var initCmd = &cobra.Command{
}

multi := pterm.DefaultMultiPrinter
rootLoginSpinner, _ := pterm.DefaultSpinner.Start("Logging in with root")
localReqsChecks, _ := utils.GetSpinner().WithWriter(multi.NewWriter()).Start("Setting up your local env")
rootLoginSpinner, _ := utils.GetSpinner().WithWriter(multi.NewWriter()).Start("Logging in with root")
stage0Spinner, _ := utils.GetSpinner().WithWriter(multi.NewWriter()).Start("Adding user Sidekick")
sidekickLoginSpinner, _ := utils.GetSpinner().WithWriter(multi.NewWriter()).Start("Logging into with sidekick user")
stage1Spinner, _ := utils.GetSpinner().WithWriter(multi.NewWriter()).Start("Setting up VPS")
Expand All @@ -138,6 +140,23 @@ var initCmd = &cobra.Command{
pterm.Println()
multi.Start()

localReqsChecks.Sequence = []string{"▀ ", " ▀", " ▄", "▄ "}
brewCheckCmd := exec.Command("brew", "-v")
_, brewCheckCmdErr := brewCheckCmd.CombinedOutput()
if brewCheckCmdErr != nil {
log.Fatalf("Failed to run brew. Brew is required to use Sidekick: %s", brewCheckCmd)
os.Exit(1)
}

installSopsCmd := exec.Command("brew", "install", "sops")
_, installSopsCmdErr := installSopsCmd.CombinedOutput()
if installSopsCmdErr != nil {
log.Fatalf("Failed to install Sops. Sops is need to encrypt your local env: %s", installSopsCmd)
os.Exit(1)
}

localReqsChecks.Success("Installed local requirements successfully")

rootLoginSpinner.Success("Logged in successfully!")

stage0Spinner.Sequence = []string{"▀ ", " ▀", " ▄", "▄ "}
Expand All @@ -153,7 +172,6 @@ var initCmd = &cobra.Command{
hasSidekickUser = true
}
}

}
if !hasSidekickUser && loggedInUser == "root" {
if err := utils.RunStage(sshClient, utils.UsersetupStage); err != nil {
Expand All @@ -168,7 +186,7 @@ var initCmd = &cobra.Command{
sidekickSshClient, err := utils.Login(server, "sidekick")
if err != nil {
sidekickLoginSpinner.Fail("Something went wrong logging in to your VPS")
// panic(err)
log.Fatal(err)
}
sidekickLoginSpinner.Success("Logged in successfully with new user!")

Expand Down
6 changes: 5 additions & 1 deletion cmd/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,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)
envHandleErr := utils.HandleEnvFile(envFileName, envVariables, &dockerEnvProperty, &envFileChecksum)
if envHandleErr != nil {
pterm.Error.Printfln("Something went wrong handling your env file: %s", envHandleErr)
os.Exit(1)
}
defer os.Remove("encrypted.env")
} else {
pterm.Info.Println("No env file detected - Skipping env parsing")
Expand Down

0 comments on commit 3ecc864

Please sign in to comment.