Skip to content

Latest commit

 

History

History
196 lines (151 loc) · 7.23 KB

localhost.md

File metadata and controls

196 lines (151 loc) · 7.23 KB

Cinema - Localhost Deployment

Overview

The Cinema project can be deployed in a single machine (localhost) using Docker Compose V2.

Access to compose-v1 tag if Compose V1 specification is needed.

Index

Requirements

  • Docker Engine 20.10.22
  • Docker Compose v2.15.1

Starting services

Use the command compose up to start all services in your local environment.

docker compose up --detach
Output
[+] Running 7/7
⠿ Container microservices-docker-go-mongodb-website-1    Started
⠿ Container microservices-docker-go-mongodb-db-1         Started
⠿ Container microservices-docker-go-mongodb-showtimes-1  Started
⠿ Container microservices-docker-go-mongodb-bookings-1   Started
⠿ Container microservices-docker-go-mongodb-users-1      Started
⠿ Container microservices-docker-go-mongodb-proxy-1      Started
⠿ Container microservices-docker-go-mongodb-movies-1     Started

Check the containers running.

docker compose ps
Output
NAME    IMAGE                                      COMMAND   SERVICE      PORTS
.....   ghcr.io/mmorejon/cinema-bookings:v2.2.1    .....     bookings
.....   mongo:4.2.23                               .....     db           27017/tcp
.....   ghcr.io/mmorejon/cinema-movies:v2.2.1      .....     movies
.....   traefik:v2.4.2                             .....     proxy        0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp
.....   ghcr.io/mmorejon/cinema-showtimes:v2.2.1   .....     showtimes
.....   ghcr.io/mmorejon/cinema-users:v2.2.1       .....     users
.....   ghcr.io/mmorejon/cinema-website:v2.2.1     .....     website

Once the services have started, you can access the web through the following link: http://localhost.

Website Home

Restore database information

You will start using an empty database for all microservices, but if you want you can restore a preconfigured data execute this command:

docker compose exec db mongorestore \
  --uri mongodb://db:27017 \
  --gzip /backup/cinema
Output
.....  preparing collections to restore from
.....  reading metadata for movies.movies from /backup/cinema/movies/movies.metadata.json.gz
.....  reading metadata for showtimes.showtimes from /backup/cinema/showtimes/showtimes.metadata.json.gz
.....  reading metadata for users.users from /backup/cinema/users/users.metadata.json.gz
.....  reading metadata for bookings.bookings from /backup/cinema/bookings/bookings.metadata.json.gz
.....  restoring bookings.bookings from /backup/cinema/bookings/bookings.bson.gz
.....  no indexes to restore
.....  finished restoring bookings.bookings (2 documents, 0 failures)
.....  restoring movies.movies from /backup/cinema/movies/movies.bson.gz
.....  no indexes to restore
.....  finished restoring movies.movies (6 documents, 0 failures)
.....  restoring showtimes.showtimes from /backup/cinema/showtimes/showtimes.bson.gz
.....  no indexes to restore
.....  finished restoring showtimes.showtimes (3 documents, 0 failures)
.....  restoring users.users from /backup/cinema/users/users.bson.gz
.....  no indexes to restore
.....  finished restoring users.users (5 documents, 0 failures)
.....  16 document(s) restored successfully. 0 document(s) failed to restore.

This command will go inside the mongodb container (db service described in compose.yaml file). Once the command finished the data inserted will be ready to be consulted. Try listing users again http://localhost/users/list.

Users List

Enabling microservices APIs

The microservices are not exposed to ensure greater security, but if you need to enable them for testing you can do so through the tags defined by Trafik for the Docker provider.

    labels:
      # Enable public access
      - "traefik.http.routers.users.rule=PathPrefix(`/api/users/`)"
      - "traefik.http.services.users.loadbalancer.server.port=4000"

Once exposed all services the following links will be availables:

Service Description
Traefik Proxy Dashboard Allows you to identify Traefik componentes like routers, provider, services, middlewares among others
List users api List all users
List movies api List all movies
List showtimes api List all showtimes
List bookings api List all bookings

The following command is an example of how to list the users:

curl -X GET http://localhost/api/users/
Output
[{"ID":"600209d347932ef15c50af15","Name":"Wanda","LastName":"Austin"},{"ID":"600209d347932ef15c50af16","Name":"Charles","LastName":"Babbage"},{"ID":"600209d347932ef15c50af17","Name":"Stefan","LastName":"Banach"},{"ID":"600209d347932ef15c50af18","Name":"Laura","LastName":"Bassi"},{"ID":"600209d347932ef15c50af19","Name":"Niels","LastName":"Bohr"}]

Stopping services

docker compose stop
Output
[+] Running 7/7
⠿ Container microservices-docker-go-mongodb-website-1    Stopped
⠿ Container microservices-docker-go-mongodb-db-1         Stopped
⠿ Container microservices-docker-go-mongodb-bookings-1   Stopped
⠿ Container microservices-docker-go-mongodb-showtimes-1  Stopped
⠿ Container microservices-docker-go-mongodb-movies-1     Stopped
⠿ Container microservices-docker-go-mongodb-users-1      Stopped
⠿ Container microservices-docker-go-mongodb-proxy-1      Stopped

Traefik Proxy dashboard

This project use Traefik Proxy v2.4.2, the dashboard should look like this image:

overview

Next: Endpoints

Build from source code

If you want to include new functionalities, fix bugs or do some tests use the source code to build the docker image from the docker compose file. To make it uncomment the build line in de microservice and comment the image line.

  users:
    build: ./users                                   # uncomment this line
    # image: ghcr.io/mmorejon/cinema-users:v2.1.0    # comment this line
    command:
      - "-mongoURI"
      - "mongodb://db:27017/"
    #   - "-enableCredentials"
    #   - "true"
    # environment:
    #   MONGODB_USERNAME: "demo"
    #   MONGODB_PASSWORD: "e3LBVTPdlzxYbxt9"
    labels: {}
      # Enable public access
      # - "traefik.http.routers.users.rule=PathPrefix(`/api/users/`)"
      # - "traefik.http.services.users.loadbalancer.server.port=4000"