Docker'ized the application.

master
Pacman Ghost 5 years ago
parent 4c054ba98e
commit 7d9ceac239
  1. 37
      Dockerfile
  2. 3
      docker/config/debug.cfg
  3. 31
      docker/config/logging.yaml
  4. 5
      docker/config/site.cfg
  5. 3
      docker/run.sh
  6. 6
      requirements-dev.txt
  7. 5
      requirements.txt
  8. 47
      setup.py
  9. 24
      vasl_templates/webapp/static/help/index.html
  10. 2
      vasl_templates/webapp/static/vassal.js
  11. 12
      vasl_templates/webapp/vassal.py

@ -0,0 +1,37 @@
# To build the image:
# docker build --tag vasl-templates .
# Add "--build-arg ENABLE_TESTS=1" to allow the test suite to be run against a container.
#
# To run a container:
# docker run --rm -it --name vasl-templates \
# -p 5010:5010 \
# -v .../vasl-6.4.3.vmod:/data/vasl.vmod \
# vasl-templates
FROM python:alpine3.6
# NOTE: pillow needs zlib and jpeg, lxml needs libxslt, we need build-base for gcc, etc.
RUN apk add --no-cache build-base zlib-dev jpeg-dev libxslt-dev
ENV LIBRARY_PATH=/lib:/usr/lib
WORKDIR /app
ARG ENABLE_TESTS
# install the Python requirements
COPY requirements.txt requirements-dev.txt ./
RUN pip install -r requirements.txt ; \
if [ "$ENABLE_TESTS" ]; then pip install -r requirements-dev.txt ; fi
# install the application
ADD vasl_templates vasl_templates
COPY setup.py LICENSE.txt ./
RUN pip install -e .
# copy the config files
COPY docker/config/* vasl_templates/webapp/config/
RUN if [ "$ENABLE_TESTS" ]; then echo "ENABLE_REMOTE_TEST_CONTROL = 1" >>vasl_templates/webapp/config/debug.cfg ; fi
EXPOSE 5010
COPY docker/run.sh .
CMD ./run.sh

@ -0,0 +1,3 @@
[Debug]
TEST_VASL_MODS = /test-data/vasl-vmods

@ -0,0 +1,31 @@
version: 1
formatters:
standard:
format: "%(asctime)s.%(msecs)03d | %(message)s"
datefmt: "%H:%M:%S"
handlers:
console:
class: "logging.StreamHandler"
formatter: "standard"
stream: "ext://sys.stdout"
file:
class: "logging.FileHandler"
formatter: "standard"
filename: "/tmp/vasl-templates.log"
mode: "w"
loggers:
werkzeug:
level: "WARNING"
handlers: [ "console" ]
vasl_mod:
level: "WARNING"
handlers: [ "console", "file" ]
update_vsav:
level: "WARNING"
handlers: [ "console", "file" ]
control_tests:
level: "DEBUG"
handlers: [ "console", "file" ]

@ -0,0 +1,5 @@
[Site Config]
FLASK_HOST = 0.0.0.0
VASL_MOD = /data/vasl.vmod

@ -0,0 +1,3 @@
#!/bin/sh
python /app/vasl_templates/webapp/run_server.py

@ -0,0 +1,6 @@
pytest==3.6.0
tabulate==0.8.2
lxml==4.2.4
pylint==1.9.2
pytest-pylint==0.9.0
pyinstaller==3.4

@ -0,0 +1,5 @@
flask==1.0.2
pyyaml==3.13
pillow==5.3.0
selenium==3.12.0
click==6.7

@ -1,11 +1,30 @@
""" Setup the package.
Install this module in development mode to get the tests to work:
pip install --editable .[dev]
pip install --editable .[dev]
"""
import os
from setuptools import setup, find_packages
# ---------------------------------------------------------------------
# NOTE: We break the requirements out into separate files so that we can load them early
# into a Docker image, where they can be cached, instead of having to re-install them every time.
def parse_requirements( fname ):
"""Parse a requirements file."""
lines = []
fname = os.path.join( os.path.split(__file__)[0], fname )
for line in open(fname,"r"):
line = line.strip()
if line == "" or line.startswith("#"):
continue
lines.append( line )
return lines
# ---------------------------------------------------------------------
setup(
name = "vasl_templates",
version = "0.6", # nb: also update constants.py
@ -13,27 +32,15 @@ setup(
license = "AGPLv3",
url = "https://github.com/pacman-ghost/vasl-templates",
packages = find_packages(),
install_requires = [
# Python 3.6.5
"flask==1.0.2",
# NOTE: PyQt5 requirements: https://doc.qt.io/qt-5/linux.html
# Linux: mesa-libGL-devel ; @"C Development Tools and Libraries"
# nb: WebEngine seems to be broken in 5.10.1 :-/
"PyQT5==5.10.0",
"pyyaml==3.13",
"pillow==5.3.0",
"selenium==3.12.0",
"click==6.7",
],
install_requires = parse_requirements( "requirements.txt" ),
extras_require = {
"dev": [
"pytest==3.6.0",
"tabulate==0.8.2",
"lxml==4.2.4",
"pylint==1.9.2",
"pytest-pylint==0.9.0",
"PyInstaller==3.4",
"gui": [
# NOTE: PyQt5 requirements: https://doc.qt.io/qt-5/linux.html
# Linux: mesa-libGL-devel ; @"C Development Tools and Libraries"
# nb: WebEngine seems to be broken in 5.10.1 :-/
"PyQT5==5.10.0",
],
"dev": parse_requirements( "requirements-dev.txt" ),
},
include_package_data = True,
data_files = [

@ -54,7 +54,7 @@
<p> While not essential, it is <em>strongly</em> recommended that you set up a <a href="https://virtualenv.pypa.io/en/stable/">virtual environment</a> first. Then, install the requirements:
<div class="code">
pip install .
pip install .[gui]
</div>
<h4> Running the desktop application </h4>
@ -316,6 +316,28 @@ export JSHINT_RHINO=~/bin/jshint-2.6.3/dist/jshint-rhino.js
</div>
Note that both of these are run as part of a normal <tt>pytest</tt> run.
<h2> Docker </h2>
<p> The webapp can be run using Docker. To create an image, <tt>cd</tt> to the project root and build the image e.g.
<div class="code">
docker build --tag vasl-templates .
</div>
<small><em>NOTE: To allow the test suite to be run against the container, add <tt>--build-arg ENABLE_TESTS=1</tt> to the command.</em></small>
<p> Then run the container:
<div class="code">
docker run --rm -it --name vasl-templates \
-p 5010:5010 \
-v /home/pacman-ghost/vasl/vasl-6.4.3.vmod:/data/vasl.vmod \
vasl-templates
</div>
<small><em>NOTE: The "Update VASL scenario" feature is currently not working in a container..</em></small>
<p> Note that if you have SElinux enabled, it may prevent the container from accessing the VASL <tt>.vmod</tt> file, in which case, you can allow access like this:
<div class="code">
chcon -Rt svirt_sandbox_file_t /home/pacman-ghost/vasl/vasl-6.4.3.vmod
</div>
<h2> Creating a pre-compiled package </h2>
<p> It is possible to compile the desktop application down to a single binary. This is typically done for the benefit of Windows users, but also works for other platforms. From the root directory of the repo:

@ -83,7 +83,7 @@ function do_update_vsav( vsav_data, fname )
$( "#vassal-shim-error .message" ).html( data.error ) ;
var log = "" ;
if ( data.stdout && data.stderr )
log = "=== STDOUT ===" + data.stdout + "\n=== STDERR ===\n" + data.stderr ;
log = "=== STDOUT ===\n" + data.stdout + "\n=== STDERR ===\n" + data.stderr ;
else if ( data.stdout )
log = data.stdout ;
else if ( data.stderr )

@ -246,11 +246,13 @@ class VassalShim:
raise SimpleError( "Can't find VASL module: {}".format( self.vasl_mod ) )
# locate the VASSAL shim JAR
if IS_FROZEN:
meipass = sys._MEIPASS #pylint: disable=no-member,protected-access
self.shim_jar = os.path.join( meipass, "vasl_templates/webapp/vassal-shim.jar" )
else:
self.shim_jar = os.path.join( os.path.split(__file__)[0], "../../vassal-shim/release/vassal-shim.jar" )
self.shim_jar = app.config.get( "VASSAL_SHIM" )
if not self.shim_jar:
if IS_FROZEN:
meipass = sys._MEIPASS #pylint: disable=no-member,protected-access
self.shim_jar = os.path.join( meipass, "vasl_templates/webapp/vassal-shim.jar" )
else:
self.shim_jar = os.path.join( os.path.split(__file__)[0], "../../vassal-shim/release/vassal-shim.jar" )
if not os.path.isfile( self.shim_jar ):
raise SimpleError( "Can't find the VASSAL shim JAR." )

Loading…
Cancel
Save