Skip to content

Commit

Permalink
Merge branch 'deploy2' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1nty authored Mar 12, 2019
2 parents 421c35b + 745e398 commit 0c2fb6b
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 30 deletions.
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@ script:
- py.test --cov-report=xml --cov=instadam tests/

after_success:
- codecov
- codecov

before_deploy:
- openssl aes-256-cbc -K $encrypted_7fdaadf61be2_key -iv $encrypted_7fdaadf61be2_iv -in deploy_rsa.enc -out /tmp/deploy_rsa -d
- eval "$(ssh-agent -s)"
- chmod 600 /tmp/deploy_rsa
- ssh-add /tmp/deploy_rsa
deploy:
provider: script
skip_cleanup: true
script: bash scripts/deploy.sh
on:
branch: deploy2
17 changes: 6 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
FROM python:3.6-alpine

RUN adduser -D instadam
RUN mkdir -p /home/flaskapp/src
WORKDIR /home/flaskapp

WORKDIR /home/instadam

COPY requirements requirements
COPY requirements/prod.txt requirements.txt
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev

RUN pip install --no-cache-dir -r requirements/prod.txt
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install gunicorn

RUN apk --purge del .build-deps

COPY instadam instadam
COPY manage.py ./

RUN chown -R instadam:instadam ./
USER instadam
COPY instadam /home/flaskapp/instadam
COPY manage.py /home/flaskapp

EXPOSE 5000
14 changes: 14 additions & 0 deletions conf.d/instadam.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server {
listen 80;
server_name localhost;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;

proxy_pass http://app:8080;
}
}
Binary file added deploy_rsa.enc
Binary file not shown.
44 changes: 31 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,42 @@ services:
restart: always
image: postgres:10
environment:
- POSTGRES_USER=${_DB_USERNAME}
- POSTGRES_PASSWORD=${_DB_PASSWORD}
- POSTGRES_DB=${_DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
volumes:
- ./postgres-data/postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
- "dbdata:/var/lib/postgresql/data"
networks:
- db_nw
app:
restart: always
build: .
environment:
- _DB_USERNAME=${_DB_USERNAME}
- _DB_PASSWORD=${_DB_PASSWORD}
- _DB_NAME=${_DB_NAME}
ports:
- 5000:5000
- _DB_USERNAME=${DB_USERNAME}
- _DB_PASSWORD=${DB_PASSWORD}
- _DB_NAME=${DB_NAME}
volumes:
- .:/app
- ./instadam:/home/flaskapp/src
networks:
- db_nw
- web_nw
depends_on:
- postgres
entrypoint: ["python","manage.py","start", "--mode=production"]
entrypoint: ["python","manage.py","deploy"]
nginx:
image: "nginx:1.13.5"
ports:
- "8080:80"
volumes:
- ./conf.d:/etc/nginx/conf.d
networks:
- web_nw
depends_on:
- app
networks:
db_nw:
driver: bridge
web_nw:
driver: bridge
volumes:
dbdata:
2 changes: 1 addition & 1 deletion instadam/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Production(Config):
"""
SECRET_KEY = FLASK_SECRETE_KEY
_SQLALCHEMY_DATABASE_DATABASE = ''
_SQLALCHEMY_DATABASE_HOSTNAME = 'localhost'
_SQLALCHEMY_DATABASE_HOSTNAME = 'postgres'
_SQLALCHEMY_DATABASE_PASSWORD = DATABASE_PASSWORD
_SQLALCHEMY_DATABASE_USERNAME = DATABASE_USERNAME
SQLALCHEMY_DATABASE_URI = 'postgres://{u}:{p}@{h}/{d}'.format(
Expand Down
5 changes: 1 addition & 4 deletions instadam/models/project.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import datetime as dt

from sqlalchemy.orm import relationship

# @formatter:off
from instadam.models.annotation import Annotation
# @formatter:on

from instadam.models.label import Label
from ..app import db


Expand Down
7 changes: 7 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
def cli():
pass

@cli.command()
def deploy():
app = create_app('production')
with app.app_context():
db.create_all()
app.run(host='0.0.0.0', port=8080)


@cli.command()
@click.option('--mode', default='development', help='production/development')
Expand Down
10 changes: 10 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
rsync -e "ssh -o StrictHostKeyChecking=no" -r --delete-after --quiet $TRAVIS_BUILD_DIR $TRAVIS_SSH_USER@$TRAVIS_SSH_HOST:/tmp/$TRAVIS_BUILD_ID;
ssh -o StrictHostKeyChecking=no $TRAVIS_SSH_USER@$TRAVIS_SSH_HOST -t "sudo source ~/.bashrc;\
cd ~/InstaDam-backend;\
sudo docker-compose down;\
cd /tmp/${TRAVIS_BUILD_ID};\
sudo rm -rf ~/InstaDam-backend;\
sudo mv /tmp/${TRAVIS_BUILD_ID}/InstaDam-backend ~/;\
cd ~/InstaDam-backend;\
sudo docker-compose --verbose up --build&"

0 comments on commit 0c2fb6b

Please sign in to comment.