-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dockerfile + wrapping script, and updated README accordingly
- Loading branch information
Showing
3 changed files
with
109 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,20 @@ | ||
FROM python:3.5-alpine AS build-env | ||
|
||
# You can build the docker image with the command : | ||
# docker build --no-cache -t trainline . | ||
|
||
# You can create a container with : | ||
# docker run -it --rm trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours | ||
|
||
RUN pip install -U --no-cache-dir --target /app trainline \ | ||
&& find /app | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf | ||
|
||
FROM gcr.io/distroless/python3 | ||
|
||
COPY --from=build-env /app /app | ||
|
||
ENV PYTHONPATH=/app | ||
ENV LC_ALL=C.UTF-8 | ||
ENV LANG=C.UTF-8 | ||
|
||
ENTRYPOINT ["python", "/app/bin/trainline_cli.py"] |
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
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,45 @@ | ||
#!/bin/sh | ||
|
||
# A wrapper script for invoking a docker container | ||
# Based on https://spin.atomicobject.com/2015/11/30/command-line-tools-docker/ | ||
|
||
DOCKER_IMAGE="thibdct/trainline" | ||
|
||
error(){ | ||
error_code=$1 | ||
echo "ERROR: $2" >&2 | ||
exit $1 | ||
} | ||
check_cmd_in_path(){ | ||
cmd=$1 | ||
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!" | ||
} | ||
upgrade(){ | ||
docker pull $DOCKER_IMAGE | ||
exit 1 | ||
} | ||
uninstall(){ | ||
read -p "Are you sure to uninstall (y/n)? " -n 1 -r | ||
echo | ||
if [[ $REPLY =~ ^[Yy]$ ]] | ||
then | ||
docker rmi $DOCKER_IMAGE | ||
rm $0 | ||
fi | ||
exit 1 | ||
} | ||
|
||
# Checks for dependencies | ||
check_cmd_in_path docker | ||
|
||
case $1 in | ||
--uninstall) | ||
uninstall | ||
;; | ||
--upgrade) | ||
upgrade | ||
;; | ||
esac | ||
|
||
# Run our containerized command | ||
exec docker run -it --rm $DOCKER_IMAGE "$@" |