-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
459 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# .coveragerc | ||
[run] | ||
source=service | ||
|
||
[report] | ||
show_missing = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
# project-template | ||
|
||
This is a skeleton you can use to start your projects | ||
|
||
## Overview | ||
|
||
This project template contains starter code for your class project. The `/service` folder contains your `models.py` file for your model and a `service.py` file for your service. The `/tests` folder has test case starter code for testing the model and the service separately. All you need to do is add your functionality. You can use the [lab-flask-rest](https://github.com/nyu-devops/lab-flask-rest) | ||
for code examples. | ||
|
||
## Setup | ||
|
||
You should clone this repository and and the copy and paste the starter code into your project repo folder on your local computer. | ||
|
||
Assuming your repo is empty, you can use the following commands: | ||
|
||
```shell | ||
git clone https://github.com/nyu-devops/project-template.git | ||
cp -R project-template/ <your_repo_folder>/ | ||
``` | ||
|
||
This will recursively copy the contents of the template to your repo folder. | ||
|
||
## Contents | ||
|
||
The project contains the following: | ||
|
||
```text | ||
dot-env-example - copy to .env to use environment variables | ||
config.py - configuration parameters | ||
service/ - service python package | ||
├── __init__.py - package initializer | ||
├── models.py - module with business models | ||
└── service.py - module with service routes | ||
tests/ - test cases package | ||
├── __init__.py - package initializer | ||
├── test_models.py - test suite for busines models | ||
└── test_service.py - test suite for service routes | ||
``` | ||
|
||
This repository is part of the NYU class **CSCI-GA.2810-001: DevOps and Agile Methodologies** taught by John Rofrano, Adjunct Instructor, NYU Curant Institute, Graduate Division, Computer Science. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
# All Vagrant configuration is done below. The "2" in Vagrant.configure | ||
# configures the configuration version (we support older styles for | ||
# backwards compatibility). Please don't change it unless you know what | ||
# you're doing. | ||
Vagrant.configure(2) do |config| | ||
# Every Vagrant development environment requires a box. You can search for | ||
# boxes at https://atlas.hashicorp.com/search. | ||
config.vm.box = "ubuntu/bionic64" | ||
config.vm.hostname = "project" | ||
|
||
# accessing "localhost:8080" will access port 80 on the guest machine. | ||
# config.vm.network "forwarded_port", guest: 80, host: 8080 | ||
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1" | ||
|
||
# Create a private network, which allows host-only access to the machine | ||
# using a specific IP. | ||
config.vm.network "private_network", ip: "192.168.33.10" | ||
|
||
# Mac users can comment this next line out but | ||
# Windows users need to change the permission of files and directories | ||
# so that nosetests runs without extra arguments. | ||
config.vm.synced_folder ".", "/vagrant", mount_options: ["dmode=775,fmode=664"] | ||
|
||
# Provider-specific configuration so you can fine-tune various | ||
# backing providers for Vagrant. These expose provider-specific options. | ||
# Example for VirtualBox: | ||
# | ||
config.vm.provider "virtualbox" do |vb| | ||
# Customize the amount of memory on the VM: | ||
vb.memory = "1024" | ||
vb.cpus = 2 | ||
# Fixes some DNS issues on some networks | ||
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] | ||
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] | ||
end | ||
|
||
# Copy your .gitconfig file so that your git credentials are correct | ||
if File.exists?(File.expand_path("~/.gitconfig")) | ||
config.vm.provision "file", source: "~/.gitconfig", destination: "~/.gitconfig" | ||
end | ||
|
||
# Copy the ssh keys into the vm for git access | ||
if File.exists?(File.expand_path("~/.ssh/id_rsa")) | ||
config.vm.provision "file", source: "~/.ssh/id_rsa", destination: "~/.ssh/id_rsa" | ||
end | ||
|
||
if File.exists?(File.expand_path("~/.ssh/id_rsa.pub")) | ||
config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub" | ||
end | ||
|
||
# Copy your .vimrc file so that your vi looks like you expect | ||
if File.exists?(File.expand_path("~/.vimrc")) | ||
config.vm.provision "file", source: "~/.vimrc", destination: "~/.vimrc" | ||
end | ||
|
||
# Enable provisioning with a shell script. Additional provisioners such as | ||
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the | ||
# documentation for more information about their specific syntax and use. | ||
config.vm.provision "shell", inline: <<-SHELL | ||
apt-get update | ||
apt-get install -y git python3 python3-pip python3-venv | ||
apt-get -y autoremove | ||
# Install app dependencies | ||
cd /vagrant | ||
pip3 install -r requirements.txt | ||
SHELL | ||
|
||
###################################################################### | ||
# Add PostgreSQL docker container | ||
###################################################################### | ||
# docker run -d --name postgres -p 5432:5432 -v psql_data:/var/lib/postgresql/data postgres | ||
config.vm.provision :docker do |d| | ||
d.pull_images "postgres:alpine" | ||
d.run "postgres:alpine", | ||
args: "-d --name postgres -p 5432:5432 -v psql_data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=postgres" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
""" | ||
Global Configuration for Application | ||
""" | ||
import os | ||
|
||
# Get configuration from environment | ||
DATABASE_URI = os.getenv("DATABASE_URI", "sqlite:///../development.db") | ||
|
||
# Configure SQLAlchemy | ||
SQLALCHEMY_DATABASE_URI = DATABASE_URI | ||
SQLALCHEMY_TRACK_MODIFICATIONS = False | ||
|
||
# Secret for session management | ||
SECRET_KEY = os.getenv("SECRET_KEY", "s3cr3t-key-shhhh") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copy this file to .env to expose these environment variables | ||
FLASK_APP=service:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Runtime dependencies | ||
Flask==1.1.1 | ||
Flask-API==1.1 | ||
Flask-SQLAlchemy==2.4.1 | ||
python-dotenv==0.10.3 | ||
|
||
# Testing | ||
nose==1.3.7 | ||
rednose==1.3.0 | ||
pinocchio==0.4.2 | ||
coverage==4.5.4 | ||
pylint>=2.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
Package: service | ||
Package for the application models and service routes | ||
This module creates and configures the Flask app and sets up the logging | ||
and SQL database | ||
""" | ||
import os | ||
import sys | ||
import logging | ||
from flask import Flask | ||
|
||
# Create Flask application | ||
app = Flask(__name__) | ||
app.config.from_object('config') | ||
|
||
# Import the rutes After the Flask app is created | ||
from service import service, models | ||
|
||
# Set up logging for production | ||
if __name__ != '__main__': | ||
gunicorn_logger = logging.getLogger('gunicorn.error') | ||
app.logger.handlers = gunicorn_logger.handlers | ||
app.logger.setLevel(gunicorn_logger.level) | ||
app.logger.propagate = False | ||
# Make all log formats consistent | ||
formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] [%(module)s] %(message)s", "%Y-%m-%d %H:%M:%S %z") | ||
for handler in app.logger.handlers: | ||
handler.setFormatter(formatter) | ||
app.logger.info('Logging handler established') | ||
|
||
app.logger.info(70 * "*") | ||
app.logger.info(" M Y S E R V I C E R U N N I N G ".center(70, "*")) | ||
app.logger.info(70 * "*") | ||
|
||
try: | ||
service.init_db() # make our sqlalchemy tables | ||
except Exception as error: | ||
app.logger.critical("%s: Cannot continue", error) | ||
# gunicorn requires exit code 4 to stop spawning workers when they die | ||
sys.exit(4) | ||
|
||
app.logger.info("Service inititalized!") |
Oops, something went wrong.