https://pulumi.com logo
#python
Title
# python
s

shy-football-10348

06/10/2020, 12:23 AM
I would like to say something like:
url = ecr.repository_url
or
url = ecr['repository_url']
g

gentle-diamond-70147

06/10/2020, 12:24 AM
url = ecr.repository_url
should work. Are you getting an error when doing that?
s

shy-football-10348

06/10/2020, 12:30 AM
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

strong-plastic-28250

06/10/2020, 12:42 AM
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

shy-football-10348

06/10/2020, 12:49 AM
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

strong-plastic-28250

06/10/2020, 12:53 AM
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

shy-football-10348

06/10/2020, 12:58 AM
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

chilly-hairdresser-56259

06/10/2020, 12:59 AM
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

shy-football-10348

06/10/2020, 1:23 AM
rgr, thanks for the link and referral, this should work