Skip to content
This repository has been archived by the owner on May 14, 2023. It is now read-only.

Commit

Permalink
Add Zappa
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed Jun 29, 2020
1 parent 14af6b8 commit a105459
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
15 changes: 13 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ script:
after_success:
- docker-compose push
# TODO: IF and migrate
- docker pull $ZAPPA_IMG || true
- docker build -t $ZAPPA_IMG --cache-from $ZAPPA_IMG -f ./server/zappa.dockerfile ./server/
- |
docker run --rm \
-e AWS_ACCESS_KEY_ID=$ZAPPA_AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$ZAPPA_AWS_SECRET_ACCESS_KEY \
-e AWS_DEFAULT_REGION=$ZAPPA_AWS_DEFAULT_REGION \
$ZAPPA_IMG \
bash -c 'source /venv/bin/activate && zappa update prod'
deploy:
provider: s3
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
access_key_id: $S3_AWS_ACCESS_KEY_ID
secret_access_key: $S3_AWS_SECRET_ACCESS_KEY
bucket: $TOGGLECORP_S3_BUCKET
skip_cleanup: true
local_dir: ./client/build
Expand All @@ -44,3 +54,4 @@ env:
global:
- REACT_STORE_DIR=client/src/vendor/react-store
- TC_BRANCH_NAME=`echo ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} | tr / _`
- ZAPPA_IMG=docker.pkg.github.com/toggle-corp/togglecorp/zappa:latest
15 changes: 8 additions & 7 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
django>=2.2,<2.3
boto3==1.9.5
django-cors-headers==2.4.0
djangorestframework==3.9.4
djangorestframework-camel-case==0.2.0
drf-dynamic-fields==0.3.0
pyjwt==1.6.4
django-jet==1.0.8
psycopg2-binary==2.7.5
boto3==1.9.5
django-storages==1.7.1
django>=2.2,<2.3
djangorestframework-camel-case==0.2.0
djangorestframework==3.9.4
drf-dynamic-fields==0.3.0
ipython==6.5.0
psycopg2-binary==2.8.5
pyjwt==1.6.4
uwsgi
zappa==0.51.0
7 changes: 5 additions & 2 deletions server/togglecorp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
APPS_DIR = os.path.join(BASE_DIR, 'apps')
sys.path.append(APPS_DIR)
sys.path.insert(0, APPS_DIR)


# Quick-start development settings - unsuitable for production
Expand All @@ -18,7 +18,7 @@
SECRET_KEY = '+c=ii9osx=a^h#m$s%@sql2pyj_#xq%3p(0=r&#+3+hjq@tsis'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', True)
DEBUG = os.environ.get('DEBUG', 'True').lower() == 'true'

ALLOWED_HOSTS = ['*']

Expand Down Expand Up @@ -97,6 +97,9 @@
'PASSWORD': os.environ.get('DATABASE_PASSWORD', 'postgres'),
'PORT': os.environ.get('DATABASE_PORT', '5432'),
'HOST': os.environ.get('DATABASE_HOST', 'db'),
'OPTIONS': {
'connect_timeout': 5,
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions server/zappa.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.6-slim

MAINTAINER togglecorp info@togglecorp.com

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN apt-get update -y \
&& apt-get install -y \
vim \
curl \
cron \
unzip \
python3 \
python3-dev \
libpq-dev \
python3-setuptools \
python3-pip

RUN pip install --upgrade pip \
&& pip install virtualenv \
&& virtualenv /venv \
&& . /venv/bin/activate \
&& pip install --no-cache-dir -r requirements.txt \
&& apt-get autoremove

COPY . /code/
15 changes: 15 additions & 0 deletions server/zappa_settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"prod": {
"aws_region": "us-east-1",
"django_settings": "togglecorp.settings",
"project_name": "togglecorp-server",
"runtime": "python3.8",
"s3_bucket": "zappa-togglecorp",
"certificate_arn": "arn:aws:acm:us-east-1:182509255933:certificate/64de3375-63d6-4118-89e0-f1b08fab91b8",
"domain": "api.togglecorp.com",
"vpc_config" : {
"SubnetIds": ["subnet-930078d9", "subnet-5f9b3038"],
"SecurityGroupIds": [ "sg-00085d77439843e85" ]
}
}
}

0 comments on commit a105459

Please sign in to comment.