Skip to content

Commit

Permalink
Add a reference Docker File (pypa#113)
Browse files Browse the repository at this point in the history
* 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
cooperlees authored Jan 5, 2019
1 parent be8d17e commit ec43965
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
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"]
28 changes: 28 additions & 0 deletions src/runner.py
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()

0 comments on commit ec43965

Please sign in to comment.