Skip to content

Latest commit

 

History

History
118 lines (76 loc) · 3.24 KB

README.md

File metadata and controls

118 lines (76 loc) · 3.24 KB

Visitors Serivce

The code base of visitors service in this repo references https://github.com/jdob/visitors-service.

It's dependent by the visitors web ui which is located at visitors-webui.

Run server in local

To run visitors-service locally, following instructions below:

  1. Check if python3.8 is installed in your local envrionment:

    python3 --version
    
  2. If not, run the following commands to install python3.8:

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt-get update
    sudo apt-get install python3.8
    
  3. If you have other python version installed (e.g., python3.10), select python3.8:

    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
    update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
     
    update-alternatives --config python3
    

    Enter number 1 to select python3.8.

  4. Install pip, python3.8-dev and python3.8-venv packages

    sudo apt install python3-pip
    sudo apt-get install python3.8-dev python3.8-venv
    
  5. Change directory to visitors-service, then run the following commands to start server:

    python3 -m venv .venv
    source .venv/bin/activate
    
    pip install -r requirements.txt
    ./startup.sh
    

    You will see the following message in the output, which indicates the server is successfully started:

    Starting development server at http://0.0.0.0:8000/
    Quit the server with CONTROL-C.
    
  6. Open http://localhost:8000/visitors/ in the browser and you should see an empty array [] displayed in the page.

Stop server

Follow steps below to stop server and quit the virtual environment.

  1. Press CONTROL-C to quit the server.

  2. Quit the virtual environment:

    deactivate
    
  3. If your system installed other python version (e.g., python3.10), switch it back:

    update-alternatives --config python3
    

    Enter the specific number to switch back to python3.10.

Run server in Docker

Containerize the application so that it can run as a contanier in Docker or Kubernetes cluster.

Build application image

Change directory to visitors-service, then run the following commands to build a Docker image and push to DockerHub:

docker build -t visitors-service:1.0.0 .
docker tag visitors-service:1.0.0 <DockerHub-account>/visitors-service:1.0.0
docker push <DockerHub-account>/visitors-service:1.0.0

Run as container

Execute the command below to run the containerzed application in Docker.

docker run -it --rm -p 8000:8000 --name visitors-service visitors-service:1.0.0

Open http://localhost:8000/visitors/ in the browser and you should see an empty array [] displayed in the page.

Stop the container

To stop running the containerzed application, you can press CONTROL-C or execute the command below in a separate CLI.

docker stop visitors-service

References