generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 234
Add developer container to support running integration tests, etc. on macOS #1780
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
Open
dannycjones
wants to merge
2
commits into
awslabs:main
Choose a base branch
from
dannycjones:dev-container
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+201
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| FROM public.ecr.aws/amazonlinux/amazonlinux:2023 | ||
|
|
||
| RUN dnf upgrade -y && \ | ||
| dnf install -y \ | ||
| fuse \ | ||
| fuse-devel \ | ||
| cmake3 \ | ||
| clang \ | ||
| clang-devel \ | ||
| git \ | ||
| pkg-config \ | ||
| jq && \ | ||
| dnf clean all | ||
|
|
||
| # Configure FUSE | ||
| RUN echo "user_allow_other" >> /etc/fuse.conf | ||
|
|
||
| # Create non-root user | ||
| RUN useradd -m -s /bin/bash dev-user && \ | ||
| usermod -aG wheel dev-user | ||
|
|
||
| # Install Rust as dev-user | ||
| USER dev-user | ||
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none | ||
| ENV PATH="/home/dev-user/.cargo/bin:${PATH}" | ||
|
|
||
| # Set colored prompt | ||
| RUN echo 'PS1="\[\033[1;36m\][dev-container]:\[\033[1;34m\]\w\[\033[0m\] \$ "' >> /home/dev-user/.bashrc | ||
|
|
||
| WORKDIR /workspace | ||
|
|
||
| RUN mkdir -p /workspace/target | ||
|
|
||
| # Install cargo-nextest and Rust version based on toolchain config at build time | ||
| COPY --chown=dev-user:dev-user rust-toolchain.toml ./ | ||
| RUN rustup show && cargo install cargo-nextest --locked | ||
|
|
||
| ENV RUST_BACKTRACE=1 | ||
|
|
||
| COPY --chown=dev-user:dev-user dev-container/entrypoint.sh /home/dev-user/entrypoint.sh | ||
| RUN chmod +x /home/dev-user/entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/home/dev-user/entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Development Container | ||
|
|
||
| Docker container for running Mountpoint S3 tests on Linux. Useful for macOS users to test against a Linux kernel/OS. | ||
|
|
||
| The container uses runtime builds with persistent caching: | ||
| - System dependencies are baked into the image at build time | ||
| - Rust toolchains (`~/.rustup/`), cargo dependencies, and build artifacts are cached in Docker volumes between runs | ||
| - On each container start, the entrypoint ensures the correct Rust toolchain (from `rust-toolchain.toml`) is installed | ||
| - Source code is mounted at runtime (not baked into image) | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```bash | ||
| # Build and run the container | ||
| ./dev-container/run.py --build | ||
|
|
||
| # Interactive shell | ||
| ./dev-container/run.py | ||
|
|
||
| # Run a command (use -- to separate script args from container args) | ||
| ./dev-container/run.py --use-credentials-from-aws-config -- cargo nextest run --features s3_tests,fuse_tests -p mountpoint-s3-fs | ||
| ``` | ||
|
|
||
| ## Credential Options | ||
|
|
||
| You'll need to configure AWS credentials if you want to run things like the integration tests which access S3. | ||
|
|
||
| As an example, you might have credentials available in your `~/.aws/` folder. | ||
| You can use the `--use-credentials-from-aws-config` option to bind mount that directory into the container. | ||
|
|
||
| See `--help` for more available arguments. | ||
|
|
||
| ## When to Rebuild | ||
|
|
||
| Rebuild the image when: | ||
| - System dependencies need updating | ||
|
|
||
| You do **not** need to rebuild when: | ||
| - Rust toolchain version changes in `rust-toolchain.toml` (the entrypoint installs the correct toolchain automatically) | ||
| - Code or cargo dependencies change (cached in Docker volumes) | ||
|
|
||
| ## Cleanup | ||
|
|
||
| To remove the cached rustup volume (e.g., when old toolchains accumulate): | ||
|
|
||
| ```bash | ||
| ./dev-container/run.py --drop-rustup-volume | ||
| ``` | ||
|
|
||
| Build artifacts and cargo dependencies are cached in Docker volumes between runs, so you don't need to rebuild for code or dependency changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Ensure the correct Rust toolchain is installed (reads /workspace/rust-toolchain.toml) | ||
| rustup show > /dev/null | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| exec /bin/bash | ||
| else | ||
| exec "$@" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| #!/usr/bin/env python3 | ||
| import argparse | ||
| import os | ||
| import subprocess | ||
|
|
||
| CONTAINER_USER = 'dev-user' | ||
| CARGO_CACHE_VOLUME = 'mountpoint-s3-cargo-cache' | ||
| CARGO_TARGET_VOLUME = 'mountpoint-s3-target-cache' | ||
| RUSTUP_VOLUME = 'mountpoint-s3-rustup-home' | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Run Mountpoint S3 development container') | ||
| parser.add_argument('--image', default='mountpoint-s3-dev', help='Docker image name') | ||
| parser.add_argument('--build', action='store_true', help='Build the image before running') | ||
| parser.add_argument('--drop-rustup-volume', action='store_true', help='Remove the rustup Docker volume and exit') | ||
|
|
||
| creds_group = parser.add_mutually_exclusive_group() | ||
| creds_group.add_argument('--use-credentials-from-env', action='store_true', help='Pass through AWS env vars') | ||
| creds_group.add_argument('--use-credentials-from-aws-config', action='store_true', help='Pass through AWS env vars') | ||
|
|
||
| args, container_args = parser.parse_known_args() | ||
|
|
||
| # Remove '--' separator if present | ||
| if container_args and container_args[0] == '--': | ||
| container_args = container_args[1:] | ||
|
|
||
| if args.drop_rustup_volume: | ||
| subprocess.run(['docker', 'volume', 'rm', RUSTUP_VOLUME], check=True) | ||
| return | ||
|
|
||
| if args.build: | ||
| subprocess.run( | ||
| ['docker', 'build', '-f', 'dev-container/Dockerfile.development', '-t', args.image, '.'], check=True | ||
| ) | ||
|
|
||
| docker_args = [ | ||
| 'docker', | ||
| 'run', | ||
| '-it', | ||
| '--rm', | ||
| '--device=/dev/fuse', | ||
| '--privileged', | ||
| # f'--user={os.getuid()}:{os.getgid()}', | ||
| f'--env-file={os.getcwd()}/.env', | ||
dannycjones marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| f'-v={os.getcwd()}:/workspace', | ||
| f'-v={CARGO_CACHE_VOLUME}:/home/{CONTAINER_USER}/.cargo/registry', | ||
| f'-v={CARGO_TARGET_VOLUME}:/workspace/target', | ||
| f'-v={RUSTUP_VOLUME}:/home/{CONTAINER_USER}/.rustup', | ||
| ] | ||
|
|
||
| if args.use_credentials_from_env: | ||
| for var in ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN', 'AWS_REGION']: | ||
| if var in os.environ: | ||
| docker_args.extend(['-e', var]) | ||
| elif args.use_credentials_from_aws_config: | ||
| aws_dir = os.path.expanduser('~/.aws') | ||
| if os.path.exists(aws_dir): | ||
| docker_args.extend(['-v', f'{aws_dir}:/home/{CONTAINER_USER}/.aws:ro']) | ||
|
|
||
| if container_args: | ||
| docker_args.extend([args.image, '/bin/bash', '-c', ' '.join(container_args)]) | ||
| else: | ||
| docker_args.extend([args.image, '/bin/bash']) | ||
|
|
||
| subprocess.run(docker_args) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.