0

I'm using Pulumi to try and create an EBS application. As part of this I need to push a new docker image to ECR.

I need to push the image after the docker registry has been created but before the beanstalk application version tries to update to the new image.

I have the following code, but want push_image_to_repository() to be somehow called after the ecr.Repository has been created (ignore the ugly os.sytem call, that will be removed later).

application = Application(resource_name=ENV_APP_NAME, name=ENV_APP_NAME)
repository = ecr.Repository(resource_name=APP_NAME, name=APP_NAME)

image_tag = artifact_path.name.replace(".zip", "")

def push_image_to_repository(arn):
    upstream = f'{arn}/{image_tag}'
    os.system(f'make -C . push UPSTREAM={upstream}')


app_version = ApplicationVersion(
    resource_name=ENV_APP_NAME,
    application=application,
    bucket=releases_bucket.id,
    key=artifact_path.name,
)
environment = Environment(
    application=application,
    resource_name=ENV_APP_NAME,
    name=ENV_APP_NAME,
    solution_stack_name=STACK,
    settings=BEANSTALK_ENVIRONMENT_SETTINGS,
    wait_for_ready_timeout=BEANSTALK_ENVIRONMENT_TIMEOUT,
    version=app_version,
)

How can I go about doing this?

  • Have a look if [`pulumi-docker`](https://github.com/pulumi/pulumi-docker/) can help you here. I don't have AWS/python example, but maybe this [Azure/TypeScript example](https://github.com/pulumi/examples/blob/d814dbbd723a61bfd620825f3eb9f585e2817967/azure-ts-appservice-docker/index.ts#L58-L68) is somewhat helpful? – Mikhail Shilkov Jun 17 '19 at 11:29
  • @MikhailShilkov looks like that SDK is incomplete. I see support for push for JavaScript but not Python. – NotHilaryClinton Jun 17 '19 at 11:56

1 Answers1

1

With typescript (python should be pretty similar):

const repository = new aws.ecr.Repository({...})

const registry = pulumi.output(repostory.registryId).apply(async registryId => {
  const credentials = await aws.ecr.getCredentials({ registryId })
  const decodedCredentials = Buffer.from(credentials.authorizationToken, "base64").toString()
  const [username, password] = decodedCredentials.split(":")
  return { server: credentials.proxyEndpoint, username, password }
})

new docker.Image('my-image', {
  build: { context: '...' },
  imageName: pulumi.interpolate`${repository.repositoryUrl}:my-tag`,
  registry: registry,
})

Igor S.
  • 553
  • 4
  • 10