Skip to content

Commit

Permalink
Update Docker Compose file on start command
Browse files Browse the repository at this point in the history
This change makes sure that the docker-compose.yml is not only written
on "setup" but also on every "start". This way, users don't need to
run setup again after a Local Beach upgrade in order to get the latest
changes provided to docker-compose.yml.
  • Loading branch information
robertlemke committed Sep 10, 2021
1 parent 8430125 commit e6c28ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/beach/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func retrieveCloudStorageCredentials(instanceIdentifier string, projectNamespace
}

if len(bucketName) == 0 {
log.Debug("Received the following output while fetching BEACH_GOOGLE_CLOUD_STORAGE_* variables:")
log.Debug(output)
return errors.New("could not determine cloud storage bucket name from instance variables"), "", []byte("")
}
log.Debug("Using cloud storage bucket " + bucketName)
Expand Down
17 changes: 17 additions & 0 deletions cmd/beach/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
"github.com/flownative/localbeach/pkg/path"
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -107,6 +108,22 @@ func startLocalBeach() error {
}

if len(nginxStatusOutput) == 0 || len(databaseStatusOutput) == 0 {
composeFileContent := readFileFromAssets("local-beach/docker-compose.yml")
composeFileContent = strings.ReplaceAll(composeFileContent, "{{databasePath}}", path.Database)
composeFileContent = strings.ReplaceAll(composeFileContent, "{{certificatesPath}}", path.Certificates)

destination, err := os.Create(filepath.Join(path.Base, "docker-compose.yml"))
if err != nil {
log.Error("failed creating docker-compose.yml: ", err)
} else {
_, err = destination.WriteString(composeFileContent)
if err != nil {
log.Error(err)
}

}
_ = destination.Close()

log.Info("Starting reverse proxy and database server ...")
commandArgs := []string{"-f", path.Base + "docker-compose.yml", "up", "--remove-orphans", "-d"}
err = exec.RunInteractiveCommand("docker-compose", commandArgs)
Expand Down

0 comments on commit e6c28ab

Please sign in to comment.