fun testPush()

in jetbrains-core/it/software/aws/toolkits/jetbrains/services/ecr/EcrPushIntegrationTest.kt [48:89]


    fun testPush() {
        val remoteTag = UUID.randomUUID().toString()

        val dockerfile = folder.newFile()
        dockerfile.writeText(
            """
                # arbitrary base image with a shell
                FROM public.ecr.aws/amazonlinux/amazonlinux:2
                RUN touch $(date +%s)
            """.trimIndent()
        )

        val project = projectRule.project
        runBlocking {
            val serverInstance = EcrUtils.getDockerServerRuntimeInstance().runtimeInstance
            val ecrLogin = ecrClient.authorizationToken.authorizationData().first().getDockerLogin()
            val dockerAdapter = ToolkitDockerAdapter(project, serverInstance)
            val imageId = dockerAdapter.buildLocalImage(dockerfile)!!

            // gross transform because we only have the short SHA right now
            val localImage = serverInstance.agent.getImages(null).first { it.imageId.startsWith(EcrIntegrationTestUtils.getImagePrefix(imageId)) }
            val localImageId = localImage.imageId
            val pushRequest = ImageEcrPushRequest(
                serverInstance,
                localImageId,
                remoteRepo,
                remoteTag
            )
            EcrUtils.pushImage(projectRule.project, ecrLogin, pushRequest)

            assertThat(
                ecrClient.batchGetImage {
                    it.repositoryName(remoteRepo.repositoryName)
                    it.imageIds(ImageIdentifier.builder().imageTag(remoteTag).build())
                }.images()
            )
                .hasSize(1)
                .allSatisfy { image ->
                    assertDigestFromDockerManifest(image, localImageId)
                }
        }
    }