Skip to content

Commit

Permalink
Merge 3f487f2 into ec683eb
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn authored Nov 4, 2024
2 parents ec683eb + 3f487f2 commit f9ee511
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
17 changes: 12 additions & 5 deletions deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
Dir.chdir("/usr/src/app")

DEPLOY_NOW = !get_env("DEPLOY_NOW").nil?
DEPLOY_CUSTOMIZE = !get_env("NO_DEPLOY_CUSTOMIZE")
DEPLOY_CUSTOMIZE_PATH = get_env("DEPLOY_CUSTOMIZE_PATH")
DEPLOY_CUSTOMIZE = !get_env("NO_DEPLOY_CUSTOMIZE") || !DEPLOY_CUSTOMIZE_PATH.nil?
DEPLOY_ONLY = !get_env("DEPLOY_ONLY").nil?
CREATE_AND_PUSH_BRANCH = !get_env("DEPLOY_CREATE_AND_PUSH_BRANCH").nil?
FLYIO_BRANCH_NAME = "flyio-new-files"
Expand Down Expand Up @@ -239,15 +240,21 @@

if DEPLOY_CUSTOMIZE
manifest = in_step Step::CUSTOMIZE do
cmd = "flyctl launch sessions create --session-path /tmp/session.json --manifest-path #{MANIFEST_PATH} --from-manifest #{MANIFEST_PATH}"
if DEPLOY_CUSTOMIZE_PATH.nil?
cmd = "flyctl launch sessions create --session-path /tmp/session.json --manifest-path #{MANIFEST_PATH} --from-manifest #{MANIFEST_PATH}"

exec_capture(cmd)
session = JSON.parse(File.read("/tmp/session.json"))
exec_capture(cmd)
session = JSON.parse(File.read("/tmp/session.json"))

artifact Artifact::SESSION, session
artifact Artifact::SESSION, session
end

cmd = "flyctl launch sessions finalize --session-path /tmp/session.json --manifest-path #{MANIFEST_PATH}"

if !DEPLOY_CUSTOMIZE_PATH.nil?
cmd += " --from-file #{DEPLOY_CUSTOMIZE_PATH}"
end

exec_capture(cmd)
manifest = JSON.parse(File.read("/tmp/manifest.json"))

Expand Down
56 changes: 37 additions & 19 deletions internal/command/launch/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func newSessions() *cobra.Command {
Description: "Path to write the manifest info to",
Default: "manifest.json",
},
flag.String{
Name: "from-file",
Description: "Path to a CLI session JSON file",
Default: "",
},
)

// not that useful anywhere else yet
Expand Down Expand Up @@ -192,14 +197,39 @@ func runSessionFinalize(ctx context.Context) (err error) {
io := iostreams.FromContext(ctx)
logger := logger.FromContext(ctx)

sessionBytes, err := os.ReadFile(flag.GetString(ctx, "session-path"))
if err != nil {
return err
}
var finalSession fly.CLISession

var session fly.CLISession
if err := json.Unmarshal(sessionBytes, &session); err != nil {
return err
if customizePath := flag.GetString(ctx, "from-file"); customizePath != "" {
sessionBytes, err := os.ReadFile(customizePath)
if err != nil {
return err
}

if err := json.Unmarshal(sessionBytes, &finalSession); err != nil {
return err
}
} else {
sessionBytes, err := os.ReadFile(flag.GetString(ctx, "session-path"))
if err != nil {
return err
}

var session fly.CLISession
if err := json.Unmarshal(sessionBytes, &session); err != nil {
return err
}

// FIXME: better timeout here
ctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
defer cancel()

finalSession, err = waitForCLISession(ctx, logger, io.ErrOut, session.ID)
switch {
case errors.Is(err, context.DeadlineExceeded):
return errors.New("session expired, please try again")
case err != nil:
return err
}
}

manifestBytes, err := os.ReadFile(flag.GetString(ctx, "manifest-path"))
Expand All @@ -219,18 +249,6 @@ func runSessionFinalize(ctx context.Context) (err error) {
warnedNoCcHa: true,
}

// FIXME: better timeout here
ctx, cancel := context.WithTimeout(ctx, 15*time.Minute)
defer cancel()

finalSession, err := waitForCLISession(ctx, logger, io.ErrOut, session.ID)
switch {
case errors.Is(err, context.DeadlineExceeded):
return errors.New("session expired, please try again")
case err != nil:
return err
}

// Hack because somewhere from between UI and here, the numbers get converted to strings
if err := patchNumbers(finalSession.Metadata, "vm_cpus", "vm_memory"); err != nil {
return err
Expand Down

0 comments on commit f9ee511

Please sign in to comment.