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(lambda-python): root-owned cache items not cleaned up after install #22512

Merged
merged 5 commits into from
Oct 19, 2022

Conversation

varju
Copy link
Contributor

@varju varju commented Oct 15, 2022

This is another attempt at fixing #22012. #22398 intended to fix it, but the issue still occurs when building on arm64 machines with both compatible_runtimes=[lambdas.Runtime.PYTHON_3_9] and compatible_architectures=[lambdas.Architecture.ARM_64]

The core problem is that the build leaves root-owned files under /tmp/pip-cache, which then cause permission problems when subsequent layers calling pip install are unable to create temporary directories. Example error:

WARNING: Building wheel for alembic-utils failed: [Errno 13] Permission denied: '/tmp/pip-cache/wheels/5c'

Expanding on the idea within #22398, this PR adds one more step to the chain of operations, removing any temporary files from the cache that are no longer needed (because the packages are now installed), and ensuring that subsequent layers are able to create temporary files inside the cache directories.

Comparing the contents of the Docker image before and after this change...

Before:

$ ls -aFl /tmp/*cache
/tmp/pip-cache:
total 16
drwxrwxrwx  4 root root 4096 Oct 15 00:57 ./
drwxrwxrwt  1 root root 4096 Oct 15 00:58 ../
drwxr-xr-x 18 root root 4096 Oct 15 00:57 http/
drwxr-xr-x  2 root root 4096 Oct 15 00:57 selfcheck/

/tmp/poetry-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 00:57 ./
drwxrwxrwt 1 root root 4096 Oct 15 00:58 ../

After:

$ ls -aFl /tmp/*cache
/tmp/pip-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 01:00 ./
drwxrwxrwt 1 root root 4096 Oct 15 01:00 ../

/tmp/poetry-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 00:59 ./
drwxrwxrwt 1 root root 4096 Oct 15 01:00 ../

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional 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 Oct 15, 2022

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Oct 15, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 15, 2022 01:06
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@varju varju changed the title Clean up root-owned cache items fix(lambda-python): Clean up root-owned cache items Oct 15, 2022
@varju varju changed the title fix(lambda-python): Clean up root-owned cache items fix(lambda-python): clean up root-owned cache items Oct 15, 2022
@varju varju force-pushed the 22012-arm64-docker-python-layer branch from e1f074b to 4664d9d Compare October 17, 2022 22:37
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 17, 2022 22:38

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@@ -1,31 +1,31 @@
import * as path from 'path';
import { Packaging } from '../lib/packaging';

test('Packging with no dependencies', () => {
test('Packaging with no dependencies', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing a typo unrelated to the current problem. I can revert this if it's not okay to mix unrelated changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm never upset about typo fixes :)

@varju varju marked this pull request as ready for review October 17, 2022 23:56
@TheRealAmazonKendra TheRealAmazonKendra changed the title fix(lambda-python): clean up root-owned cache items fix(lambda-python): root-owned cache items not cleaned up after install Oct 19, 2022
@@ -1,31 +1,31 @@
import * as path from 'path';
import { Packaging } from '../lib/packaging';

test('Packging with no dependencies', () => {
test('Packaging with no dependencies', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm never upset about typo fixes :)

@mergify
Copy link
Contributor

mergify bot commented Oct 19, 2022

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).

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review October 19, 2022 13:15

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@mergify
Copy link
Contributor

mergify bot commented Oct 19, 2022

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).

@mergify mergify bot merged commit 5ef65e0 into aws:main Oct 19, 2022
@varju varju deleted the 22012-arm64-docker-python-layer branch October 19, 2022 16:46
mrgrain pushed a commit to mrgrain/aws-cdk that referenced this pull request Oct 24, 2022
…ll (aws#22512)

This is another attempt at fixing aws#22012. aws#22398 intended to fix it, but the issue still occurs when building on arm64 machines with both `compatible_runtimes=[lambdas.Runtime.PYTHON_3_9]` and `compatible_architectures=[lambdas.Architecture.ARM_64]`

The core problem is that the build leaves root-owned files under `/tmp/pip-cache`, which then cause permission problems when subsequent layers calling `pip install` are unable to create temporary directories. Example error:

```
WARNING: Building wheel for alembic-utils failed: [Errno 13] Permission denied: '/tmp/pip-cache/wheels/5c'
```

Expanding on the idea within aws#22398, this PR adds one more step to the chain of operations, removing any temporary files from the cache that are no longer needed (because the packages are now installed), and ensuring that subsequent layers are able to create temporary files inside the cache directories.

Comparing the contents of the Docker image before and after this change...

Before:
```
$ ls -aFl /tmp/*cache
/tmp/pip-cache:
total 16
drwxrwxrwx  4 root root 4096 Oct 15 00:57 ./
drwxrwxrwt  1 root root 4096 Oct 15 00:58 ../
drwxr-xr-x 18 root root 4096 Oct 15 00:57 http/
drwxr-xr-x  2 root root 4096 Oct 15 00:57 selfcheck/

/tmp/poetry-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 00:57 ./
drwxrwxrwt 1 root root 4096 Oct 15 00:58 ../
```

After:
```
$ ls -aFl /tmp/*cache
/tmp/pip-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 01:00 ./
drwxrwxrwt 1 root root 4096 Oct 15 01:00 ../

/tmp/poetry-cache:
total 8
drwxrwxrwx 2 root root 4096 Oct 15 00:59 ./
drwxrwxrwt 1 root root 4096 Oct 15 01:00 ../
```

----

### All Submissions:

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

### Adding new Unconventional Dependencies:

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

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] 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 p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants