Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Add flag for exposing session ports. #365

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Add flag for exposing session ports. #365

merged 1 commit into from
Apr 21, 2022

Conversation

codeviking
Copy link
Contributor

@codeviking codeviking commented Apr 21, 2022

This adds the --port flag to the beaker session create
command.

This codebase doesn't have any tests. So I tested manually. I started
a local executor, then build a local beaker CLI and started a session
like so:

❯ ./beaker session create \
        --node 01G16Y53QY0YYNYPDNRYJ1A36T \
        --image beaker://sams/cuda11.2-ubuntu20.04 \
        --port 8888

This worked! The docker ps command shows the container, with a random port
bound to container port 8888:

❯ docker ps
CONTAINER ID   IMAGE                                                     COMMAND     CREATED          STATUS          PORTS                     NAMES
0a63319a448d   gcr.io/ai2-beaker-core/uploads/dev/c7g9tvj56ghj02m8t4g0   "bash -l"   27 seconds ago   Up 25 seconds   0.0.0.0:55106->8888/tcp   session-01g16zmjee54a35xm9s5f7snkn

I tested invalid ports (overflow, 0, etc). Everything seemed to work.

https://github.com/allenai/beaker-service/issues/2009

This adds the `--port` flag to the `beaker session create`
command.
cmd.Flags().Float64Var(&cpus, "cpus", 0, "Minimum CPU cores to reserve, e.g. 7.5")
cmd.Flags().IntVar(&gpus, "gpus", 0, "Minimum number of GPUs to reserve")
cmd.Flags().StringVar(&memory, "memory", "", "Minimum memory to reserve, e.g. 6.5GiB")
cmd.Flags().StringVar(&sharedMemory, "shared-memory", "", "Shared memory (size of /dev/shm), e.g. 1GiB")
cmd.Flags().StringSliceVar(

Choose a reason for hiding this comment

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

thanks for the roadmap for adding preemptible to beaker flags :)

Copy link

@katepanter katepanter left a comment

Choose a reason for hiding this comment

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

this is really cool, Sam!

@@ -178,6 +185,17 @@ To pass flags, use "--" e.g. "create -- ls -l"`,
})
}

var tcpPorts []api.TCPPort
for _, p := range ports {
pp, err := strconv.ParseInt(p, 10, 32)
Copy link
Member

Choose a reason for hiding this comment

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

lol, I love that go has 3 parameters for ParseInt.

Copy link
Contributor Author

@codeviking codeviking Apr 21, 2022

Choose a reason for hiding this comment

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

Yea, setting the bit size was surprising. Particularly when the type that's returned is int.

It'd be nice if it were a separate function, say, strconv.ParseInt32(). That way the returned type could be int32 and I wouldn't have to cast/convert things in code. But of course blows out the stdlib a bit. It's tricky!

/shrug

@codeviking codeviking merged commit 9229bfa into main Apr 21, 2022
@codeviking codeviking deleted the sams/ports branch April 21, 2022 21:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants