Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add startup script option #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func buildInstance(options *options.Options) (*computepb.Instance, error) {
Key: ptr.Ptr("ssh-keys"),
Value: ptr.Ptr("devpod:" + string(publicKey)),
},
{
Key: ptr.Ptr("startup-script"),
Value: ptr.Ptr(options.StartupScript),
},
},
},
MachineType: ptr.Ptr(fmt.Sprintf("projects/%s/zones/%s/machineTypes/%s", options.Project, options.Zone, options.MachineType)),
Expand Down
3 changes: 3 additions & 0 deletions hack/provider/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ options:
TAG:
description: A tag to attach to the instance.
default: "devpod"
STARTUP_SCRIPT:
description: A startup script to run on the VM.
default: ""
DISK_SIZE:
description: The disk size to use (GB).
default: "40"
Expand Down
5 changes: 5 additions & 0 deletions pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Options struct {
MachineType string
ServiceAccount string
PublicIP bool
StartupScript string
}

func FromEnv(withMachine bool) (*Options, error) {
Expand Down Expand Up @@ -59,6 +60,10 @@ func FromEnv(withMachine bool) (*Options, error) {
if err != nil {
return nil, err
}
retOptions.StartupScript, err = fromEnvOrError("STARTUP_SCRIPT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can make this optional by just reading os.Getenv("STARTUP_SCRIPT"). Right now it would fail if it's empty

if err != nil {
return nil, err
}

publicIp, err := fromEnvOrError("PUBLIC_IP_ENABLED")
if err != nil {
Expand Down