question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider an improved way of referencing containers in cloud.Service

See original GitHub issue

This is not a priority, but I wanted to capture this idea.

Consider this code:

let redisPort = 6379;

let redisCache = new cloud.Service("voting-app-cache", {
    containers: {
        redis: {
            // <snip>
            ports: [{ port: redisPort }]
        },
    },
});

let frontend = new cloud.Service("voting-app-frontend", {
    containers: {
        votingAppFrontend: {
            // <snip>
            environment: { 
                // using a string to reference the "redis" container
                // is there a better way to reference the port?
                "REDIS": redisCache.getEndpoint("redis", redisPort).then(e => e.hostname)
            }
        },
    },
});

To reference the redis container from the frontend.votingAppFrontend container, I have to use the string value redis. It’s also annoying that I have to pass in the port, though I realize it will default to the first open port. I saw that ports are not named in Docker Compose, so that might be a hard thing to change.

At first glance, I’m not sure how we would make the types stronger (looks like dependent types), but perhaps there’s a way.

Other than promises, this is really the only flaw of an otherwise lovely program.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
lukehobancommented, Nov 21, 2017

This is something that’s bugged me with our current APIs, btw, since the “single container” case entails some extra concepts that may not make sense. (“What, I just wanted to run a single container, why would I have an array of them?”)

Here’s a thought - we could split the containers part of the arguments to Service into a separate parameter from the other options (which are often not needed) and then offer two overloads:

export interface ServiceConstructor {
    new (name: string, containers: Containers, args?: ServiceArguments): Service;
    new (name: string, container: Container, args?: ServiceArguments): Service;
}

The later would be the “simple” model, and would name the container the same as the name provided to the Service constructor.

Donna’s example would look like:

let redisPort = 6379;

let redisCache = new cloud.Service("voting-app-cache", {
    // <snip>
    ports: [{ port: redisPort }]
});

let frontend = new cloud.Service("voting-app-frontend", {
    // <snip>
    environment: { 
        // using a string to reference the "redis" container
        // is there a better way to reference the port?
        "REDIS": redisCache.getEndpoint("redis", redisPort).then(e => e.hostname)
    },
});

This also makes the multi-container case more pleasent as you don’t need to say the word “containers” for something that will always be there.

1reaction
joeduffycommented, Nov 21, 2017

I would think we want to show the simple use case. I suspect many (most) services will just have a single container and single exposed port. This is something that’s bugged me with our current APIs, btw, since the “single container” case entails some extra concepts that may not make sense. (“What, I just wanted to run a single container, why would I have an array of them?”)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for building containers | Cloud Architecture Center
This article describes a set of best practices for building containers. These practices cover a wide range of goals, from shortening the ...
Read more >
11 Leading Practices When Implementing a Container Strategy
Containers provide a manageable means to quickly redeploy a service in a specific configuration, replacing infrastructure with code.
Read more >
Introduction to Docker quiz - TheServerSide.com
This 10-question Docker quiz will let you know if you're ready to move beyond the basics and expand your knowledge of container-related topics ......
Read more >
Serverless computing vs. containers | How to choose
Serverless architecture and containers offer some similar benefits but differ in several crucial ways. Learn how to compare serverless computing vs.
Read more >
What is a container? | Microsoft Azure
Containers address this problem by providing a lightweight, immutable infrastructure for application packaging and deployment. An application or service, its ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found