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

Commit

Permalink
Merge branch 'dev' into fix/container-environment-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sellooh committed Oct 15, 2024
2 parents fe5c75f + b96c99f commit 3d67f7f
Show file tree
Hide file tree
Showing 342 changed files with 9,821 additions and 2,219 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion cmd/sst/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func CmdInit(cli *cli.Cli) error {
case slices.ContainsFunc(hints, func(s string) bool { return strings.HasPrefix(s, "astro.config") }):
fmt.Println(" Astro detected. This will...")
fmt.Println(" - create an sst.config.ts")
fmt.Println(" - modify the tsconfig.json")
fmt.Println(" - add sst to package.json")
template = "astro"
break
Expand Down Expand Up @@ -110,7 +111,9 @@ func CmdInit(cli *cli.Cli) error {
template = "remix"
break

case slices.ContainsFunc(hints, func(s string) bool { return (strings.HasPrefix(s, "vite.config") && fileContains(s, "@analogjs/platform")) }):
case slices.ContainsFunc(hints, func(s string) bool {
return (strings.HasPrefix(s, "vite.config") && fileContains(s, "@analogjs/platform"))
}):
fmt.Println(" Analog detected. This will...")
fmt.Println(" - create an sst.config.ts")
fmt.Println(" - add sst to package.json")
Expand Down
46 changes: 29 additions & 17 deletions cmd/sst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/sst/ion/cmd/sst/mosaic/errors"
"github.com/sst/ion/cmd/sst/mosaic/ui"
"github.com/sst/ion/internal/util"
"github.com/sst/ion/pkg/flag"
"github.com/sst/ion/pkg/global"
"github.com/sst/ion/pkg/project"
"github.com/sst/ion/pkg/project/provider"
Expand Down Expand Up @@ -73,7 +74,7 @@ func main() {
slog.Error("exited with error", "err", err)
// check if context cancelled error
if err != context.Canceled {
ui.Error("Unexpected error occurred. Please check the logs in .sst/log/sst.log")
ui.Error("Unexpected error occurred. Please run with --print-logs or check .sst/log/sst.log if available.")
}
}
telemetry.Close()
Expand All @@ -87,7 +88,7 @@ func run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, syscall.SIGINT)
signal.Notify(interruptChannel, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-interruptChannel
slog.Info("interrupted")
Expand All @@ -102,23 +103,25 @@ func run() error {
return err
}

spin := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
spin.Suffix = " Updating dependencies..."
if global.NeedsPulumi() {
spin.Start()
err := global.InstallPulumi()
if err != nil {
return err
if !flag.SST_SKIP_DEPENDENCY_CHECK {
spin := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
spin.Suffix = " Updating dependencies..."
if global.NeedsPulumi() {
spin.Start()
err := global.InstallPulumi()
if err != nil {
return err
}
}
}
if global.NeedsBun() {
spin.Start()
err := global.InstallBun()
if err != nil {
return err
if global.NeedsBun() {
spin.Start()
err := global.InstallBun()
if err != nil {
return err
}
}
spin.Stop()
}
spin.Stop()
return c.Run()
}

Expand Down Expand Up @@ -216,6 +219,12 @@ var root = &cli.Command{
"Changing the stage will redeploy your app to a new stage with new resources. The old resources will still be around in the old stage.",
":::",
"",
"You can also use the `SST_STAGE` environment variable.",
"```bash frame=\"none\"",
"SST_STAGE=dev sst [command]",
"```",
"This can also be declared in a `.env` file or in the CLI session.",
"",
"If the stage is not passed in, then the CLI will:",
"",
"1. Use the username on the local machine.",
Expand Down Expand Up @@ -350,7 +359,8 @@ var root = &cli.Command{
"",
"1. Watch your `sst.config.ts` and deploy your app",
"2. Run your functions [Live](/docs/live/) and logs their invocations",
"3. Run the dev mode for components that have `dev.autostart` enabled",
"3. Start a [`sst tunnel`](#tunnel) session if your app has a VPC with `bastion` enabled",
"4. Run the dev mode for components that have `dev.autostart` enabled",
" - Components like `Service` and frontends like `Nextjs`, `Remix`, `Astro`, `StaticSite`, etc.",
" - It starts their `dev.command` in a separate pane",
" - And loads any [linked resources](/docs/linking) in the environment",
Expand Down Expand Up @@ -939,6 +949,8 @@ var root = &cli.Command{
"- General machine information, like the number of CPUs, OS, CI/CD environment, etc.",
"",
"This is completely optional and can be disabled at any time.",
"",
"You can also opt-out by setting an environment variable: `SST_TELEMETRY_DISABLED=1` or `DO_NOT_TRACK=1`.",
}, "\n"),
},
Children: []*cli.Command{
Expand Down
5 changes: 4 additions & 1 deletion cmd/sst/mosaic.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func CmdMosaic(c *cli.Cli) error {
}

if os.Getenv("SST_SERVER") != "" {
return util.NewReadableError(nil, "The dev command for this process does not look right. Check your dev script in package.json to make sure it is simply starting your process and not running `sst dev`. More info here: https://ion.sst.dev/docs/reference/cli/#dev")
return util.NewReadableError(nil, "The dev command for this process does not look right. Check your dev script in package.json to make sure it is simply starting your process and not running `sst dev`. More info here: https://sst.dev/docs/reference/cli/#dev")
}

p, err := c.InitProject()
Expand Down Expand Up @@ -240,6 +240,9 @@ func CmdMosaic(c *cli.Cli) error {
append([]string{"SST_CHILD=" + d.Name}, multiEnv...)...,
)
}
for range evt.Tunnels {
multi.AddProcess("tunnel", []string{currentExecutable, "tunnel", "--stage", p.App().Stage}, "⇌", "Tunnel", "", true, true, os.Environ()...)
}
break
}
}
Expand Down
41 changes: 41 additions & 0 deletions cmd/sst/mosaic/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"log/slog"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -225,6 +227,45 @@ func Start(

slog.Info("connected to iot")

go func() {
evts := bus.Subscribe(&FunctionLogEvent{}, &FunctionInvokedEvent{}, &FunctionResponseEvent{}, &FunctionErrorEvent{}, &FunctionBuildEvent{})
logs := map[string]*os.File{}

getLog := func(functionID string, requestID string) *os.File {
log, ok := logs[requestID]
if !ok {
path := p.PathLog("lambda/" + functionID + "/" + requestID)
os.MkdirAll(filepath.Dir(path), 0755)
log, _ = os.Create(path)
logs[requestID] = log
}
return log
}

for range evts {
for evt := range evts {
switch evt := evt.(type) {
case *FunctionInvokedEvent:
log := getLog(evt.FunctionID, evt.RequestID)
log.WriteString("invocation " + evt.RequestID + "\n")
log.WriteString(string(evt.Input))
log.WriteString("\n")
case *FunctionLogEvent:
getLog(evt.FunctionID, evt.RequestID).WriteString(evt.Line + "\n")
case *FunctionResponseEvent:
log := getLog(evt.FunctionID, evt.RequestID)
log.WriteString("response " + evt.RequestID + "\n")
log.WriteString(string(evt.Output))
log.WriteString("\n")
delete(logs, evt.RequestID)
case *FunctionErrorEvent:
getLog(evt.FunctionID, evt.RequestID).WriteString(evt.ErrorType + ": " + evt.ErrorMessage + "\n")
delete(logs, evt.RequestID)
}
}
}
}()

go func() {
workers := map[string]*WorkerInfo{}
workerEnv := map[string][]string{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sst/mosaic/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Transform(err error) error {
project.ErrVersionInvalid: "The version range defined in the config is invalid",
provider.ErrCloudflareMissingAccount: "The Cloudflare Account ID was not able to be determined from this token. Make sure it has permissions to fetch account information or you can set the CLOUDFLARE_DEFAULT_ACCOUNT_ID environment variable to the account id you want to use.",
server.ErrServerNotFound: "You are currently trying to run a frontend or some other process on its own - starting from v3 `sst dev` can bring up all of the processes in your application in a single window. Simply run `sst dev` in the same directory as your `sst.config.ts`. If this is not clear check out the monorepo example here: https://github.com/sst/ion/tree/dev/examples/aws-monorepo\n\n If you prefer running your processes in different terminal windows, you can start just the deploy process by running `sst dev --mode=basic` and then bring up your process with `sst dev -- <command>` in another terminal window.",
provider.ErrBucketMissing: "The state bucket is missing, it may have been accidentally deleted. Go to https://console.aws.amazon.com/systems-manager/parameters/%252Fsst%252Fbootstrap/description?region=us-east-1&tab=Table and check if the state bucket mentioned there exists. If it doesn't you can recreate it or delete the `/sst/bootstrap` key to force recreation.",
provider.ErrBucketMissing: "The state bucket is missing, it may have been accidentally deleted. Go to https://console.aws.amazon.com/systems-manager/parameters/%252Fsst%252Fbootstrap/description?tab=Table and check if the state bucket mentioned there exists. If it doesn't you can recreate it or delete the `/sst/bootstrap` key to force recreation.",
}

readable := []error{
Expand Down
5 changes: 0 additions & 5 deletions cmd/sst/mosaic/multiplexer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/gdamore/tcell/v2"
tcellterm "github.com/sst/ion/cmd/sst/mosaic/multiplexer/tcell-term"
"github.com/sst/ion/internal/util"
)

type vterm struct {
Expand Down Expand Up @@ -58,7 +57,6 @@ func (p *process) start() error {
p.cmd.Dir = p.dir
}
p.vt.Clear()
util.SetProcessGroupID(p.cmd)
err := p.vt.Start(p.cmd)
if err != nil {
return err
Expand All @@ -68,9 +66,6 @@ func (p *process) start() error {
}

func (p *process) Kill() {
if p.cmd != nil && p.cmd.Process != nil {
util.TerminateProcess(p.cmd.Process.Pid)
}
p.vt.Close()
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/sst/mosaic/multiplexer/tcell-term/vt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"log"
"log/slog"
"os"
"os/exec"
"runtime/debug"
Expand Down Expand Up @@ -460,8 +461,9 @@ func (vt *VT) Close() {
vt.mu.Lock()
defer vt.mu.Unlock()
if vt.cmd != nil && vt.cmd.Process != nil {
vt.cmd.Process.Kill()
vt.cmd.Wait()
slog.Info("killing process", "pid", vt.cmd.Process.Pid)
vt.cmd.Process.Signal(syscall.SIGTERM)
slog.Info("process killed")
}
vt.pty.Close()
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/sst/mosaic/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ func (u *UI) Event(unknown interface{}) {
u.println(TEXT_NORMAL.Render(" " + line))
}
for i, line := range status.Help {
if i == 0 { u.println() }
if i == 0 {
u.println()
}
u.println(TEXT_NORMAL.Render(" " + line))
}
importDiffs, ok := evt.ImportDiffs[status.URN]
Expand Down
Loading

0 comments on commit 3d67f7f

Please sign in to comment.