diff --git a/fri/DOCKER-README.md b/fri/DOCKER-README.md index 459d362..036b571 100644 --- a/fri/DOCKER-README.md +++ b/fri/DOCKER-README.md @@ -2,78 +2,99 @@ Open Terminal and run the following commands:- -```` +``` $ sudo apt-get update $ sudo apt-get install curl $ curl -fsSL https://get.docker.com/ | sh -```` -Optional command:- To run docker commands without sudo -```` +``` + +Optional command:- To run docker commands without sudo + +``` $ sudo usermod -aG docker -```` -The above command add the system username in the docker group, Restart the system to complete the process. +``` -After restart run +The above command adds the system username to the docker group. Restart the system to complete the process. -```` -$ sudo service docker start -```` +After restart, run + +``` +$ sudo service docker start +``` # Building FRI Container Now, we elaborate on building FRI as a container, together with the Kong API Gateway. Connect to the Server VM, assuming x.x.x.x to be the IP address of your server. -```` + +``` $ ssh -i "controlcore.pem" ubuntu@x.x.x.x -```` +``` + Perform Git clone if this is the first time you are configuring the Server -```` + +``` $ git clone git@github.com/ControlCore-Project/concore.git -```` +``` -First build the Docker Container of the FRI. -```` +First build & run the Docker Container of the FRI. + +``` $ git pull +$ cd fri + $ docker build -t fri . -```` + +$ docker run -d --name fri -p 8090:8080 fri +``` # Running Control-Core FRI with Kong as containers -If you are already running FRI, make sure to stop and clear existing FRI container as it is likely conflict with the port. If there is Kong gateway running in default ports, stop and clear it too. -```` +If you are already running FRI, make sure to stop and clear existing FRI containers as they will likely conflict with the port. If there is a Kong gateway running in default ports, stop and clear it too. + +``` $ docker stop fri $ docker rm fri $ docker stop kong $ docker rm kong -```` +$ docker stop kong-database +$ docker rm kong-database +``` -Start and configure Cassandra container for Kong API. -```` +Start and configure PostgreSQL container for Kong API. + +``` $ docker run -d --name kong-database \ - -p 9042:9042 \ - cassandra:3 + -p 5432:5432 \ + -e POSTGRES_USER=kong \ + -e POSTGRES_DB=kong \ + -e POSTGRES_PASSWORD=kong \ + postgres:13 +``` +Run the Kong migrations for PostgreSQL. +``` $ docker run --rm \ --link kong-database:kong-database \ - -e "KONG_DATABASE=cassandra" \ + -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ -e "KONG_PG_USER=kong" \ -e "KONG_PG_PASSWORD=kong" \ - -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ - kong kong migrations bootstrap -```` + kong/kong-gateway:latest kong migrations bootstrap +``` Start Kong -```` + +``` $ docker run -d --name kong \ --link kong-database:kong-database \ - -e "KONG_DATABASE=cassandra" \ + -e "KONG_DATABASE=postgres" \ -e "KONG_PG_HOST=kong-database" \ + -e "KONG_PG_USER=kong" \ -e "KONG_PG_PASSWORD=kong" \ - -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \ -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ @@ -83,62 +104,62 @@ $ docker run -d --name kong \ -p 8443:8443 \ -p 8001:8001 \ -p 8444:8444 \ - kong -```` + kong/kong-gateway:latest +``` Start FRI container -```` -$ nohup sudo docker run --name fri -p 8090:8080 fri > controlcore.out & -```` - -Delete if there is a previously configured Kong service. If not, skip this step. First you need to find the ID-VALUE for the route with a GET command before deleting the route and service. -```` -$ curl -X GET "http://localhost:8001/services/fri/routes" -```` -Use the ID output from above to issue the delete command as below (issue this only if you have a previous conflicting service definiton in kong. Otherwise, skip this step): -```` -$ curl -X DELETE "http://localhost:8001/services/fri/routes/ID-VALUE" -$ curl -X DELETE "http://localhost:8001/services/fri/" -```` +``` +$ nohup sudo docker run --name fri -p 8090:8080 fri > controlcore.out & +``` Define Kong Service and Route. -First Configure a Kong service, replacing the variable "private-ip" with the private IP address of your server below. -```` +First, configure a Kong service, replacing the variable "private-ip" with the private IP address of your server below. + +``` $ curl -i -X POST --url http://localhost:8001/services/ --data 'name=fri' --data 'url=http://private-ip:8090' -```` -Then configure route to the service -```` +``` + +Then configure a route to the service + +``` $ curl -i -X POST --url http://localhost:8001/services/fri/routes --data 'paths=/' -```` +``` Now, controlcore.org is routed through the Kong APIs. - # Troubleshooting the FRI Connect to the Server VM -```` + +``` $ ssh -i "controlcore.pem" ubuntu@x.x.x.x -```` +``` + Check the Server logs. -```` + +``` $ tail -f controlcore.out -```` +``` + or -```` + +``` $ docker logs fri -f -```` +``` + Find the FRI docker container -```` + +``` $ docker ps -```` -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -dfdd3b3d3308 fri "python main.py" 38 minutes ago Up 38 minutes 0.0.0.0:80->80/tcp fri +``` + +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfdd3b3d3308 fri "python main.py" 38 minutes ago Up 38 minutes 0.0.0.0:80->80/tcp fri Access the container -```` + +``` $ docker exec -it dfdd /bin/bash -```` +``` diff --git a/fri/docker-compose.yml b/fri/docker-compose.yml index 542536f..71bd5a2 100644 --- a/fri/docker-compose.yml +++ b/fri/docker-compose.yml @@ -9,20 +9,39 @@ services: - 8090:8080 command: tail -f /dev/null - kong-database: - image: cassandra:3 + postgres: + image: postgres:13 + container_name: kong-database + restart: always + environment: + POSTGRES_USER: kong + POSTGRES_PASSWORD: kong + POSTGRES_DB: kong ports: - - 9042:9042 + - 5432:5432 + volumes: + - postgres_data:/var/lib/postgresql/data + + kong-migrations: + image: kong + depends_on: + - postgres + environment: + KONG_DATABASE: postgres + KONG_PG_HOST: kong-database + KONG_PG_USER: kong + KONG_PG_PASSWORD: kong + command: kong migrations bootstrap kong: image: kong depends_on: - - kong-database + - kong-migrations environment: - KONG_DATABASE: cassandra + KONG_DATABASE: postgres KONG_PG_HOST: kong-database + KONG_PG_USER: kong KONG_PG_PASSWORD: kong - KONG_CASSANDRA_CONTACT_POINTS: kong-database KONG_PROXY_ACCESS_LOG: /dev/stdout KONG_ADMIN_ACCESS_LOG: /dev/stdout KONG_PROXY_ERROR_LOG: /dev/stderr @@ -34,4 +53,5 @@ services: - 8001:8001 - 8444:8444 - \ No newline at end of file +volumes: + postgres_data: \ No newline at end of file