diff --git a/.docker/sample.env b/.docker/sample.env new file mode 100644 index 000000000..91b69260a --- /dev/null +++ b/.docker/sample.env @@ -0,0 +1,9 @@ +# DAEMON_GROUP_ID=1420 # Match your docker group ID for permissions +# IMS_SERVER_PORT=8080 +# DOCKER_RANGERS_NETWORK=rangers +# IMS_DB_IMAGE=mariadb:10.5.24 +# IMS_DB_HOST_NAME=ranger_ims_database +# IMS_DB_DATABASE=ims +# IMS_DB_PASSWORD=7B33108D-4CD4-41B5-A244-B16F97038860 +# IMS_DB_ROOT_PASSWORD=% +# IMS_DB_ROOT_PASSWORD=ims-root diff --git a/.dockerignore b/.dockerignore index 4b6cf2f88..9415b08cc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ +/.docker /.hypothesis /.tox /build/ diff --git a/.gitignore b/.gitignore index bf788de6b..f1fc5bf4b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ /htmldocs/ /src/*.egg-info/ __pycache__/ +*.env +/.docker/* +!/.docker/sample.env diff --git a/MANIFEST.in b/MANIFEST.in index f0037cdc7..a1fe4acbb 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,6 @@ include .codecov.yml include .coveragerc +include .docker/sample.env include .dockerignore include .flake8 include .isort.cfg @@ -15,8 +16,10 @@ include bin/shell include bin/test_docker include codecov.yml include conf/directory-sample.yaml +include conf/imsd-docker-compose-sample.conf include conf/imsd-sample.conf include COPYRIGHT.txt +include docker-compose.yml include Dockerfile include LICENSE.txt include mypy.ini diff --git a/README.rst b/README.rst index a79d3a5f6..4c74fcb06 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,26 @@ To run all of the default test environments:: Running the Server ~~~~~~~~~~~~~~~~~~ +-------------------- +With docker-compose +-------------------- + +Run:: + + # First time setup; these files are mounted into the container + cp conf/imsd-docker-compose-sample.conf conf/imsd.conf + cp conf/directory-sample.yaml conf/directory.yaml + + If you need to override any of the environment variables set in + `docker-compose.yml`, copy `.docker/sample.env` to `/.env` and + uncomment and edit the neccessary variables. + + docker compose up + +------------------ +Outside docker +------------------ + To run the server will require some configuration, and if you try to start the server with the default configuration, you will probably see an error such as this:: 2020-03-12T09:16:55-0700 [ims.run._command.Command#info] Setting up web service at http://localhost:80/ @@ -58,6 +78,11 @@ To build and run the server (for development only):: tox run -e exec + +--------------------- +Settings Permissions +--------------------- + In your browser, open http://localhost:8080/ to reach the server. Log in as any user in the ``conf/directory.yaml`` directory file. In the ``conf/imsd.conf`` sample configuration file, the users ``Hardware`` and ``Loosy`` are administrators, and in the sample directory, all users have passwords that match their handles. You'll want to log in as one of those to set up an Event. Use the pull-down menu at the top right corner of the page (it will show the logged in user's Ranger handle), and select ``Admin``. On the next page, navigate to the Events page and create an event called ``Test``. @@ -66,6 +91,7 @@ In the box labeled ``Access for Test (writers)``, enter the string ``*``. That You should now be able to select your new event from the ``Event`` menu at the top right, and then create new incidents within that event. + Pull Requests ~~~~~~~~~~~~~ diff --git a/conf/imsd-docker-compose-sample.conf b/conf/imsd-docker-compose-sample.conf new file mode 100644 index 000000000..dd3abc004 --- /dev/null +++ b/conf/imsd-docker-compose-sample.conf @@ -0,0 +1,56 @@ +[Core] + +# Absolute or relative to parent of parent of this file +ServerRoot = . + +DataStore = MySQL +Directory = File + +# Absolute or relative to ServerRoot +ConfigRoot = conf +DataRoot = data +CachedResources = cache + +# Bind address +Host = localhost +Port = 8080 + +Admins = Hardware, Loosy + +#MasterKey = 6C21E8C9-8B83-4EA3-93BD-6C6EFE8A712B + +#JWTSecret = DD264110-3A97-4348-9473-6D50B582550C + +RequireActive = True + + +[Store:SQLite] + +# Relative to DataRoot +File = db.sqlite + + +[Store:MySQL] + +HostName = mysql +HostPort = 3306 + +Database = ims +UserName = ims +Password = ims + + +[Directory:File] + +# Relative to ConfigRoot +File = directory.yaml + + +[Directory:ClubhouseDB] + +Hostname = dms.rangers.example.com +HostPort = 3306 + +Database = rangers +Username = ims +Password = 9F29BB2B-E775-489C-9C20-9FE3EFEE1F22 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..2f8a041bd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,48 @@ +services: + app: + build: . + container_name: ranger_ims_server + user: :${DAEMON_GROUP_ID:-1420} + environment: + IMS_DIRECTORY: "${IMS_DIRECTORY:-File}" + IMS_DIRECTORY_FILE: "${IMS_DIRECTORY_FILE:-/opt/ims/conf/directory.yaml}" + IMS_DB_HOST_NAME: "${IMS_DB_HOST_NAME:-ranger_ims_database}" + IMS_DB_DATABASE: "${IMS_DB_DATABASE:-ims}" + IMS_DB_USER_NAME: "${IMS_DB_USER_NAME:-ims}" + IMS_DB_PASSWORD: "${IMS_DB_PASSWORD:-ims}" + volumes: + - ./conf:/opt/ims/conf + - ./:/srv/ims + ports: + - ${IMS_SERVER_PORT:-8080}:8080 + depends_on: + database: + condition: service_healthy + command: + - /opt/ims/bin/ims + - "--log-file" + - "-" + - "--config" + - "/opt/ims/conf/imsd.conf" + - server + + database: + image: "${IMS_DB_IMAGE:-mariadb:10.5.24}" + container_name: ranger_ims_database + environment: + MARIADB_DATABASE: "${IMS_DB_DATABASE:-ims}" + MARIADB_USER: "${IMS_DB_USER_NAME:-ims}" + MARIADB_PASSWORD: "${IMS_DB_PASSWORD:-ims}" + MARIADB_ROOT_HOST: "${IMS_DB_ROOT_HOST:-%}" + MARIADB_ROOT_PASSWORD: "${IMS_DB_ROOT_PASSWORD:-ims-root}" + volumes: + - ./.docker/mysql/data/:/var/lib/mysql + healthcheck: + test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + interval: 10s + timeout: 5s + retries: 5 + +networks: + default: + name: "${DOCKER_RANGERS_NETWORK:-rangers}"