Code Monkey home page Code Monkey logo

flask-file-upload's Introduction

Flask file upload

The goal for this project was to understand how to have multiple Docker containers or OpenShift pods working together.

About

This project will create the following environment:

  • Container 1: A flask application which accepts file uplaods, adds an entry within a MySQL database and save the file within a mounted volume point.

  • Container 2: A MySQL database to store entries.

  • Container 3: A mounted volume storage on a host system or a OpenShift pod which is a persistent volume for storage. Which is connected to the application container.

Run via Docker

You should first create a new Python virtual environment to install the required packages.

$ virtualenv ~/venv
$ source ~/venv/bin/activate
(venv) $ pip install -r requirements.txt

To run the project using Docker containers, you first will need to build the container images. This is done using docker-compose. Run the following command to build the images:

(venv) $ make build-images

Once the images are built successfully, you can now start them. Run the following command to start new containers:

(venv) $ make start-containers

You can now test the application by uploading a file. There is an example file within the root of this project example.yml which you can use.

$ curl -F '[email protected]' http://0.0.0.0:5000/upload_yml

When the flask application container is booted, a mounted volume is created at the /tmp directory. If you view the latest files in that directory, you will see new files being created. These files are the ones that were uploaded.

You can also login to the container for the database to see the entries being added.

$ docker exec -it <container_name> /bin/bash
$ mysql -u root -p
mysql> use kingbob;
mysql> select * from file_entry;

Run via OpenShift

You will need to stand up a local instance of OpenShift and download the oc client binary to communicate with OpenShift. You can use any of the available ways to stand up OpenShift Origin (oc cluster, minishift).

Once you have your OpenShift instance running, run the following commands to create the pods:

# create mysql pod
oc new-app --template=mysql-persistent \
--param=DATABASE_SERVICE_NAME=db \
MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=kingbob \
-l db=mysql

# create flask-file-upload pod
oc new-app rywillia/flask-file-upload MYSQL_DATABASE=kingbob \
MYSQL_ROOT_PASSWORD=password -l app=flask

# expose route for flask application to be accessed externally
oc expose service flask-file-upload --name=flask-file-upload \
-l app=flask

# create persistent volume and attach to flask pod deployoment config
oc set volume deploymentconfigs/flask-file-upload \
--add --mount-path=/mnt/app --name=app-storage --claim-size=1G

You can now test the application by uploading a file. There is an example file within the root of this project example.yml which you can use.

$ curl -F '[email protected]' http://0.0.0.0:5000/upload_yml

When the flask application container is booted, a mounted volume is created at the /tmp directory. If you view the latest files in that directory, you will see new files being created. These files are the ones that were uploaded.

You can also login to the container for the database to see the entries being added.

$ oc exec -it <pod_name> /bin/bash
$ mysql -u root -h <internal_ip_of_pod> -P <pod_port> -p
mysql> use kingbob;
mysql> select * from file_entry;

You can run the following commands to clean up your OpenShift pods:

# delete all objects associated with database pod
oc delete dc,pod,pvc,services,secret -l db=mysql

# delete all objects associated with flask pod
oc delete imagestream,dc,pod,pvc,services,secret,route -l app=flask

flask-file-upload's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.