Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecr-assets): fix repeated deploys of stacks with tar assets #23497

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

dastbe
Copy link
Contributor

@dastbe dastbe commented Dec 29, 2022

The current implementation fails because it assumes the output of
docker load can only be

Loaded Image: {image}

However, if docker has to take any actions (such as untagging a previous
image) the output will look like

{error message}
{error message}
Loaded Image: {image}

To fix this, we can simply take the last line of the output via tail
before we attempt to extract the image. If the last line isn't of the
correct form, this will fail in an effectively equivalent way to how it
failed previously.

A previous attempt at fixing this (#18823) used a more complicated sed
command which used a cli flag that is not consistently available. This
approach won't work on all platforms (ex. macos) and is also much less
clear that it's correct.

This change also adds an integration test that tests the tarbell stack, though
it doesn't test the repeated deploy automatically. I have tested that by
running the integration test multiple times with an image modification in
between. We also vendor the tarball of the hello-world docker image, which
results in ~20kb of additional data in the repo. This is about as small as we
can get a vendored image with as straightforward a vendoring process.

fixes #18822


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Dec 29, 2022

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Dec 29, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team December 29, 2022 19:21
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 labels Dec 29, 2022
@dastbe dastbe force-pushed the fix-repeated-tarball-invocations branch 3 times, most recently from 1962771 to 419cdbf Compare December 31, 2022 01:47
@dastbe
Copy link
Contributor Author

dastbe commented Jan 9, 2023

ping!

Copy link
Contributor

@comcalvi comcalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a demo-tarball file with an empty tarball in it...Instead of using hello-world, can we use a tarball form of the demo-image directory under test?

@dastbe
Copy link
Contributor Author

dastbe commented Feb 14, 2023

We have a demo-tarball file with an empty tarball in it...Instead of using hello-world, can we use a tarball form of the demo-image directory under test?

so unfortunately an empty tarball is not valid from docker's perspective, so won't be loaded and therefore the integration test will fail. here's an example:

docker images
REPOSITORY              TAG       IMAGE ID       CREATED       SIZE
ghcr.io/dagger/engine   v0.3.9    2671daeb98d9   5 weeks ago   183MB
dastbe on Davids-Air in ~/workplace/aws-cdk/packages/@aws-cdk/aws-ecr-assets/test (fix-repeated-tarball-invocations)
docker load -i demo-tarball/empty.tar
open /var/lib/docker/tmp/docker-import-995944040/repositories: no such file or directory
dastbe on Davids-Air in ~/workplace/aws-cdk/packages/@aws-cdk/aws-ecr-assets/test (fix-repeated-tarball-invocations)
docker images
REPOSITORY              TAG       IMAGE ID       CREATED       SIZE
ghcr.io/dagger/engine   v0.3.9    2671daeb98d9   5 weeks ago   183MB
dastbe on Davids-Air in ~/workplace/aws-cdk/packages/@aws-cdk/aws-ecr-assets/test (fix-repeated-tarball-invocations)
docker load -i demo-tarball-hello-world/hello-world.tar
efb53921da33: Loading layer [==================================================>]  10.75kB/10.75kB
Loaded image: hello-world:latest
dastbe on Davids-Air in ~/workplace/aws-cdk/packages/@aws-cdk/aws-ecr-assets/test (fix-repeated-tarball-invocations)
docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
ghcr.io/dagger/engine   v0.3.9    2671daeb98d9   5 weeks ago     183MB
hello-world             latest    46331d942d63   11 months ago   9.14kB

@dastbe dastbe requested a review from comcalvi February 14, 2023 04:23
Copy link
Contributor

@MrArnoldPalmer MrArnoldPalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dastbe thanks for your patience here. With the test failure using the empty-tarball I think vendoring hello-world is alright. I'd say lets remove the update.sh script cause I don't really see the need to update the image in the tarball for testing purposes and it isn't referenced anywhere in the test.

Additionally investigated changing the test, to either be a unit test or to not actually deploy the stack in the integ test using deploy: { enabled: false } because we don't actually need it to do so, only to build the images with docker. Either way though the build commands don't get run until actual stack deploy so I believe this is in fact the best way to test this for now.

@dastbe dastbe force-pushed the fix-repeated-tarball-invocations branch from 419cdbf to 4342f4b Compare February 27, 2023 02:29
@mergify mergify bot dismissed stale reviews from comcalvi and MrArnoldPalmer February 27, 2023 02:30

Pull request has been modified.

@dastbe
Copy link
Contributor Author

dastbe commented Feb 27, 2023

I'd say lets remove the update.sh script cause I don't really see the need to update the image in the tarball for testing purposes and it isn't referenced anywhere in the test.

done

Additionally investigated changing the test, to either be a unit test or to not actually deploy the stack in the integ test using deploy: { enabled: false } because we don't actually need it to do so, only to build the images with docker. Either way though the build commands don't get run until actual stack deploy so I believe this is in fact the best way to test this for now.

just to clarify you're not asking me to change anything correct?

MrArnoldPalmer
MrArnoldPalmer previously approved these changes Feb 27, 2023
Copy link
Contributor

@MrArnoldPalmer MrArnoldPalmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to clarify you're not asking me to change anything correct?

Correct, you're all good 👍🏻

@mergify
Copy link
Contributor

mergify bot commented Feb 27, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

The current implementation fails because it assumes the output of
`docker load` can only be

```
Loaded Image: {image}
```

However, if docker has to take any actions (such as untagging a previous
image) the output will look like

```
{error message}
{error message}
Loaded Image: {image}
```

To fix this, we can simply take the last line of the output via `tail`
before we attempt to extract the image. If the last line isn't of the
correct form, this will fail in an effectively equivalent way to how it
failed previously.

A previous attempt at fixing this (aws#18823) used a more complicated `sed`
command which used a cli flag that is not consistently available. This
approach won't work on all platforms (ex. macos) and is also much less
clear that it's correct.

This change also adds an integration test that tests the tarbell stack, though
it doesn't test the repeated deploy automatically. I have tested that by
running the integration test multiple times with an image modification in
between. We also vendor the tarball of the hello-world docker image, which
results in ~10kb of additional data in the repo. This is about as small as we
can get a vendored image with as straightforward a vendoring process.

fixes aws#18822
@dastbe dastbe force-pushed the fix-repeated-tarball-invocations branch from 4342f4b to eb45b05 Compare February 28, 2023 00:27
@mergify mergify bot dismissed MrArnoldPalmer’s stale review February 28, 2023 00:29

Pull request has been modified.

@dastbe dastbe requested review from MrArnoldPalmer and removed request for comcalvi February 28, 2023 01:24
@TheRealAmazonKendra
Copy link
Contributor

When you manually rebase or merge from main, it cancels our reviews, which is why this hasn't merged yet. Please do not take that action in the future, unless using the command @Mergifyio update. Our automation takes care of handling everything once we've provided an approval.

@mergify
Copy link
Contributor

mergify bot commented Feb 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: c7ccff0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit c2296a8 into aws:main Feb 28, 2023
@mergify
Copy link
Contributor

mergify bot commented Feb 28, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Mar 28, 2023
…23497)

The current implementation fails because it assumes the output of
`docker load` can only be

```
Loaded Image: {image}
```

However, if docker has to take any actions (such as untagging a previous
image) the output will look like

```
{error message}
{error message}
Loaded Image: {image}
```

To fix this, we can simply take the last line of the output via `tail`
before we attempt to extract the image. If the last line isn't of the
correct form, this will fail in an effectively equivalent way to how it
failed previously.

A previous attempt at fixing this (aws#18823) used a more complicated `sed`
command which used a cli flag that is not consistently available. This
approach won't work on all platforms (ex. macos) and is also much less
clear that it's correct.

This change also adds an integration test that tests the tarbell stack, though
it doesn't test the repeated deploy automatically. I have tested that by
running the integration test multiple times with an image modification in
between. We also vendor the tarball of the hello-world docker image, which
results in ~20kb of additional data in the repo. This is about as small as we
can get a vendored image with as straightforward a vendoring process.

fixes aws#18822


----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(cdk-assets): TarballImageAsset fails build if trying to load tarball with existing tag
5 participants