-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Setup a dev docker container with hatch #933
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
Merged
Merged
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -71,4 +71,7 @@ target/ | |
| .idea/ | ||
|
|
||
| # Gemini | ||
| .gemini | ||
| .gemini/ | ||
|
|
||
| # Claude Code | ||
| .claude/ | ||
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,23 @@ | ||
| ARG PYTHON_VERSION | ||
|
|
||
| FROM python:${PYTHON_VERSION} | ||
|
|
||
| RUN pip install hatch==1.14.0 | ||
|
|
||
| # Add only the minimal files required to be able to pre-create the hatch environments. | ||
| # If any of these files changes, a new Docker build is necessary. This is why we need | ||
| # to only include the minimal set of files. | ||
| ADD pyproject.toml /working/pyproject.toml | ||
| ADD LICENSE.txt /working/LICENSE.txt | ||
| ADD README.md /working/README.md | ||
| ADD src/kaggle/__init__.py /working/src/kaggle/__init__.py | ||
| WORKDIR /working | ||
|
|
||
| # Pre-create the hatch environments. | ||
| # This drastically cut the time to run commands with the `docker-hatch` wrapper | ||
| # since the creation of the environments (including syncing dependencies) is | ||
| # only done once when building this image and is skipped later. | ||
| RUN hatch env create default | ||
| RUN hatch env create lint | ||
|
|
||
| ENTRYPOINT ["hatch"] |
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
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,72 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| PYTHON_VERSION='3.11.6' # Default Python version to use. | ||
| CACHE_FLAG='' | ||
|
|
||
| usage() { | ||
| cat << EOF | ||
| Usage: $0 [OPTIONS] HATCH-OPTIONS-COMMAND-ARGS | ||
| Run the given HATCH-OPTIONS-COMMAND-ARGS in a container. | ||
|
|
||
| Options: | ||
| -h, --help Show documentation on how to use $0 | ||
| -v, --python-version PYTHON-VERSION Run in a container using this specfic Python version. | ||
| Valid versions are tags of the \`python\` Docker image: https://hub.docker.com/_/python | ||
| -f, --force-rebuild-docker-image Force re-build the Docker image. | ||
| EOF | ||
| } | ||
|
|
||
| while :; do | ||
| case "$1" in | ||
| -h|--help) | ||
| usage | ||
| exit | ||
| ;; | ||
| -v|--python-version) | ||
| if [[ -z $2 ]]; then | ||
| usage | ||
| printf 'ERROR: No PYTHON-VERSION specified after the %s flag.\n' "$1" >&2 | ||
| exit | ||
| fi | ||
| PYTHON_VERSION=$2 | ||
| shift # skip the flag value | ||
| ;; | ||
| -f|--force-rebuild-docker-image) | ||
| CACHE_FLAG='--no-cache' | ||
| ;; | ||
| # Use this marker to indicate that the rest of the command is for hatch | ||
| --) | ||
| shift # skip this one to pass the rest to hatch | ||
| break | ||
| ;; | ||
| -?*) | ||
| usage | ||
| printf 'ERROR: Unknown option: %s\n' "$1" >&2 | ||
| exit | ||
| ;; | ||
| *) | ||
| break | ||
| esac | ||
|
|
||
| shift | ||
| done | ||
|
|
||
| DOCKER_IMAGE="kaggle-cli-docker-hatch:${PYTHON_VERSION}" | ||
|
|
||
| readonly PYTHON_VERSION | ||
| readonly DOCKER_IMAGE | ||
| readonly CACHE_FLAG | ||
|
|
||
| echo "Running 'hatch $@' inside a Docker container using Python ${PYTHON_VERSION}" | ||
|
|
||
| docker build -f Dockerfile \ | ||
| -t ${DOCKER_IMAGE} \ | ||
| ${CACHE_FLAG} \ | ||
| --cache-from ${DOCKER_IMAGE} \ | ||
| --build-arg PYTHON_VERSION=${PYTHON_VERSION} \ | ||
| --quiet \ | ||
| . | ||
|
|
||
| set -x | ||
| docker run -it --rm -v $PWD:/working -v ~/.kaggle:/root/.kaggle -w /working ${DOCKER_IMAGE} "$@" | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "-it" intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is to allow pseudo-TTY which enables running a shell via
./docker-hatch shell.