Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
👷 add deploy circle ci job
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenautjoe committed Nov 3, 2018
1 parent f61a8c4 commit 62947e1
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 5 deletions.
47 changes: 42 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ jobs:
# download test reporter as a static binary
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
# run tests!
# this example uses Django's built-in test-runner
# other common Python testing frameworks include pytest and nose
# https://pytest.org
# https://nose.readthedocs.io
- run:
name: run tests
command: |
Expand All @@ -59,4 +54,46 @@ jobs:
python manage.py test
# upload test report to Code Climate using `after-build`
./cc-test-reporter after-build --exit-code $?
deploy:
working_directory: ~/repo
docker:
- image: circleci/python:3.7.0
steps:
- checkout
- run:
name: Install utils dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install jinja2
- run:
name: Installing deployment dependencies
working_directory: /
command: |
sudo apt-get -y -qq update
sudo apt-get install python-pip python-dev build-essential
sudo pip install awsebcli --upgrade
- run:
name: Make EB Basic Auth Config
command: |
. venv/bin/activate
python utils/make_eb_basic_auth_config.py --htpasswd=$HTTPASSWD
- run:
name: Make EB Config
command: |
. venv/bin/activate
python utils/make_eb_config.py --name=$APPLICATION_NAME --region=$AWS_DEFAULT_REGION
- run:
name: Deploy to EB
command: eb deploy $CIRCLE_BRANCH-$APPLICATION_NAME

workflows:
version: 2
build:
jobs:
- build
- deploy:
filters:
branches:
only:
- master
1 change: 1 addition & 0 deletions .ebextensions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
basic_auth.config
14 changes: 14 additions & 0 deletions .ebextensions/cors.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
files:
"/etc/httpd/conf.d/cors.conf" :
mode: "000644"
owner: root
group: root
content: |
<Location "/">
Header set Access-Control-Allow-Origin: https://www.openbook.social
Header set Access-Control-Allow-Methods: "POST, GET, PUT, DELETE, OPTIONS"
Header add Access-Control-Allow-Headers: "Authorization, Content-Type, Accept"
Header set Access-Control-Allow-Credentials: true

SetOutputFilter DEFLATE
</Location>
3 changes: 3 additions & 0 deletions .ebextensions/django.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: openbook/wsgi.py
11 changes: 11 additions & 0 deletions .ebextensions/health_host.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
files:
"/etc/httpd/conf.d/health_host.conf" :
mode: "000644"
owner: root
group: root
content: |
<Location "/health/">
AuthType None
Require all granted
RequestHeader set HOST "openbook.social"
</Location>
2 changes: 2 additions & 0 deletions .elasticbeanstalk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
37 changes: 37 additions & 0 deletions utils/make_eb_basic_auth_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import argparse
from jinja2 import Environment, FileSystemLoader


def make_eb_basic_auth_config(htpasswd_contents):
# Capture our current directory
UTILS_DIR = os.path.dirname(os.path.abspath(__file__))
# Create the jinja2 environment.
# Notice the use of trim_blocks, which greatly helps control whitespace.
j2_env = Environment(loader=FileSystemLoader(UTILS_DIR))
return j2_env.get_template('templates/eb/basic_auth.config.yml').render(
HTPASSWD=htpasswd_contents
)


def write_eb_config(dest, htpasswd_contents):
contents = make_eb_basic_auth_config(htpasswd_contents)
fh = open(dest, 'w')
fh.write(contents)
fh.close()


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='EB Config Maker')
# Optional argument
parser.add_argument('--dest', type=str,
help='The destination of the generated eb config',
default='./.ebextensions/basic_auth.config')

parser.add_argument('--htpasswd', type=str,
required=True,
help='The htpasswd file contents')

args = parser.parse_args()

write_eb_config(args.dest, htpasswd_contents=args.htpasswd)
42 changes: 42 additions & 0 deletions utils/make_eb_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import argparse
from jinja2 import Environment, FileSystemLoader


def make_eb_config(application_name, default_region):
# Capture our current directory
UTILS_DIR = os.path.dirname(os.path.abspath(__file__))
# Create the jinja2 environment.
# Notice the use of trim_blocks, which greatly helps control whitespace.
j2_env = Environment(loader=FileSystemLoader(UTILS_DIR))
return j2_env.get_template('templates/eb/config.yml').render(
APPLICATION_NAME=application_name,
DEFAULT_REGION=default_region
)


def write_eb_config(dest, application_name, default_region):
contents = make_eb_config(application_name, default_region)
fh = open(dest, 'w')
fh.write(contents)
fh.close()


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='EB Config Maker')
# Optional argument
parser.add_argument('--dest', type=str,
help='The destination of the generated eb config',
default='./.elasticbeanstalk/config.yml')

parser.add_argument('--name', type=str,
required=True,
help='The name of the application')

parser.add_argument('--region', type=str,
required=True,
help='The default application region')

args = parser.parse_args()

write_eb_config(args.dest, application_name=args.name, default_region=args.region)
18 changes: 18 additions & 0 deletions utils/templates/eb/basic_auth.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
files:
"/etc/httpd/conf.d/basic_auth.conf" :
mode: "000644"
owner: root
group: root
content: |
<Location "/">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>
"/etc/apache2/.htpasswd" :
mode: "000644"
owner: root
group: root
content: |
{{ HTPASSWD }}
22 changes: 22 additions & 0 deletions utils/templates/eb/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
branch-defaults:
master:
environment: $CIRCLE_BRANCH-{{ APPLICATION_NAME }}
global:
application_name: {{ APPLICATION_NAME }}
default_region: {{ DEFAULT_REGION }}
default_ec2_keyname: null
default_platform: python-3.6
include_git_submodules: true
instance_profile: null
platform_name: null
platform_version: null
profile: null
repository: null
sc: git
workspace_type: Application
Resources:
AWSEBAutoScalingGroup:
Type: "AWS::AutoScaling::AutoScalingGroup"
Properties:
HealthCheckType: "ELB"
HealthCheckGracePeriod: "600"

0 comments on commit 62947e1

Please sign in to comment.