Giter VIP home page Giter VIP logo

exercise's Introduction

HOW TO RUN

With admin privilege run de following command to docker compose the django enviroment.

$ git clone https://github.com/fergo2910/exercise.git
$ cd exercise
$ docker-compose up [-d]

And then enter to the landpage localhost/exercise_redis/home If you want to connect into the database, you can run the following command to the redis container

docker exec -it <container> redis-cli [-h <hostname>]

CONFIGURATION

For redis persistence storage change the volumne directory to your folder to store the data at the docker-compose.yml file.

volumes:
- //c/Users/fjgonzalez/Music/data:/data

For Node.js app to recognize redis, Node.js calls redis with the hostname in the code_node_api/node_modules/redis/index.js where is define the port and the host (line 70).

RUNNING THE APP

Once the environment is working, the following url should be executed: localhost/exercise_redis/home. In the localhost/exercise_redis/elements you can add products and search products.

CLEANING UP

When you want to try new changes into code, you need stop docker-compose with Ctrl + C and remove the images that were created with the docker-compose. Also you can run the commands.

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker images
docker rmi exercise_web_app_01
docker rmi exercise_web_app_02

So you can start from scratch.

ARCHITECTURE

The architecture of this exercise is the following: ARCHITECTURE

Two networks were created to be used within the solution

  • back-tier Internal network communicating the api of Node.js and Redis
  • front-tier Internal network communicating the web app, consul and Node.js

It was developed in this way to define the difference between Frontend and Backend (as a concept).

Redis

Images: redis:latest

Using its default configuration and storing information persistently outside the container.

Hostname within back-tier network: 'redis'

Visible port for tests: 6379

Node api

Image: node:latest

Generator of api as REST server and storage in Redis, self registration of services to consul when the container starts.

Hostname within back-tier network: 'node_api'

Visible port for test: 7000

Consul

Image: consul:latest

Service check and service provider for web app and api communication. Shows and provides the web app with the available node to consume the 'service_api' service self-registered by node_api

Hostname within front-tier network: 'consul'

Visible port for test: 8500

Web app

Image: exercise_web_app_0#

Web application nodes in django framework. Entry, request and sample of information stored in redis. Consume consul service to obtain node, node give the connection of the REST server and then retrive the result. Image generated with Dockerfile when executing the `docker-compose up` command

Hostname within front-tier network: 'web_app_01' and 'web_app_02'

Visible port for test: 8000 and 9000

URL for exercise: localhost:[port]/exercise_redis/home

Load balancer

Image: dockercloud/haproxy:latest

Load balancer using haproxy, round robin with docker links to web app.

Hostname within front-tier network: 'lb'

Visible port for test: 80

URL for exercise: localhost/exercise_redis/home

DEPLOY WITH CFN

If you want the same enviroment in cloud you could run a CFN service with the following steps.

  1. Go to your aws console and EC2 service.
  2. Generate a Key-pair to connect to an EC2 Instance.
  3. This will save a key.pem file with a rsa key. Save this key into your root project.
  4. change the privileges of the key.pem with the command chmod 400 key.pem so the key wont be modifiable, only readable.
  5. Now, you need to create a user in your aws account.
    1. Go to your console
    2. Go to IAM service
    3. Users, and create a user and save the public and secrete keys of the user.
  6. Set up a profile for aws-cli with the command aws configure --profile exercise
  7. Enter the public key of the created user
  8. Enter the private key of the created user
  9. Choose your region
  10. You can leave the default format in blank
  11. Now with aws configured run, the following command to create the CloudFormation stack in AWS.
aws cloudformation create-stack --stack-name exercise_stack --template-body file://$PWD/aws-stack.yml --profile exercise --region us-west-2
  1. When the stack is CREATE_COMPLETE you need to go to Resources and click in the Physical ID of the EC2_Deploy and copy the public IP of the instance.
  2. You have to configure a volumne for redis in the aws-docker-compose.yml using:
  3. Finally, you can run docker-compose -H tcp://public_ip:2375 up -f aws-docker-compose.yml
  4. When everything is up you can access through your browser to the public ip and it will show you the same page that you build with docker compose localy.

exercise's People

Contributors

fergo2910 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.