Skip to content

Commit

Permalink
Added Dockerfile + wrapping script, and updated README accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
tducret committed Jan 1, 2019
1 parent 9e16b4c commit ed284d6
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
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"]
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Travis](https://img.shields.io/travis/tducret/trainline-python.svg)](https://travis-ci.org/tducret/trainline-python)
[![Coveralls github](https://img.shields.io/coveralls/github/tducret/trainline-python.svg)](https://coveralls.io/github/tducret/trainline-python)
[![PyPI](https://img.shields.io/pypi/v/trainline.svg)](https://pypi.org/project/trainline/)
[![Docker Image size](https://img.shields.io/microbadger/image-size/thibdct/trainline.svg)](https://hub.docker.com/r/thibdct/trainline/)
![License](https://img.shields.io/github/license/tducret/trainline-python.svg)

## Description
Expand All @@ -11,6 +12,8 @@ Non-official Python wrapper and CLI tool for Trainline

I wrote a French blog post about it [here](https://www.tducret.com/scraping/2018/09/05/trouvez-le-billet-de-train-le-moins-cher-grace-a-ce-module-python.html)

🎁 I added [a tiny Docker image](#docker) to use the tool very easily

# Requirements

- Python 3
Expand Down Expand Up @@ -110,6 +113,47 @@ departure_date;arrival_date;duration;number_of_segments;price;currency;transport
[...]
```

# Docker

You can use the `trainline` tool with the [Docker image](https://hub.docker.com/r/thibdct/trainline/)

You may execute :

`docker run -it --rm thibdct/trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours`

> The Docker image is built on top of [Google Distroless image](https://github.com/GoogleContainerTools/distroless), so it is tiny :)
## 🤘 The easy way 🤘

I also built a bash wrapper to execute the Docker container easily.

Install it with :

```bash
curl -s https://raw.githubusercontent.com/tducret/trainline-python/master/trainline.sh \
> /usr/local/bin/trainline && chmod +x /usr/local/bin/trainline
```
*You may replace `/usr/local/bin` with another folder that is in your $PATH*

Check that it works :

```bash
trainline --help
trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours
```

You can upgrade the app with :

```bash
trainline --upgrade
```

and even uninstall with :

```bash
trainline --uninstall
```

# TODO

- [ ] Create a sort function in Folders class (to get the cheapest trips first for example)
Expand Down
45 changes: 45 additions & 0 deletions trainline.sh
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 "$@"

0 comments on commit ed284d6

Please sign in to comment.