From fcfbbe8809c4ff3c4209a503a62d1d2d1f0215f0 Mon Sep 17 00:00:00 2001 From: "R. Miles McCain" Date: Thu, 28 May 2020 21:47:17 +0000 Subject: [PATCH] Remove confusing setup variables; migrate to commands. --- Dockerfile | 2 +- GUIDE.md | 21 ++++++++------------- shynet/entrypoint.sh | 8 ++++---- shynet/manage.py | 2 +- shynet/startup_checks.sh | 27 +++------------------------ 5 files changed, 17 insertions(+), 43 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97bcec5..c6cb7d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,4 +32,4 @@ RUN python manage.py collectstatic --noinput && \ # Launch USER appuser EXPOSE 8080 -ENTRYPOINT [ "./entrypoint.sh" ] +CMD [ "./entrypoint.sh" ] diff --git a/GUIDE.md b/GUIDE.md index f8f7127..8610191 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -32,29 +32,24 @@ Before continuing, please be sure to have the latest version of Docker installed 3. Configure an environment file for Shynet, using [this file](/TEMPLATE.env) as a template. (This file is typically named `.env`.) Make sure you set the database settings, or Shynet won't be able to run. -4. Launch the Shynet server by running `docker run --env-file= milesmcc/shynet:latest`. Watch the output of the script; if it's the first run, you'll see a temporary password printed that you can use to log in. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`. +4. Launch the Shynet server for the first time by running `docker run --env-file= milesmcc/shynet:latest`. Provided you're using the default environment information (i.e., `PERFORM_CHECKS_AND_SETUP` is `True`), you'll see a few warnings about not having an admin user or host setup; these are normal. Don't worry — we'll do this in the next step. You only need to stop if you see a stacktrace about being unable to connect to the database. -5. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 4. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead. +5. Create an admin user by running `docker run --env-file= milesmcc/shynet:latest ./manage.py registeradmin `. A temporary password will be printed to the console. -6. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page. +6. Set the hostname of your Shynet instance by running `docker run --env-file= milesmcc/shynet:latest ./manage.py hostname `, where `` is the _publicly accessible hostname_ of your instance, including port. This setting affects the URL that the tracking script sends its results to, so make sure it's correct. (Example hostnames: `shynet.rmrm.io` or `example.com:8000`.) -7. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track. +7. Set the whitelabel of your Shynet instance by running `docker run --env-file= milesmcc/shynet:latest ./manage.py whitelabel `. While this setting doesn't affect any core operations of Shynet, it lets you rename Shynet to whatever you want. (Example whitelabels: `"My Shynet Instance"` or `"Acme Analytics"`.) -## Updating Your Configuration +8. Launch your webserver by running `docker run --env-file= milesmcc/shynet:latest`. You may need to bind Docker's port 8080 (where Shynet runs) to your local port 80 (http); this can be done using the flag `-p 80:8080` after `run`. Visit your service's homepage, and verify everything looks right! You should see a login prompt. Log in with the credentials from step 5. You'll probably be prompted to "confirm your email"—if you haven't set up an email server, the confirmation email will be printed to the console instead. -When you first setup Shynet, you set a number of environment variables that determine first-run initialization settings (these variables start with `SHYNET_`). Once they're first set, though, changing them won't have any effect. Be sure to run the following commands in the same way that you deploy Shynet (i.e., linked to the same database). +9. Create a service by clicking "+ Create Service" in the top right hand corner. Fill out the options as appropriate. Once you're done, press "create" and you'll be redirected to your new service's analytics page. -* Create an admin account by running `docker run --env-file= milesmcc/shynet:latest python manage.py registeradmin `. The command will print a temporary password that you'll be able to use to log in. - -* Configure Shynet's hostname (e.g. `shynet.example.com` or `localhost:8000`) by running `docker run --env-file= milesmcc/shynet:latest python manage.py hostname ""`. This doesn't affect Shynet's bind port; instead, it determines what hostname to inject into the tracking script. (So you'll want to use the "user-facing" hostname here.) - -* Name your Shynet instance by running `docker run --env-file= milesmcc/shynet:latest python manage.py whitelabel ""`. This could be something like "My Shynet Server" or "Acme Analytics"—whatever suits you. +10. Finally, click on "Manage" in the top right of the service's page to get the tracking script code. Inject this script on all pages you'd like the service to track. --- ## Enhancements - ### Installation with SSL If you are going to be running Shynet through a reverse proxy, please see [Configuring a Reverse Proxy](#configuring-a-reverse-proxy) instead. @@ -187,7 +182,7 @@ Here are solutions for some common issues. If your situation isn't described her #### I changed the `SHYNET_WHITELABEL`/`SHYNET_HOST` environment variable, but nothing happened! -* Those values only affect how your Shynet instance is setup on first run; once it's configured, they have no effect. See [updating your configuration](#updating-your-configuration) for help on how to update your configuration. +* Those values only affect how your Shynet instance is setup on first run; once it's configured, they have no effect. See [updating your configuration](#updating-your-configuration) for help on how to update your configuration. (Note: these environment variables are not present in newer Shynet versions; they have been removed from the guide.) #### Shynet can't connect to my database running on `localhost`/`127.0.0.1` diff --git a/shynet/entrypoint.sh b/shynet/entrypoint.sh index 0c6e4bc..c53c326 100755 --- a/shynet/entrypoint.sh +++ b/shynet/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ ! $PERFORM_CHECKS_AND_SETUP == False ]]; then - ./startup_checks.sh -fi - -./webserver.sh + ./startup_checks.sh && exec ./webserver.sh + else + exec ./webserver.sh +fi \ No newline at end of file diff --git a/shynet/manage.py b/shynet/manage.py index 1f0fb41..2654836 100755 --- a/shynet/manage.py +++ b/shynet/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """Django's command-line utility for administrative tasks.""" import os import sys diff --git a/shynet/startup_checks.sh b/shynet/startup_checks.sh index 6193b0a..060190b 100755 --- a/shynet/startup_checks.sh +++ b/shynet/startup_checks.sh @@ -13,33 +13,12 @@ if [[ ${sanity_results[0]} == True ]]; then echo "Database is ready to go." fi if [[ -n $SHYNET_ADMIN_EMAIL && ${sanity_results[1]} == True ]]; then - echo "Creating an admin user..." - { - temppwd=$( ./manage.py registeradmin $SHYNET_ADMIN_EMAIL ) && echo "Admin user ($SHYNET_ADMIN_EMAIL) created! Password: $temppwd" - } || { - echo "Failed to create admin, exiting" & exit 1 - } - else - echo "Making no changes to admin user." + echo "Warning: no admin user available. Consult docs for instructions." fi if [[ -n $SHYNET_HOST && ${sanity_results[2]} == True ]]; then - echo "Setting hostname..." - { - ./manage.py hostname $SHYNET_HOST && echo "Hostname set to $SHYNET_HOST!" - } || { - echo "Failed setting hostname, exiting" & exit 1 - } - else - echo "Making no changes to hostname." + echo "Warning: Shynet's hostname is not set. The script won't work correctly. Consult docs for instructions." fi if [[ -n $SHYNET_WHITELABEL && ${sanity_results[3]} == True ]]; then - echo "Setting whitelabel..." - { - ./manage.py whitelabel "$SHYNET_WHITELABEL" && echo "Whitelabel set! Whitelabel: $SHYNET_WHITELABEL" - } || { - echo "Failed to set whitelabel, exiting" & exit 1 - } - else - echo "Making no changes to whitelabel." + echo "Warning: Shynet's whitelabel is not set. Consult docs for instructions." fi echo "Startup checks complete!"