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

Use LINK_PORT variable if it's set #1370

Closed
wants to merge 7 commits into from
Closed

Use LINK_PORT variable if it's set #1370

wants to merge 7 commits into from

Conversation

mwarkentin
Copy link
Contributor

@mwarkentin mwarkentin commented Nov 3, 2016

This brings PORT up to parity with SCHEME, PATH, USERNAME, and PASSWORD.

Use Case

We are trying to use the official rabbitmq image for local development.

  • That image EXPOSEs multiple ports
  • Convox uses the first one exposed in docker inspect
  • It doesn't provide a way to set it explicitly like the other LINK_* environment variables can be used

TODO

This brings PORT up to parity with SCHEME, PATH, USERNAME, and PASSWORD.
@codecov-io
Copy link

codecov-io commented Nov 3, 2016

Current coverage is 29.05% (diff: 0.00%)

Merging #1370 into master will decrease coverage by 0.02%

@@             master      #1370   diff @@
==========================================
  Files           137        137          
  Lines         12900      12913    +13   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           3752       3752          
- Misses         8750       8763    +13   
  Partials        398        398          

Powered by Codecov. Last update 46de994...33567ef

@mwarkentin
Copy link
Contributor Author

@mwarkentin
Copy link
Contributor Author

My main question is around what needs to be done in release.go.

  • Do we need to support this both locally and on the rack? My use case is currently local only.
  • Do we need to support both public ('8000:8000) and private (8000) ports?
  • If so, would it make sense to write a function in ports.go which parses a port string and returns a Port instance?

@mwarkentin
Copy link
Contributor Author

Confirmed that this change works locally:

docker-compose.yml:

worker:
  build: .
  command: /app/bin/worker
  environment:
    - ...
  links:
    - broker

broker:
  image: rabbitmq:3.6
  environment:
    - LINK_SCHEME=amqp
    - LINK_PORT=5672
  ports:
    - 5672
/Users/michaelwarkentin/go/src/github.com/convox/rack/cmd/convox/convox start

...

worker   │ running: docker run -i --rm --name notifications-worker ... --add-host broker:172.17.0.2 -e BROKER_SCHEME=amqp -e BROKER_HOST=172.17.0.2 -e BROKER_PORT=5672 -e BROKER_PATH= -e BROKER_USERNAME= -e BROKER_PASSWORD= -e BROKER_URL=amqp://172.17.0.2:5672 --add-host redis:172.17.0.4 ... notifications/worker sh -c /app/bin/worker

@ddollar
Copy link
Contributor

ddollar commented Nov 7, 2016

Seems good. Yes, we should do it for production also, that would be here:

https://github.com/convox/rack/blob/master/api/models/release.go#L489

@mwarkentin
Copy link
Contributor Author

@ddollar Thanks. I took a look at adding it there, but wasn't sure what to do for converting an environment variable (string) into a Port object: https://github.com/convox/rack/blob/master/manifest/ports.go#L5-L10

It's a little less clear to me how this would be used on a rack (as I'd expect the only option is to go through the service's ELB, which already has the exposed ports defined.

@ddollar
Copy link
Contributor

ddollar commented Nov 7, 2016

I'm assuming this LINK_PORT defines which port shows up by default in the full link _URL ?

@ddollar
Copy link
Contributor

ddollar commented Nov 7, 2016

Perhaps loop through other.Ports looking for the one where LINK_PORT matches .Container

@mwarkentin
Copy link
Contributor Author

@ddollar I'll give that a shot, thanks!

i, _ := strconv.Atoi(other.Exports["LINK_PORT"])
if err != nil {
// handle error
fmt.Println(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Golang noobie.. not sure what to do here in case of an error converting LINK_PORT to an int.

Copy link
Contributor

Choose a reason for hiding this comment

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

return nil, err

if i == p.Container {
port = p
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything we should do if they've set LINK_PORT but it doesn't match any of the exposed ports?

Copy link
Contributor

Choose a reason for hiding this comment

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

That should be an error.

* If `LINK_PORT` not set, default to first port immediately
* Return error if `LINK_PORT` can't be converted to integer
* Return error if `LINK_PORT` set to non-existant port
@@ -18,7 +19,7 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/convox/rack/api/crypt"
"github.com/convox/rack/api/structs"
"github.com/convox/rack/manifest"
mp "github.com/convox/rack/manifest"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to do this as I wasn't able to refer to manifest.Port in my code otherwise (there's a local variable also called manifest already). Open on suggestions for a better way to handle this (or better name for it - mp stands for manifest package).

I updated other the other references that I found as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

So let's go the other way with this to avoid surprises around the namespace. Perhaps name the variable m down in the function and let this be manifest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do, thanks!

@@ -18,7 +19,7 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
"github.com/convox/rack/api/crypt"
"github.com/convox/rack/api/structs"
"github.com/convox/rack/manifest"
mp "github.com/convox/rack/manifest"
Copy link
Contributor

Choose a reason for hiding this comment

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

So let's go the other way with this to avoid surprises around the namespace. Perhaps name the variable m down in the function and let this be manifest

* Imported package is back to `manifest`
* Manifest arg to `resolveLinks` is now `m`
* Pointer to manifest is now `mp`
func (r *Release) resolveLinks(app App, manifest *manifest.Manifest) (*manifest.Manifest, error) {
m := *manifest
func (r *Release) resolveLinks(app App, m *manifest.Manifest) (*manifest.Manifest, error) {
mp := *m
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ran into one more existing variable name conflict here - renamed the pointer to the manifest from m to mp and updated other references.

@mwarkentin
Copy link
Contributor Author

Updated docs here: https://github.com/convox/site/pull/340

@mwarkentin
Copy link
Contributor Author

@MiguelMoll Not sure if you saw this one, @ddollar mentioned that it could make it into the next release potentially?

@ddollar ddollar added the merge label Nov 14, 2016
@MiguelMoll MiguelMoll added this to the 20161116 milestone Nov 16, 2016
@MiguelMoll
Copy link
Contributor

@mwarkentin Getting the release ready 👍 Could you update this branch with master? Then we'll be ready to go.

@mwarkentin
Copy link
Contributor Author

@MiguelMoll Updated, thanks!

MiguelMoll added a commit that referenced this pull request Nov 16, 2016
@MiguelMoll MiguelMoll mentioned this pull request Nov 16, 2016
18 tasks
MiguelMoll added a commit that referenced this pull request Nov 16, 2016
MiguelMoll added a commit that referenced this pull request Nov 17, 2016
@mwarkentin mwarkentin deleted the link-port-support branch November 18, 2016 13:38
@mwarkentin
Copy link
Contributor Author

@MiguelMoll Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants