Skip to content

Commit ed284d6

Browse files
committed
Added Dockerfile + wrapping script, and updated README accordingly
1 parent 9e16b4c commit ed284d6

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.5-alpine AS build-env
2+
3+
# You can build the docker image with the command :
4+
# docker build --no-cache -t trainline .
5+
6+
# You can create a container with :
7+
# docker run -it --rm trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours
8+
9+
RUN pip install -U --no-cache-dir --target /app trainline \
10+
&& find /app | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
11+
12+
FROM gcr.io/distroless/python3
13+
14+
COPY --from=build-env /app /app
15+
16+
ENV PYTHONPATH=/app
17+
ENV LC_ALL=C.UTF-8
18+
ENV LANG=C.UTF-8
19+
20+
ENTRYPOINT ["python", "/app/bin/trainline_cli.py"]

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Travis](https://img.shields.io/travis/tducret/trainline-python.svg)](https://travis-ci.org/tducret/trainline-python)
44
[![Coveralls github](https://img.shields.io/coveralls/github/tducret/trainline-python.svg)](https://coveralls.io/github/tducret/trainline-python)
55
[![PyPI](https://img.shields.io/pypi/v/trainline.svg)](https://pypi.org/project/trainline/)
6+
[![Docker Image size](https://img.shields.io/microbadger/image-size/thibdct/trainline.svg)](https://hub.docker.com/r/thibdct/trainline/)
67
![License](https://img.shields.io/github/license/tducret/trainline-python.svg)
78

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

1213
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)
1314

15+
🎁 I added [a tiny Docker image](#docker) to use the tool very easily
16+
1417
# Requirements
1518

1619
- Python 3
@@ -110,6 +113,47 @@ departure_date;arrival_date;duration;number_of_segments;price;currency;transport
110113
[...]
111114
```
112115

116+
# Docker
117+
118+
You can use the `trainline` tool with the [Docker image](https://hub.docker.com/r/thibdct/trainline/)
119+
120+
You may execute :
121+
122+
`docker run -it --rm thibdct/trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours`
123+
124+
> The Docker image is built on top of [Google Distroless image](https://github.com/GoogleContainerTools/distroless), so it is tiny :)
125+
126+
## 🤘 The easy way 🤘
127+
128+
I also built a bash wrapper to execute the Docker container easily.
129+
130+
Install it with :
131+
132+
```bash
133+
curl -s https://raw.githubusercontent.com/tducret/trainline-python/master/trainline.sh \
134+
> /usr/local/bin/trainline && chmod +x /usr/local/bin/trainline
135+
```
136+
*You may replace `/usr/local/bin` with another folder that is in your $PATH*
137+
138+
Check that it works :
139+
140+
```bash
141+
trainline --help
142+
trainline --departure="Toulouse" --arrival="Bordeaux" --next=12hours
143+
```
144+
145+
You can upgrade the app with :
146+
147+
```bash
148+
trainline --upgrade
149+
```
150+
151+
and even uninstall with :
152+
153+
```bash
154+
trainline --uninstall
155+
```
156+
113157
# TODO
114158

115159
- [ ] Create a sort function in Folders class (to get the cheapest trips first for example)

trainline.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
3+
# A wrapper script for invoking a docker container
4+
# Based on https://spin.atomicobject.com/2015/11/30/command-line-tools-docker/
5+
6+
DOCKER_IMAGE="thibdct/trainline"
7+
8+
error(){
9+
error_code=$1
10+
echo "ERROR: $2" >&2
11+
exit $1
12+
}
13+
check_cmd_in_path(){
14+
cmd=$1
15+
which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!"
16+
}
17+
upgrade(){
18+
docker pull $DOCKER_IMAGE
19+
exit 1
20+
}
21+
uninstall(){
22+
read -p "Are you sure to uninstall (y/n)? " -n 1 -r
23+
echo
24+
if [[ $REPLY =~ ^[Yy]$ ]]
25+
then
26+
docker rmi $DOCKER_IMAGE
27+
rm $0
28+
fi
29+
exit 1
30+
}
31+
32+
# Checks for dependencies
33+
check_cmd_in_path docker
34+
35+
case $1 in
36+
--uninstall)
37+
uninstall
38+
;;
39+
--upgrade)
40+
upgrade
41+
;;
42+
esac
43+
44+
# Run our containerized command
45+
exec docker run -it --rm $DOCKER_IMAGE "$@"

0 commit comments

Comments
 (0)