Skip to content

Suggested Deployment

daviddob edited this page Aug 11, 2016 · 17 revisions

Introduction

This is a guide to setup a fully self-sufficient Tango deployment environment out-of-the-box using Docker. The suggested deployment pattern for Tango uses Nginx as a proxy and Supervisor as a process manager for Tango and all its dependencies. All requests to Nginx are rerouted to a Tango process.

Details

  • Nginx default port - 8600
  • Tango ports - 8610, 8611
  • Redis port - 6379
  • You can change any of these in the respective config files in deployment/config/ before you build the tango_deployment image.

Steps

  1. Clone the Tango repo

    $ git clone https://github.com/autolab/Tango.git; cd Tango
  2. Create a config.py file from the given template.

    $ cp config.template.py config.py
  3. Install docker on host machine by following instructions on the docker installation page. Ensure docker is running by doing a docker ps.

  4. Run the following command to build the Tango deployment image.

    $ docker build --tag="tango_deployment" .
  5. Ensure the image was built by running docker images; tango_deployment should appear in the list of images.

  6. Run the following command to access the image in a container with a bash shell. The -p flag will map nginxPort on the docker container to localPort on your local machine (or on the VM that docker is running in on the local machine) so that Tango is accessible from outside the docker container.

    $ docker run --privileged -p <localPort>:<nginxPort> -it tango_deployment /bin/bash
  7. Now, inside the container, edit config.py with Docker container specific options (COURSELABS path, OUTPUT path, DOCKER_VOLUME_PATH, etc...). Furthermore, ensure that USE_REDIS = True.

  8. Run the following command to start supervisor, which will then start Tango and all its dependencies.

    $ service supervisor start
  9. Run curl localhost:<nginxPort> to ensure everything was setup correctly and that Nginx is correctly routing requests. You should see a hello world message from Tango.

  10. Follow these directions to get started with setting up the localDocker VMMS for Tango within the Docker container. Note that this VMMS can be substituted for any other one on the list of supported VMMS's.

  11. Once you have the localDocker VMMS set up, leave the tango_deployment container by typing exit and once back in the host shell run the following command to get the name of your production container.

    $ docker ps -as
    
    CONTAINER ID        IMAGE               COMMAND               NAMES               SIZE
    c704d45c3737    tango_deployment       "/bin/bash"            erwin             40.26 MB 
    
  12. The container created in this instance has the name erwin. The name of the production container can be changed by running the following command and will be used to run the container and create services.

    $ docker rename <old_name> <new_name>
  13. To reopen the container once it has been built you use the following command. This will reopen the interactive shell within the container and allow for configuration of the container after its initial run.

    $ docker start erwin
    $ docker attach erwin
  14. Once the container is set up with the autograding image local_vmms configured with any necessary software/environments needed for autograding (java, perl, etc) some configurations need to be changed to make the container daemon ready. Using the container_id above, there is a config.v2.json file that needs to be changed.

    $ sudo ls  /var/lib/docker/containers
    c704d45c37372a034cb97761d99f6f3f362707cc23d689734895e017eda3e55b
    $ sudo vim /var/lib/docker/containers/c704d45c37372a034cb97761d99f6f3f362707cc23d689734895e017eda3e55b/config.v2.json
  15. Edit the "Path" field in the config.v2.json file from "/bin/bash" to "/usr/bin/supervisord" and save the file then run the following commands to verify the changes were successful. The COMMAND field should now be "/usr/bin/supervisord"

    $ service docker restart
    $ docker ps -as
    
    CONTAINER ID        IMAGE               COMMAND               NAMES               SIZE
    c704d45c3737    tango_deployment   "/usr/bin/supervisord"     erwin             40.26 MB 
  16. At this point when the container is started the environment is fully set up and will no longer be an interactive shell but will be the supervisor service which will then start Tango and all its dependencies. Test this with the following commands and ensure Tango is functioning properly.

    $ docker start erwin
    (Test tango environment)
    $ docker stop erwin
  17. To ensure Tango starts with the system in the production environment the container needs to be configured as a service. Below is a sample service config file that needs to be changed to suit your environment and placed in "/etc/systemd/system/" The file should be named .service so for this example it is erwin.service

    [Unit]
    Description=Docker Service Managing Tango Container
    Requires=docker.service
    After=docker.service
    
    [Service]
    Restart=always
    ExecStart=/usr/bin/docker start -a erwin
    ExecStop=/usr/bin/docker stop -t 2 erwin
    
    [Install]
    WantedBy=default.target
  18. Test and ensure the service was set up correctly. The service should start successfully and remain running.

    $ systemctl daemon-reload
    $ service erwin start
    $ service erwin status
  19. Enable the service at system startup and reboot and ensure it starts with the host.

    $ systemctl enable erwin.service
    $ sudo reboot
    (Server Reboots)
    $ service erwin status
  20. Test the setup using the testing guide.

Clone this wiki locally