Commit 09c4c74a authored by Sarah Abrishami's avatar Sarah Abrishami

initial commit

parents
Pipeline #809 failed with stages
# pull official base image
FROM python:3.7.9-slim-buster
# set work directory
ENV INSTALL_PATH /flask_template
RUN mkdir -p $INSTALL_PATH
#this sets the context of where commands will be ran in and is documented
WORKDIR $INSTALL_PATH
# Copy in the application code from your work station at the current directory
# over to the working directory.
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
CMD python manage.py runserver
node {
// holds reference to docker image
def dockerImage
// ip address of the docker private repository
def dockerImageTag = "flask_template"
// Application port
def dockerPort = "6100"
def endpointPort = "6100"
stage('Clone Repo') {
checkout scm
}
stage('Build Docker Image') {
dockerImage = docker.build("${dockerImageTag}")
}
stage('Deploy Docker Image'){
echo "Docker Image Tag Name: ${dockerImageTag}"
sh "docker stop ${dockerImageTag} || true && docker rm ${dockerImageTag} || true"
sh "docker network create sumit_network || true"
sh "docker run --name ${dockerImageTag} -d --net sumit_network --restart always -p ${endpointPort}:${dockerPort} ${dockerImageTag}"
}
stage('Notify GitLab') {
updateGitlabCommitStatus name: 'build', state: 'pending'
updateGitlabCommitStatus name: 'build', state: 'success'
}
}
# Flask Template
from flask import Flask
from app.config import configs
import os
def create_app():
app = Flask(__name__)
config_name = os.getenv('FLASK_ENV') or 'default'
app.config.from_object(configs[config_name])
from app.main import main as main_blueprint
app.register_blueprint(main_blueprint)
# attach routes and custom error pages here
return app
import os
basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
DEBUG = False
TESTING = False
class DevelopmentConfig(Config):
"""
Development configurations
"""
DEBUG = True
ASSETS_DEBUG = True
class ProductionConfig(Config):
"""
Production configurations
"""
DEBUG = False
class TestingConfig(Config):
TESTING = True
configs = {
'development': DevelopmentConfig(),
'testing': TestingConfig(),
'production': ProductionConfig(),
'default': DevelopmentConfig()
}
from flask import Blueprint
from flask_cors import CORS
main = Blueprint('main', __name__)
CORS(main)
from app.main import errors
from app.main.views import isup
from . import main
@main.app_errorhandler(404)
def page_not_found(e):
return 'Page not found', 404
@main.app_errorhandler(500)
def internal_server_error(e):
return 'Internal Server Error', 500
import gzip
from flask import make_response, json, current_app
import requests
import pandas as pd
import numpy as np
def response_message(data=None, status=200):
if status in range(200, 400):
content = gzip.compress(json.dumps(data, ensure_ascii=False, indent=3, default=convert,
sort_keys=False).encode('utf8'), 5)
else:
content = gzip.compress(
json.dumps({'message': data, 'status': 'error'}, ensure_ascii=False, indent=3).encode('utf-8'), 5)
response = make_response(content, status)
response.headers['Content-length'] = len(content)
response.headers['Content-Encoding'] = 'gzip'
response.headers['Content-Type'] = 'application/json; charset=utf-8'
return response
def convert(o):
if isinstance(o, np.int64):
return int(o)
if isinstance(o, np.bool_):
if o:
return True
else:
return False
if pd.isna(o):
return None
from app.main import main
from app.main.utils.common import response_message
@main.route('/', methods=['GET', 'POST'])
def isup():
return response_message('API is active!')
import os
from app import create_app
# from flask.ext.script import Manager
from flask_script import Manager, Shell, Server
app = create_app()
manager = Manager(app)
def make_shell_context():
return dict(app=app)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('runserver', Server(host='0.0.0.0', port=6100), threaded=True)
@manager.command
def test():
"""Run the unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
# python manage.py test
if __name__ == '__main__':
manager.run()
import unittest
from flask import current_app
from app import create_app
class BasicsTestCase(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
# db.create_all()
def tearDown(self):
self.app_context.pop()
# db.session.remove()
# db.drop_all()
def test_app_exists(self):
self.assertFalse(current_app is None)
def test_app_is_testing(self):
self.assertTrue(current_app.config['TESTING'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment