diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d30ebd5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +*.example +.dockerignore +.git +.gitignore +Dockerfile +README.md +__pycache__ +docker-compose.yml diff --git a/.gitignore b/.gitignore index 789cefa..935cc0f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -db.sqlite3 *.pyc +.env.* +__pycache__ +db.sqlite3 eve_data/*.yaml -dscantool/settings.py \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d5e1b65 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,96 @@ +### BUILDER + +FROM python:3.9-alpine as builder + +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +WORKDIR /usr/src/main + +COPY ./requirements.txt . + +RUN set -eux; \ + apk add \ + gcc \ + libc-dev \ + libffi-dev \ + postgresql-dev \ + python3-dev \ + musl-dev \ + ; \ + pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/main/wheels -r requirements.txt + +### FINAL + +FROM python:3.9-alpine + +ENV DSCAN_HOME_DIR ${DSCAN_HOME_DIR:-/dscantool} +ENV DSCAN_WORK_DIR $DSCAN_HOME_DIR/app +ENV DSCAN_STATIC_DIR $DSCAN_HOME_DIR/static +ENV DSCAN_GROUP ${DSCAN_GROUP:-dscantool} +ENV DSCAN_GID ${DSCAN_GID:-10000} +ENV DSCAN_USER ${DSCAN_USER:-dscantool} +ENV DSCAN_UID ${DSCAN_UID:-10000} +ENV DSCAN_PORT ${DSCAN_PORT:-8000} +ENV GOSU_VERSION 1.16 + +WORKDIR $DSCAN_WORK_DIR + +COPY --from=builder /usr/src/main/wheels /wheels +COPY --from=builder /usr/src/main/requirements.txt . +COPY . $DSCAN_WORK_DIR + +# Install gosu +RUN set -eux; \ + \ + apk add --no-cache --virtual .gosu-deps \ + ca-certificates \ + dpkg \ + gnupg \ + ; \ + \ + dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ + \ +# verify the signature + export GNUPGHOME="$(mktemp -d)"; \ + gpg --batch --keyserver hkps://keyserver.ubuntu.com --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ + gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ + gpgconf --kill all; \ + rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ + \ +# clean up fetch dependencies + apk del --no-network .gosu-deps; \ + \ + chmod +x /usr/local/bin/gosu; \ +# verify that the binary works + gosu --version; \ + gosu nobody true + +# Install dscantool +RUN \ + set -eux; \ + mkdir -p $DSCAN_WORK_DIR; \ + mkdir -p $DSCAN_STATIC_DIR; \ + addgroup -g $DSCAN_GID $DSCAN_GROUP; \ + adduser -u $DSCAN_UID -h $DSCAN_HOME_DIR -G $DSCAN_GROUP -D $DSCAN_USER; \ + apk add libpq tini; \ + pip install --no-cache /wheels/*; \ + chmod +x $DSCAN_WORK_DIR/run.sh; \ + chown -R $DSCAN_USER:$DSCAN_GROUP $DSCAN_HOME_DIR + +# Get the EVE Static Data Export (SDE) +RUN \ + set -eux; \ + wget https://eve-static-data-export.s3-eu-west-1.amazonaws.com/tranquility/sde.zip; \ + unzip sde.zip; \ + for f in `find sde -iname "groupIDs.yaml"`; do cp $f ./eve_data/; done; \ + for f in `find sde -iname "typeIDs.yaml"`; do cp $f ./eve_data/; done; \ + rm -rf sde* + +EXPOSE $DSCAN_PORT +VOLUME $DSCAN_STATIC_DIR +ENTRYPOINT ["tini", "--"] + +CMD ["./run.sh"] diff --git a/README.md b/README.md index 18cdaaf..f049234 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,54 @@ # Nimos' Intel Tool -Nimos' Intel Tool is a web application that parses DScans and local scans from the game Eve Online. +Nimos' Intel Tool is a web application that parses DScans and local scans from the game Eve Online. I made it because my previous favorite Intel Tool dscan.me shut down and I wanted another one with a dark theme. +## Standalone installation + +(I have not tested this method) -## Installation 1. Clone this repository -2. Install requirements with `pip3 install -r requirements.txt` or from another source of your liking -3. Edit `dscan/settings.py` to your liking -4. Install database with `python3 manage.py migrate` +2. Install requirements with `pip install -r requirements.txt` or from another source of your liking +3. Edit `dscantool/settings.py` to your liking +4. Install database with `python manage.py migrate` +5. Generate static files `python manage.py collectstatic --noinput` + +### Optional: Import Type information from SDE -## Optional: Import Type information from SDE Note: Nimos' Intel Tool pulls all missing type information from ESI when needed. When starting out with an empty cache that can make the first scans take a couple of seconds to parse, but once a ship type is cached it won't be requested again. You can import all ship type information from SDE to "seed" the cache, but doing so is optional and the script is no longer maintained. Use at your own discretion or feel free to import the SDE another way. 1. Get the EVE Static Data Export (SDE) from https://developers.eveonline.com/resource/resources -2. Extract `groupIDs.yaml` and `typeIDs.yaml` from the SDE into eve_data -3. Run `python3 manage.py import_types` - +2. Extract `groupIDs.yaml` and `typeIDs.yaml` from the SDE into `eve_data` +3. Run `python manage.py import_sde` + +## Docker installation + +### Environment Variables + +| Variable | Default | Dscription | +|----------------------|-------------------------------------------------------|------------| +|`DSCAN_SECRET_KEY` |`&f8lk5k-b$^)-sdfij8gu9df7g9aa2zagdfh8iooijioukhrs_` |A secret key for a particular Django installation.| +|`DSCAN_ALLOWED_HOST` |`dscan.nimos.ws` |String representing the host/domain name that this Django site can serve.| +|`DSCAN_DB_ENGINE` |`django.db.backends.postgresql` |The database backend to use. The built-in database backends are: `django.db.backends.postgresql`, `django.db.backends.mysql`, `django.db.backends.sqlite3`, `django.db.backends.oracle`| +|`DSCAN_DB_NAME` |`dscantool` |The name of the database to use.| +|`DSCAN_DB_USER` |`dscantool` |The username to use when connecting to the database.| +|`DSCAN_DB_PASSWORD` |`dscantool` |The password to use when connecting to the database.| +|`DSCAN_DB_HOST` |`127.0.0.1` |Which host to use when connecting to the database.| +|`DSCAN_DB_PORT` |`5432` |The port to use when connecting to the database.| +|`DSCAN_LANGUAGE_CODE` |`en-us` |A string representing the language code for this installation.| +|`DSCAN_STATIC_URL` |`/static/` |URL to use when referring to static files located in `DSCAN_STATIC_ROOT`.| +|`DSCAN_STATIC_ROOT` |`/dscantool/static/` |The absolute path to the directory where collectstatic will collect static files for deployment.| +|`DSCAN_SITE_NAME` |`Nimos' Intel Tools` |The site name.| +|`DSCAN_EVE_IMAGE_URL` |`https://image.eveonline.com` |Link to EVE Online image server.| +|`DSCAN_REPOSITORY_URL`|`https://github.com/nimos/dscantool` |Link to development repository.| +|`DSCAN_ZKILLBOARD_URL`|`https://zkillboard.com` |Link to zKillboard.| +|`DSCAN_DOTLAN_URL` |`https://evemaps.dotlan.net` |Link to Dotlan.| +|`DSCAN_FEEDBACK` |`Brought to you by Nimos Endashi • Discord: Nimos#4951`|Feedback information.| ## Notes + This is just a little 2-day project, so don't expect the sleekest code. This tool relies heavily on caching. The first few scans will be slow until the database has seen most ship types and corporations, after a couple of scans performance should increase significantly. The up-side is that you never have to update the static data like you have to for many other EVE tools. -This tool has been tested with MySQL and SQLite. Feel free to use other database backends, but they might require minor fixes. When using MySQL, make sure your tables (specifically the dscan_scan and esi_invtype) use the 'utf8mb4' encoding. Otherwise it will error out trying to save certain characters. \ No newline at end of file +This tool has been tested with MySQL and SQLite. Feel free to use other database backends, but they might require minor fixes. When using MySQL, make sure your tables (specifically the `dscan_scan` and `esi_invtype`) use the 'utf8mb4' encoding. Otherwise it will error out trying to save certain characters. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6342d7c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,55 @@ +version: '3.9' + +# +# !!! ATTENTION !!! +# It doesn't work. +# Use it as an example. +# + +networks: + front: + dscan: + +services: + + nginx: + image: "nginx:alpine" + container_name: nginx + restart: always + volumes: + - ./dscan/dscantool/static:/dscantool/static + ports: + - 80:80 + networks: + - front + + dscan: + build: + context: ./ + dockerfile: Dockerfile + container_name: dscan + restart: always + environment: + - DSCAN_ALLOWED_HOST=dscan.localdomain + - DSCAN_DB_HOST=dscan_postgres + volumes: + - ./dscan/dscantool/static:/dscantool/static + depends_on: + - dscan_postgres + networks: + - front + - dscan + logging: *default-logging + + dscan_postgres: + image: "postgres:15-alpine" + container_name: dscan_postgres + restart: always + environment: + - POSTGRES_DB=dscantool + - POSTGRES_USER=dscantool + - POSTGRES_PASSWORD=dscantool + networks: + - dscan + volumes: + - ./dscan/postgres/data:/var/lib/postgresql/data diff --git a/dscan/templates/about.html b/dscan/templates/about.html index b342555..90a2e0e 100644 --- a/dscan/templates/about.html +++ b/dscan/templates/about.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% block title %}- About{%endblock title %} +{% block title %}About | {{site_name}}{%endblock title %} {% block content %}
@@ -25,9 +25,8 @@

License

GNU Affero General Public License for more details.

- The full license can be found here. + The full license can be found here.

{% endblock content %} - diff --git a/dscan/templates/base.html b/dscan/templates/base.html index ac07a81..27dbccc 100644 --- a/dscan/templates/base.html +++ b/dscan/templates/base.html @@ -5,11 +5,8 @@ - - + + {% if debug %} @@ -17,7 +14,7 @@ {% else %} {% endif %} - {% block title %}Nimos' Intel Tool{% endblock title %} + {% block title %}{{site_name}}{% endblock title %} {% block meta %} {% endblock meta %} @@ -26,14 +23,9 @@ {% endblock content %} -