Skip to content

Commit

Permalink
Introduce arg for build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
tokk-nv committed Sep 21, 2023
1 parent 2f115d1 commit af591b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ data
logs
test/data
runner
*.minus-github-api
16 changes: 16 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ These flags tend to get used more during development - normally it's good to tho
## Running Containers

To launch containers that you've built or pulled, see the [Running Containers](/docs/run.md) documentation or the package's readme page.

## Troubleshooting

When building a container, you may hit this GitHub API rate limit especially if you are working in an office environment or similar where your outward-facing IP address is shared with other developers/instances.

> ADD failed: failed to GET https://api.github.com/repos/abetlen/llama-cpp-python/git/refs/heads/main with status 403 Forbidden: {"message":"API rate limit exceeded for 216.228.112.22. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting"}
If that is the case, use `--no-github-api` to remove a line like below from `Dockerfile` that was added to force rebuild on new git commits.

```
ADD https://api.github.com/repos/${LLAMA_CPP_PYTHON_REPO}/git/refs/heads/${LLAMA_CPP_PYTHON_BRANCH} /tmp/llama_cpp_python_version.json
```

You will find `Dockerfile.minus-github-api` file newly created in each package directory if the Dockerfile contains such line, and that's what used for building.

The `Dockerfile.minus-github-api` is temporary (and is listed in `.gitignore`), so always edit the original `Dockerfile` when needed.
5 changes: 3 additions & 2 deletions jetson_containers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
parser.add_argument('--simulate', action='store_true', help="print out the build commands without actually building the containers")
parser.add_argument('--push', type=str, default='', help="repo or user to push built container image to (no push by default)")
parser.add_argument('--logs', type=str, default='', help="sets the directory to save container build logs to (default: jetson-containers/logs)")
parser.add_argument('--no-github-api', action='store_true', help="disalbe Github API use to force rebuild on new git commits")

args = parser.parse_args()

Expand Down Expand Up @@ -92,6 +93,6 @@
# build one multi-stage container from chain of packages
# or launch multiple independent container builds
if not args.multiple:
build_container(args.name, args.packages, args.base, args.build_flags, args.simulate, args.skip_tests, args.test_only, args.push)
build_container(args.name, args.packages, args.base, args.build_flags, args.simulate, args.skip_tests, args.test_only, args.push, args.no_github_api)
else:
build_containers(args.name, args.packages, args.base, args.build_flags, args.simulate, args.skip_errors, args.skip_packages, args.skip_tests, args.test_only, args.push)
build_containers(args.name, args.packages, args.base, args.build_flags, args.simulate, args.skip_errors, args.skip_packages, args.skip_tests, args.test_only, args.push, args.no_github_api)
17 changes: 15 additions & 2 deletions jetson_containers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
_NEWLINE_=" \\\n" # used when building command strings


def build_container(name, packages, base=get_l4t_base(), build_flags='', simulate=False, skip_tests=[], test_only=[], push=''):
def build_container(name, packages, base=get_l4t_base(), build_flags='', simulate=False, skip_tests=[], test_only=[], push='', no_github_api=False):
"""
Multi-stage container build that chains together selected packages into one container image.
For example, `['pytorch', 'tensorflow']` would build a container that had both pytorch and tensorflow in it.
Expand All @@ -35,6 +35,7 @@ def build_container(name, packages, base=get_l4t_base(), build_flags='', simulat
skip_tests (list[str]) -- list of tests to skip (or 'all' or 'intermediate')
test_only (list[str]) -- only test these specified packages, skipping all other tests
push (str) -- name of repository or user to push container to (no push if blank)
no_github_api (bool) -- if true, use custom Dockerfile with no `ADD https://api.github.com/repos/...` line.
Returns:
The full name of the container image that was built (as a string)
Expand Down Expand Up @@ -102,7 +103,19 @@ def build_container(name, packages, base=get_l4t_base(), build_flags='', simulat

if 'dockerfile' in pkg:
cmd = f"{sudo_prefix()}docker build --network=host --tag {container_name}" + _NEWLINE_
cmd += f"--file {os.path.join(pkg['path'], pkg['dockerfile'])}" + _NEWLINE_
if no_github_api:
dockerfilepath = os.path.join(pkg['path'], pkg['dockerfile'])
with open(dockerfilepath, 'r') as fp:
data = fp.read()
if 'ADD https://api.github.com' in data:
dockerfilepath_minus_github_api = os.path.join(pkg['path'], pkg['dockerfile'] + '.minus-github-api')
os.system(f"cp {dockerfilepath} {dockerfilepath_minus_github_api}")
os.system(f"sed 's|^ADD https://api.github.com|#[minus-github-api]ADD https://api.github.com|' -i {dockerfilepath_minus_github_api}")
cmd += f"--file {os.path.join(pkg['path'], pkg['dockerfile'] + '.minus-github-api')}" + _NEWLINE_
else:
cmd += f"--file {os.path.join(pkg['path'], pkg['dockerfile'])}" + _NEWLINE_
else:
cmd += f"--file {os.path.join(pkg['path'], pkg['dockerfile'])}" + _NEWLINE_
cmd += f"--build-arg BASE_IMAGE={base}" + _NEWLINE_

if 'build_args' in pkg:
Expand Down

0 comments on commit af591b8

Please sign in to comment.