Skip to content

Commit d93eec6

Browse files
author
mgoddard
committed
Adding Docker build and K8s YAML file
1 parent d2220b0 commit d93eec6

9 files changed

+93
-3
lines changed

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.8-slim-buster
2+
WORKDIR /app
3+
COPY . /app
4+
RUN apt-get update && apt-get --yes --no-install-recommends install python3-dev build-essential cmake && rm -rf /var/lib/apt/lists/*
5+
RUN pip3 install --no-cache-dir -r requirements.txt && rm -rf ~/.cache/pip
6+
EXPOSE 18080
7+
ENTRYPOINT [ "python", "./map_app.py" ]
8+

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,22 @@ time it takes to load the amenity icons in the browser.
5353
$ export USE_GEOHASH=true
5454
```
5555

56+
## Rebuild the Docker image (optional)
57+
58+
Edit Dockerfile as necessary, and then change `./docker_include.sh` to set
59+
`docker_id` and anything else you'd like to change.
60+
61+
```
62+
$ ./docker_build_image.sh
63+
$ ./docker_tag_publish.sh
64+
65+
```
66+
67+
## Run the app via its Docker image
68+
69+
Edit `./docker_run_image.sh`, changing the environment variables to suit your deployment.
70+
71+
```
72+
$ ./docker_run_image.sh
73+
```
74+

crdb-geo-tourist.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: crdb-geo-tourist
5+
spec:
6+
containers:
7+
- name: crdb-geo
8+
image: mgoddard/crdb-geo-tourist:1.0
9+
imagePullPolicy: Always
10+
env:
11+
- name: PGHOST
12+
value: ""
13+
- name: PGPORT
14+
value: "26257"
15+
- name: PGDATABASE
16+
value: "defaultdb"
17+
- name: PGUSER
18+
value: "root"
19+
- name: PGPASSWORD
20+
value: ""
21+
- name: MAPBOX_TOKEN
22+
value: "INSERT YOUR MAPBOX TOKEN VALUE HERE"
23+
- name: USE_GEOHASH
24+
value: "False"
25+
restartPolicy: Always
26+

docker_build_image.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
. ./docker_include.sh
4+
5+
docker build -t $docker_id/$img_name .
6+

docker_include.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tag=1.0
2+
docker_id="mgoddard"
3+
img_name="crdb-geo-tourist"

docker_run_image.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
. ./docker_include.sh
4+
5+
img="$docker_id/$img_name"
6+
tag="1.0"
7+
8+
export PGHOST="host.docker.internal"
9+
export PGPORT="26257"
10+
export PGDATABASE="defaultdb"
11+
export PGUSER="root"
12+
export PGPASSWORD=""
13+
export MAPBOX_TOKEN=$( cat ../MapBox_Token.txt )
14+
export USE_GEOHASH=False
15+
16+
docker pull $img:$tag
17+
docker run -e PGHOST -e PGPORT -e PGDATABASE -e PGUSER -e PGPASSWORD -e MAPBOX_TOKEN --publish 18080:18080 $img
18+

docker_tag_publish.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
. ./docker_include.sh
4+
5+
docker tag $docker_id/$img_name $docker_id/$img_name:$tag
6+
docker image tag $docker_id/$img_name:$tag $docker_id/$img_name:latest
7+
docker push $docker_id/$img_name:$tag
8+

map_app.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#
1414
# Prior to running, set the two required connection parameters as environment variables:
1515
#
16-
# $ export PGHOST=192.168.1.4
17-
# $ export PGPORT=5432
16+
# $ export PGHOST=192.168.1.9
17+
# $ export PGPORT=26257
1818
#
1919

2020
useGeohash = False
@@ -23,7 +23,8 @@ def db_connect():
2323
return psycopg2.connect(
2424
database=os.getenv("PGDATABASE", "defaultdb"),
2525
user=os.getenv("PGUSER", "root"),
26-
application_name="Map Client"
26+
password=os.getenv("PGPASSWORD", ""),
27+
application_name="CRDB Geo Tourist"
2728
)
2829

2930
def get_db():

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
psycopg2-binary
22
Flask
33
gunicorn
4+
python-geohash
45
Geohash
56
flask-cors

0 commit comments

Comments
 (0)