Deploy locally

2 minute read

Deploying the code locally from your computer can be useful to test some features and making sure all the bugs are fixed before pushing your changes to the Github repository.

Preliminary steps

  • Create a GitHub account
  • Install Docker Desktop

  • Once your done with the steps above, you will need to clone locally the GitHub repository (documentation).
     git clone https://github.com/Paleoclim-CNRS/netcdf_editor_app.git
    

    or

     git clone git@github.com:Paleoclim-CNRS/netcdf_editor_app.git
    
Wondering which in you should choose ?
Use SSH as a more secure option and HTTPS for basic password-based Git usage. You can find more information here.

If you plan to go for ssh, copy your ssh key to github first (follow this documentation).

At this step, you should have a copy of the Netcdf Editor Application on you local computer.

  • Move in the repository cd netcdf-editor-app

  • Make sure your repository is ready

    Fetch latest changes:

    git fetch
    

    If you have done any modification in the repository, you can undo it by using (restore the state of the local repository to match the state of the remote branch):

    git reset --hard @{u}
    

Single Page Web App

  • Change into the Single Page directory:
    cd Single_Page_WebApp
    
  • Build the image:
    docker build -f single_page_webapp.Dockerfile -t netcdf_editor_single_page . --no-cache
    

    The --no-cache means everything gets rebuilt

  • Start the container:
    docker run -d -p 8080:8080 netcdf_editor_single_page 
    
    • -d means detached mode so once the containers all start the command line is returned to you
    • -p is for port selection
      The first 8080 is the port on the local machine you can change this to whatever you want.
      The second 8080 is the entry port for the application. If you change it, modify the dockerfile Single_Page_WebApp/single_page_webapp.Dockerfile under ENTRYPOINT option --port as well.
  • Connect to the container via http://localhost:8080 (the 8080 refering to the first 8080 in command above)

Multi Page Web App

  • Make sure nothing is running:
    docker-compose -f docker-compose.yaml --env-file ./config/.env.prod down
    
  • Delete the docker volume (If there has been a database upgrade)
    • List volumes:
      docker volume ls 
      
    • Remove associated volume:
      docker volume rm netcdf_editor_app_instance_storage
      

      or remove all volumes of stopped containers:

      docker volume prune
      

You can deploy the application in 2 different ways:

  • PRODUCTION mode
    Designed for development. It uses images sent to DockerHub to deploy the containers. Modifications of you local code won't be visible on the deployed application.
    • Run
      docker-compose -f docker-compose.yaml --env-file ./config/.env.prod up --build -d --scale python_worker=2
      
    • Connect to the application via http://localhost:43829 (the port is defined in config/.env.prod under NGINX_PORT)
  • DEVELOPMENT mode
    Designed for development. Creates images from local dockerfiles and deploys containers from them - allows to see changes made in the code straight away without having to relaunch containers.
    If you want to know more about this, check here.
    • If this is the first time running the database then you will need to initialize it with the following commands
      • Get command line access to the flask container:
        docker exec -it netcdf_editor_app-flask_app-1 /bin/bash
        

        initialize database:

        python -m flask init-db
        
      • or use the one liner command:
        docker exec -it netcdf_editor_app_flask_app_1 python -m flask init-db
        

      If you don’t do this you might get a sqlite3.OperationalError error when running the application

    • Run:
      docker-compose -f docker-compose.dev.yaml --env-file ./config/.env.dev up --build -d --scale python_worker=2
      
    • Connect to the application via http://localhost:5000 (the port is defined in config/.env.dev under NGINX_PORT)

Updated: