Skip to content

Commit

Permalink
v2.3.0 - Docker support + Improved caching
Browse files Browse the repository at this point in the history
- Docker Support
    - Added `Dockerfile` for building a Docker image (python3.9-alpine based for minimal size) from the project.
    - Added `example-docker-compose.yml` - which is used as a base for the user's `docker-compose.yml` for easy management of the app inside of Docker, with Redis linked to it.
    - Added `dkr/` folder to store docker-related files and folders, including various example files in `dkr/config` folder
    - Added `prep-docker.sh` and `start-docker.sh` for generating config files from the example files, and easily preparing an environment to use docker-compose
    - Added `,dockerignore`

- Improved Caching
    - The application is no longer tightly bound to Redis, though it's still recommended. It now uses privex-helpers' Cache Abstraction Layer, which allows the use of Redis, Memcached, SQLite, in-memory cache, or other future adapters.
    - The `REDIS_` settings in `settings.py` now also change the ones in `privex.helpers.settings` so that redis env vars configure the privex-helpers' cache abstraction
    - The heart of `core.get_rdns` was refactored into `get_rdns_base`, while `get_rdns` calls it, and is wrapped by `r_cache` for transparent caching via the selected privex-helpers' cache abstraction adapter
    - `app.get_geodata` now uses `core.get_cache` (wrapper for privex-helpers' adapter_get and adapter_set) instead of `get_redis`
    - `core.get_redis` has been commented out, since it's no longer used

- Other stuff
    - Removed `"full"` extra from privex-helpers, and simply added the actual optional extra packages that the project needs by hand, since `pipenv install` was taking a very long time.
    - Improved `example.env` including adding more example ENV variables
    - Improved `.gitignore`
    - Updated shebang in `run.sh` to use `/usr/bin/env bash` instead of just `/bin/bash`
    - Updated `update_geoip.sh` with PATH, env shebang, overridable env vars, automatic sudo, and now rsync's the DB files from files.privex.io instead of wget'ing from the dead maxmind download URLs.

- Overhauled the README
    - Added Table of Contents near the start, thanks to this small web app: https://ecotrust-canada.github.io/markdown-toc/
    - Added **Features** section under first heading, which explains what the index HTML page can do, as well as the various API functionalities
    - Updated requirements to confirm py3.8 and 3.9 work great
    - Added section for **Docker**, including running a solo container, and running with docker compose
    - Added section on **keeping GeoIP2 databases up to date** using maxmind's `geoipupdate` tool, with detailed instructions on installation and config on ubuntu/debian
    - Reformatted **thanks for reading** section, as the line was way too long.

- Plus probably some other stuff that I've forgot to mention :)
  • Loading branch information
Someguy123 committed Jun 29, 2021
1 parent 0e53025 commit 040f89f
Show file tree
Hide file tree
Showing 25 changed files with 973 additions and 315 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git/
.idea/
.vscode/
.env
logs/
*.log
*.swp

dkr/data
dkr/config/caddy
43 changes: 38 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,43 @@ DEBUG=false
FLASK_ENV=production
FLASK_DEBUG=0

V4_HOST=ipv4.myip.example.com
V6_HOST=ipv6.myip.example.com
MAIN_HOST=myip.example.com
EXTRA_HOSTS=myip.vc,address.computer

IP_HEADER=X-REAL-IP
V4_SUBDOMAIN=v4
V6_SUBDOMAIN=v6

#### V4_HOST and V6_HOST aren't normally needed due to using V4/V6_SUBDOMAIN
# V4_HOST=ipv4.myip.example.com
# V6_HOST=ipv6.myip.example.com

#### Can be: redis, memcached, sqlite, memory
# CACHE_ADAPTER=auto
# CACHE_ADAPTER_INIT=true

# REDIS_HOST=localhost
# REDIS_PORT=6379
# REDIS_DB=0

# IP_HEADER=X-REAL-IP

# HOST=127.0.0.1
# HOST=::1
# PORT=5151
# FILTER_HOSTS=true

# USE_RICH_LOGGING=true
# RICH_TRACEBACKS=true
# LOG_LEVEL=WARNING
#### LOG_DIR can be relative to myip app, or absolute path e.g. /var/log/myip
# LOG_DIR=logs

#####
# Generally for development/debugging only:
#####
# USE_FAKE_IPS=true
# USE_IP_HEADER=false
# FORCE_MAIN_HOST=false
# FLASK_ENV=development
# FLASK_DEBUG=1

HOST=127.0.0.1
PORT=5151
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
venv/
env/
.vscode/
.idea/
.env

*.log
*.swp
*.db
*.sqlite3
*.pyc

__pycache__

docker-compose.yml
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM python:3.9-alpine

RUN apk update && \
apk add libmemcached-dev postgresql-dev libpq mariadb-dev mariadb-connector-c-dev openssl-dev && \
apk add gcc musl-dev libffi-dev py-cryptography python3-dev

RUN apk add curl wget bash zsh


RUN pip3 install -U pip && \
pip3 install -U pipenv

RUN curl https://sh.rustup.rs -sSf | sh -s -- --profile default --default-toolchain nightly -y

ENV PATH "${HOME}/.cargo/bin:${PATH}"
ARG PATH="${PATH}"

WORKDIR /app

RUN apk add sudo rsync
RUN mkdir /app/logs
COPY Pipfile Pipfile.lock requirements.txt update_geoip.sh /app/

VOLUME /usr/local/var/GeoIP
RUN /app/update_geoip.sh

RUN sed -Ei 's/python\_version \= "3.8"/python_version = "3.9"/' Pipfile
RUN PATH="${HOME}/.cargo/bin/:${PATH}" pipenv --python python3.9 install --ignore-pipfile

COPY .env.example LICENSE.txt README.md run.sh update_geoip.sh wsgi.py /app/
COPY myip/ /app/myip/
COPY static/ /app/static/
COPY dkr/init.sh /app/
RUN chmod +x /app/init.sh /app/update_geoip.sh /app/run.sh /app/wsgi.py

EXPOSE 5252

ENTRYPOINT [ "/app/init.sh" ]

5 changes: 4 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ gunicorn = "*"
flask-cors = ">=3.0.8"
rich = "*"
accept-types = "*"
privex-helpers = {version = ">=3.0", extras = ["full"]}
#privex-helpers = {version = ">=3.0", extras = ["cache"]}
privex-helpers = ">=3.0"
pylibmc = "*"
requests = ">=2.2"
pyyaml = "*"
markdown = ">=3.0.1"
aiohttp = ">=3.7.4"
privex-db = ">=0.9.2"

[requires]
python_version = "3.8"
Loading

0 comments on commit 040f89f

Please sign in to comment.