I would like to say something like: `url = ecr.rep...
# python
s
I would like to say something like:
url = ecr.repository_url
or
url = ecr['repository_url']
g
url = ecr.repository_url
should work. Are you getting an error when doing that?
s
I am trying to use the string for
repository_url
in a subprocess command
Copy code
ecr = aws.ecr.Repository(
    "jupyterhub",
    name="jupyterhub",
    image_scanning_configuration={
        "scanOnPush": True,
    },
    image_tag_mutability="MUTABLE"
)

url = ecr.repository_url
url = str(url)

def build_and_push_image(url):

    # current_account = aws.get_caller_identity().account_id
    # ecr_repo_url = f"{current_account}.<http://dkr.ecr.us-west-2.amazonaws.com/jupyterhub|dkr.ecr.us-west-2.amazonaws.com/jupyterhub>"
    image = f"{url}:latest"

    subprocess.run(
        [
            "aws", 
            "ecr", 
            "get-login-password", 
            "--region", 
            "us-west-2",
            "|",
            "docker",
            "login",
            "--username",
            "AWS",
            "--password-stdin",
            f"{url}"
        ], 
        cwd="../docker"
    )
Error parsing reference: "<pulumi.output.Output object at 0x10f605890>:latest" is not a valid repository/tag: invalid reference format: repository name must be lowercase
s
Use the alpha of pulumi_docker it has the class
image()
along with
dockerbuild()
will allow you to build the image locally then push to a remote repository. Also on pulumi_docker github they have examples of the auth structure to ecr so that portions already done for you.
s
Thanks! I will look into that package and give it a go instead of rolling my own thing. I still need to dynamically update my JupyterHub config with the RDS Postgres endpoint before building it and will likely still need to do the same kind of thing I am doing above. Do you know how I can achieve that?
s
If you are talking about the actual app within the docker image that will be taken care of by the
dockerbuild()
class. There are arguments if you have a custom location for the dockerfile along with the context which is where the configuration is located. Think of it just doing a
docker build..
Then your cicd will trigger pff branches and changes.
s
Okay cool that should work out just fine then. Is there anyway to get these values though just in case I need to do this in the future for something completely custom?
c
Copy code
image=Image(
    name= "%s-v1" % (p_application),
    build=DockerBuild(
        dockerfile = "../folder/single.Dockerfile",
        context = "../folder"
    ),
    image_name = pulumi.Output.all(repo.repository_url, buildId).apply(lambda vals: f"""{vals[0]}:{vals[1]}"""),
    registry = registry
)
That is what I did for the image creation, had to use
Output().apply()
This is a really good reference that I was using when going through some of it. https://github.com/pulumi/examples/pull/519/files#diff-982498c859f8161c992d7246993ab441R48-R53
s
rgr, thanks for the link and referral, this should work