Git Product home page Git Product logo

olayinkaadeleye / worklog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibm/worklog

0.0 0.0 0.0 2.64 MB

This code pattern creates a Python Flask application that incorporates MongoDB as a microservice in Docker containers. These containers are deployed in Kubernetes.

Home Page: https://developer.ibm.com/patterns/build-a-python-web-application-to-log-days-worked/

License: Apache License 2.0

Shell 0.80% JavaScript 57.40% Python 39.59% CSS 0.07% HTML 1.73% Dockerfile 0.40%

worklog's Introduction

Build Status

Work Log

In this Code Pattern, we will create a Work Log web application using Flask, MongoDB, and Kubernetes. The Work Log application is used to keep track of and log different types of days that are associated with work. The different types of days include:

  • Working in the office
  • Working remotely
  • Vacation days
  • Holidays
  • Sick days

When the reader has completed this Code Pattern, they will understand how to:

  • Create a Python Flask application
  • Incorporate MongoDB into a Python application
  • Deploy and run microservices on Kubernetes

Architecture

  1. User interacts with the App UI to initially create an account, login to account, or reset password for their account. Once User is logged in, they can view, add, and edit their work log data.
  2. The functionality of the App UI that the User interacts with is handled by React. React is where the API calls are initialized.
  3. The API calls are processed in the Flask API microservice on Kubernetes and are handled accordingly.
  4. The data is stored, gathered, and/or modified in MongoDB depending on the API calls.
  5. The response from the API calls are handled accordingly by the App UI.

Included components

  • IBM Cloud Container Service: IBM Bluemix Container Service manages highly available apps inside Docker containers and Kubernetes clusters on the IBM Cloud.
  • Swagger: A framework of API developer tools for the OpenAPI Specification that enables development across the entire API lifecycle.

Featured technologies

  • Container Orchestration: Automating the deployment, scaling and management of containerized applications.
  • Microservices: Collection of fine-grained, loosely coupled services using a lightweight protocol to provide building blocks in modern application composition in the cloud.
  • Python: Python is a programming language that lets you work more quickly and integrate your systems more effectively.
  • Flask: A microframework for Python for building APIs.
  • React: JavaScript library for building User Interfaces.
  • MongoDB: A document NoSQL database.

Prerequisites

For running these services locally without Docker containers, the following will be needed:

Steps

Follow these steps to setup and run this code pattern locally and on the Cloud. The steps are described in detail below.

  1. Clone the repo
  2. Run the application
  3. Deploy to IBM Cloud

1. Clone the repo

Clone the worklog repo locally. In a terminal, run:

$ git clone https://github.com/IBM/worklog
$ cd worklog

2. Run the application

  1. Start the application by running docker-compose up --build in this repo's root directory.
  2. Once the containers are created and the application is running, use the Open API Doc (Swagger) at http://localhost:5000/api and API.md for instructions on how to use the APIs.
  3. Use http://localhost:3000 to access the React UI.

3. Deploy to IBM Cloud

  1. To allow changes to the Flask application or the React UI, create a repo on Docker Cloud where the new modified containers will be pushed to.

NOTE: If a new repo is used for the Docker containers, the container image will need to be modified to the name of the new repo used in deploy-webapp.yml and/or deploy-webappui.yml.

$ export DOCKERHUB_USERNAME=<your-dockerhub-username>

$ docker build -t $DOCKERHUB_USERNAME/worklog:latest .
$ docker build -t $DOCKERHUB_USERNAME/worklogui:latest web/worklog

$ docker login

$ docker push $DOCKERHUB_USERNAME/worklog:latest
$ docker push $DOCKERHUB_USERNAME/worklogui:latest
  1. Provision the IBM Cloud Kubernetes Service and follow the set of instructions for creating a Container and Cluster based on your cluster type, Standard vs Lite.

Lite Cluster Instructions

  1. Run bx cs workers mycluster and locate the Public IP. This IP is used to access the worklog API and UI (Flask Application). Update the env values in both deploy-webapp.yml and deploy-webappui.yml to the Public IP.

  2. To deploy the services to the IBM Cloud Kubernetes Service, run:

$ kubectl apply -f deploy-mongodb.yml
$ kubectl apply -f deploy-webapp.yml
$ kubectl apply -f deploy-webappui.yml

## Confirm the services are running - this may take a minute
$ kubectl get pods
  1. Use https://PUBLIC_IP:32001 to access the React UI and the Open API Doc (Swagger) at https://PUBLIC_IP:32000/api for instructions on how to make API calls.

Standard Cluster Instructions

  1. Run bx cs cluster-get <CLUSTER_NAME> and locate the Ingress Subdomain and Ingress Secret. This is the domain of the URL that is to be used to access the UI and Flask Application on the Cloud. Update the env values in both deploy-webapp.yml and deploy-webappui.yml to the Ingress Subdomain. In addition, update the host and secretName in ingress.yml to Ingress Subdomain and Ingress Secret.

  2. To deploy the services to the IBM Cloud Kubernetes Service, run:

$ kubectl apply -f deploy-mongodb.yml
$ kubectl apply -f deploy-webapp.yml
$ kubectl apply -f deploy-webappui.yml

## Confirm the services are running - this may take a minute
$ kubectl get pods

## Update protocol being used to https
$ kubectl apply -f ingress.yml
  1. Use https://<INGRESS_SUBDOMAIN> to access the React UI and the Open API Doc (Swagger) at https://<INGRESS_SUBDOMAIN>/api for instructions on how to make API calls.

Links

Learn more

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

worklog's People

Contributors

max-shapiro32 avatar maxshapiro32 avatar loafyloaf avatar anthonyamanse avatar imgbotapp avatar ljbennett62 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.