-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from quaternionmedia/devops
Devops
- Loading branch information
Showing
63 changed files
with
1,130 additions
and
358 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 |
---|---|---|
@@ -1,8 +1,38 @@ | ||
# project based | ||
node_modules | ||
dist | ||
*/dist/* | ||
/dist/* | ||
.cache | ||
package-lock.json | ||
yarn.lock | ||
media/ | ||
cypress/screenshots/ | ||
cypress/videos/ | ||
/website/cypress/screenshots/ | ||
/website/cypress/videos/ | ||
__*__ | ||
/videos | ||
/api/main.json | ||
|
||
# compiled output | ||
/tmp | ||
/out-tsc | ||
|
||
# dependencies | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
|
||
# misc | ||
npm-debug.log | ||
yarn-error.log | ||
testem.log | ||
/typings | ||
/_trash | ||
|
||
# System Files | ||
.DS_Store | ||
Thumbs.db |
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,27 @@ | ||
pipeline { | ||
agent none | ||
stages { | ||
stage('Build') { | ||
agent any | ||
steps { | ||
echo 'Building..' | ||
make build | ||
//step([$class: 'DockerComposeBuilder', dockerComposeFile: 'docker-compose.yml', option: [$class: 'StartService', scale: 1, service: 'dev'], useCustomDockerComposeFile: true]) | ||
//sh 'docker-compose -f docker-compose.yml -f dev.yml build dev' | ||
} | ||
} | ||
stage('Test') { | ||
agent any | ||
steps { | ||
echo 'Testing..' | ||
} | ||
} | ||
stage('Deploy') { | ||
agent any | ||
steps { | ||
echo 'Deploying....' | ||
make run | ||
} | ||
} | ||
} | ||
} |
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,31 +1,48 @@ | ||
#!/bin/sh | ||
VERSION=v0.1.0 | ||
|
||
# Returns a greeting quote to the user. | ||
echo | ||
shuf -n 1 quotes.csv | ||
echo | ||
if [ $1 = "dev" ] || [ -z $1 ]; then | ||
if [ !-z ]; then shift; fi | ||
|
||
echo "Alfred! running dev $1" | ||
docker-compose -f docker-compose.yml -f dev.yml up $1 | ||
downloadMedia() { | ||
echo "downloading demo media" | ||
mkdir -p videos && cd videos | ||
wget -N https://storage.googleapis.com/tower-bucket/moon.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/train.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/ATripToTheMoon-300k.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/TheGreatTrainRobbery-300k.mp4 | ||
cd .. | ||
} | ||
|
||
if [ $1 = "version" -o $1 = "v" -o $1 = "-v" ]; then | ||
echo $VERSION | ||
|
||
# Starts in development (optional "--build") | ||
elif [ $1 = "dev" ] || [ -z $1 ]; then | ||
if [ !-z ]; then shift; fi | ||
echo "Alfred! running dev $1" | ||
docker-compose -f docker-compose.yml -f dev.yml up $1 | ||
|
||
# Starts in production. | ||
elif [ $1 = "prod" -o $1 = "production" ]; then | ||
shift | ||
echo "Alfred! running production $1" | ||
docker-compose down && \ | ||
docker-compose -f docker-compose.yml -f production.yml up --build -d $1 | ||
shift | ||
echo "Alfred! running production $1" | ||
docker-compose down && \ | ||
docker-compose -f docker-compose.yml -f production.yml up --build -d $1 | ||
|
||
# Installs the dependencies. | ||
elif [ $1 = "i" -o $1 = "install" ]; then | ||
shift | ||
echo "installing dependencies" | ||
docker-compose run dev yarn install | ||
make install | ||
|
||
elif [ $1 = "demo" -o $1 = "download" -o $1 = "samples" ]; then | ||
shift | ||
echo "downloading demo media" | ||
mkdir -p videos && cd videos | ||
wget -N https://storage.googleapis.com/tower-bucket/moon.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/train.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/ATripToTheMoon-300k.mp4 | ||
wget -N https://storage.googleapis.com/tower-bucket/TheGreatTrainRobbery-300k.mp4 | ||
cd .. | ||
downloadMedia | ||
|
||
elif [ $1 = "restart" -o $1 = "r" ]; then | ||
shift | ||
docker-compose -f docker-compose.yml -f production.yml restart | ||
fi |
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,9 +1,12 @@ | ||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7-alpine3.8 | ||
|
||
RUN apk add --no-cache ffmpeg | ||
RUN apk add g++ | ||
|
||
RUN pip install -U pip | ||
RUN pip install aiofiles ffmpeg-python tinydb | ||
|
||
RUN apk add libffi-dev openssl-dev | ||
COPY requirements.txt / | ||
RUN pip install -Ur /requirements.txt | ||
|
||
ENTRYPOINT ["/start-reload.sh"] |
This file was deleted.
Oops, something went wrong.
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,121 @@ | ||
from datetime import datetime, timedelta | ||
import jwt | ||
from fastapi import Depends, FastAPI, APIRouter, HTTPException, status | ||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm | ||
from jwt import PyJWTError | ||
from passlib.context import CryptContext | ||
from pydantic import BaseModel | ||
from typing import List | ||
from db import db | ||
|
||
# openssl rand -hex 32 | ||
SECRET_KEY = '645e87ee8bd522e5f93bca30be7bf580a64270cf1d50fb77c68f4b58124dd0f7' | ||
|
||
ALGORITHM = "HS256" | ||
ACCESS_TOKEN_EXPIRE_MINUTES = 30 | ||
|
||
|
||
class Token(BaseModel): | ||
access_token: str | ||
token_type: str | ||
|
||
|
||
class TokenData(BaseModel): | ||
username: str = None | ||
|
||
|
||
class User(BaseModel): | ||
username: str | ||
email: str = None | ||
# full_name: str = None | ||
disabled: bool = None | ||
|
||
|
||
class UserInDB(User): | ||
hashed_password: str | ||
|
||
class Edl(BaseModel): | ||
edl: List = None | ||
|
||
|
||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") | ||
|
||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token") | ||
|
||
# app = FastAPI() | ||
auth = APIRouter() | ||
|
||
def verify_password(plain_password, hashed_password): | ||
return pwd_context.verify(plain_password, hashed_password) | ||
|
||
|
||
def get_password_hash(password): | ||
return pwd_context.hash(password) | ||
|
||
|
||
def get_user(username: str): | ||
c = db.users.find_one({'username': username}) | ||
if c: | ||
return UserInDB(**c) | ||
|
||
|
||
def authenticate_user(username: str, password: str): | ||
user = get_user(username) | ||
if not user: | ||
return False | ||
if not verify_password(password, user.hashed_password): | ||
return False | ||
return user | ||
|
||
|
||
def create_access_token(*, data: dict, expires_delta: timedelta = None): | ||
to_encode = data.copy() | ||
if expires_delta: | ||
expire = datetime.utcnow() + expires_delta | ||
else: | ||
expire = datetime.utcnow() + timedelta(minutes=15) | ||
to_encode.update({"exp": expire}) | ||
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM) | ||
return encoded_jwt | ||
|
||
|
||
async def get_current_user(token: str = Depends(oauth2_scheme)): | ||
credentials_exception = HTTPException( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail="Could not validate credentials", | ||
headers={"WWW-Authenticate": "Bearer"}, | ||
) | ||
try: | ||
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM]) | ||
username: str = payload.get("sub") | ||
if username is None: | ||
raise credentials_exception | ||
token_data = TokenData(username=username) | ||
except PyJWTError: | ||
raise credentials_exception | ||
user = get_user(username=token_data.username) | ||
if user is None: | ||
raise credentials_exception | ||
return user | ||
|
||
|
||
async def get_current_active_user(current_user: User = Depends(get_current_user)): | ||
if current_user.disabled: | ||
raise HTTPException(status_code=400, detail="Inactive user") | ||
return current_user | ||
|
||
|
||
@auth.post("/token", response_model=Token) | ||
async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()): | ||
user = authenticate_user(form_data.username, form_data.password) | ||
if not user: | ||
raise HTTPException( | ||
status_code=status.HTTP_401_UNAUTHORIZED, | ||
detail="Incorrect username or password", | ||
headers={"WWW-Authenticate": "Bearer"}, | ||
) | ||
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES) | ||
access_token = create_access_token( | ||
data={"sub": user.username}, expires_delta=access_token_expires | ||
) | ||
return {"access_token": access_token, "token_type": "bearer"} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.