forked from pypa/bandersnatch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a reference Docker File (pypa#113)
* Add a reference Docker File - Use latest Python 3 - Install all tested Python module version in requirements.txt Tested build via `docker build --network=host --tag bandersnatch .`: https://pastebin.com/0ZGgMUtA * Actually set parsed args to a variable
- Loading branch information
1 parent
be8d17e
commit ec43965
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,19 @@ | ||
FROM python:3 | ||
|
||
RUN mkdir -p /src | ||
ADD setup.py /src | ||
ADD requirements.txt /src | ||
ADD README.md /src | ||
ADD CHANGES.md /src | ||
ADD src /src/src | ||
|
||
# Remember to bind mount the "directory" in bandersnatch.conf | ||
# Could also comment this out and bind mount in the config and add arg below | ||
ADD bandersnatch.conf /etc | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install --upgrade -r /src/requirements.txt | ||
RUN cd /src && pip install . | ||
|
||
# Please adjust the interval - Could move this to the config file or ENV Variable | ||
CMD ["python", "/src/src/runner.py", "3600"] |
This file contains 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,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Simple Script to replace cron for Docker | ||
|
||
import argparse | ||
import sys | ||
import time | ||
from subprocess import run | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("interval", help="Time in seconds between jobs") | ||
args = parser.parse_args() | ||
|
||
print(f"Running bandersnatch every {args.interval}s", file=sys.stderr) | ||
while True: | ||
start_time = time.time() | ||
run(["/usr/bin/bandersnatch", "mirror"]) | ||
run_time = time.time() - start_time | ||
if run_time < args.interval: | ||
sleep_time = args.interval - run_time | ||
print(f"Sleeping for {sleep_time}s", file=sys.stderr) | ||
time.sleep(sleep_time) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |