cabaleirog / earthquake-tracker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seismic Tracker

Set up

1.- Install Docker

If Docker is not already installed lets proceed to install it, by either using the official documentation, or the script from GetDocker. Furthermore, we will install Docker Compose for development, and/or building the container images; Docker compose installation guide can be found here.

2.1.- Initialize a Docker Swarm (Production only)

Set up the manager node.

sudo docker swarm init --advertise-addr $(hostname -i)

Save the stack file (docker-compose.yml) into the machine and create a new stack.

sudo docker stack deploy --compose-file docker-compose.yml earthquakes

2.2.- Start using Docker Compose (Development only)

To initialize the application using Docker Compose, we can simple go to the project's folder and run the following command.

sudo docker-compose up

However, as the database is going to be missing at this point, we need to complete the below steps, and might need to restart the application afterwards, as the api service would have failed, and might not recover on its own.

3.- Create database

Go to the Adminer UI (Current user is root, and password can be found on the docker-compose file, under MYSQL_ROOT_PASSWORD). Once logged in, click on Create Database and create one called locations.

4.- Add starting locations to the database

Locations can be added either directly by API calls, or by using Adminer.

Some example API calls are set below for convenience.

curl --location --request POST 'http://127.0.0.1:80/locations/add' \
    --form 'identifier="tokyo_japon"' \
    --form 'name="Tokyo, Japon"' \
    --form 'latitude="35.6895"' \
    --form 'longitude="139.69171"'
curl --location --request POST 'http://127.0.0.1:80/locations/add' \
    --form 'identifier="los_angeles_ca"' \
    --form 'name="Los Angeles, CA"' \
    --form 'latitude="34.052235"' \
    --form 'longitude="-118.243683"'
curl --location --request POST 'http://127.0.0.1:80/locations/add' \
    --form 'identifier="san_francisco_ca"' \
    --form 'name="San Francisco, CA"' \
    --form 'latitude="37.733795"' \
    --form 'longitude="-122.446747"'

5.- Verify that the application is running as expected

Now that everything is set up, go to the application, which in a local machine will be at the standard localhost, and 3 locations should be visible.

Useful commands

Start development server, forcing a rebuild:

sudo docker-compose up --build

Start production server using Docker Compose, forcing a rebuild.

sudo docker-compose -y docker-compose.yml -f docker-compose.prod.yml up --build

Remove the application:

sudo docker-compose down

About


Languages

Language:TypeScript 40.5%Language:Python 35.0%Language:SCSS 10.3%Language:HTML 7.9%Language:JavaScript 5.5%Language:Dockerfile 0.9%