Tinkerbell.Sandbox/releases/cmd/bump-version/envfile/envfile.go
Jacob Weinstock 6b841fee7c This simplifies the stand-up of a sandbox:
Only 2 main Vagrant calls are now needed (`vagrant up` and `vagrant up machine1`).
This PR only updates the Vagrant Virtualbox setup. The Vagrant Libvirt and Terraform
still need to be updated.

This uses docker-compose as the entry point for standing up the stack and makes the stand-up
of the sandbox more portal. Vagrant and Terraform are only responsible for standing up infrastructure
and then running docker-compose, not for running any glue scripts.

The docker-compose calls out to single-shot services to do all the glue required to get the fully
functional Tinkerbell stack up and running. All the single-shot services are idempotent.
This increases portability and the development iteration loop. This also simplifies the required
steps needed to get a fully functioning sandbox up and running.

This is intended to help people looking to get started by getting them to a provisioned
machine quicker and more easily.

Signed-off-by: Jacob Weinstock <jakobweinstock@gmail.com>
2021-08-09 08:04:06 -06:00

49 lines
979 B
Go

package envfile
import (
"fmt"
"sort"
"strings"
"github.com/joho/godotenv"
)
type EnvFile map[string]string
func ReadEnvFile(f string) (EnvFile, error) {
myEnv, err := godotenv.Read(f)
if err != nil {
return nil, err
}
return myEnv, nil
}
// Copied and modified from https://github.com/joho/godotenv
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
func Marshal(envMap map[string]string) (string, error) {
lines := make([]string, 0, len(envMap))
for k, v := range envMap {
lines = append(lines, fmt.Sprintf(`export %s="%s"`, k, doubleQuoteEscape(v)))
}
sort.Strings(lines)
return strings.Join(lines, "\n"), nil
}
func doubleQuoteEscape(line string) string {
for _, c := range doubleQuoteSpecialChars {
toReplace := "\\" + string(c)
if c == '\n' {
toReplace = `\n`
}
if c == '\r' {
toReplace = `\r`
}
line = strings.Replace(line, string(c), toReplace, -1)
}
return line
}
// End of the part copied from https://github.com/joho/godotenv