Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
mosaic: ensure that concurrent sst operations do not overwrite each
Browse files Browse the repository at this point in the history
other
  • Loading branch information
thdxr committed Jul 8, 2024
1 parent 5e7e748 commit e2fbb4d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pkg/js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package js
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"time"

esbuild "github.com/evanw/esbuild/pkg/api"
)
Expand All @@ -19,8 +21,8 @@ type EvalOptions struct {
}

func Build(input EvalOptions) (esbuild.BuildResult, error) {
outfile := filepath.Join(input.Dir, ".sst", "platform", "sst.config.mjs")
slog.Info("esbuild building")
outfile := filepath.Join(input.Dir, ".sst", "platform", fmt.Sprintf("sst.config.%v.mjs", time.Now().UnixMilli()))
slog.Info("esbuild building", outfile)

Check failure on line 25 in pkg/js/js.go

View workflow job for this annotation

GitHub Actions / goreleaser

call to slog.Info missing a final value
result := esbuild.Build(esbuild.BuildOptions{
Banner: map[string]string{
"js": `
Expand Down Expand Up @@ -82,3 +84,9 @@ func FormatError(input []esbuild.Message) string {
}
return strings.Join(lines, "\n")
}

func Cleanup(result esbuild.BuildResult) {
for _, file := range result.OutputFiles {
os.Remove(file.Path)
}
}
10 changes: 9 additions & 1 deletion pkg/project/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package project

import (
"encoding/json"
"fmt"
"log/slog"
"os"
"path/filepath"
Expand All @@ -11,7 +12,9 @@ import (

func (p *Project) CheckPlatform(version string) bool {
if version == "dev" {
return false
currentExecutable, _ := os.Executable()
info, _ := os.Stat(currentExecutable)
version = fmt.Sprint(info.ModTime().UnixMilli())
}
slog.Info("checking platform")
contents, err := os.ReadFile(filepath.Join(p.PathPlatformDir(), "version"))
Expand All @@ -30,6 +33,11 @@ func (p *Project) CopyPlatform(version string) error {
return err
}
p.lock = ProviderLock{}
if version == "dev" {
currentExecutable, _ := os.Executable()
info, _ := os.Stat(currentExecutable)
version = fmt.Sprint(info.ModTime().UnixMilli())
}
return os.WriteFile(filepath.Join(platformDir, "version"), []byte(version), 0644)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ console.log("~j" + JSON.stringify(mod.app({
if err != nil {
return nil, fmt.Errorf("%w%s", ErrBuildFailed, err)
}
defer js.Cleanup(buildResult)

slog.Info("evaluating config")
node := exec.Command("node", "--no-warnings", string(buildResult.OutputFiles[1].Path))
Expand Down
1 change: 1 addition & 0 deletions pkg/project/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func (s *stack) Run(ctx context.Context, input *StackInput) error {
})
return err
}
defer js.Cleanup(buildResult)
outfile := buildResult.OutputFiles[1].Path

if input.OnFiles != nil {
Expand Down

0 comments on commit e2fbb4d

Please sign in to comment.