Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/parklab/refinery-platform
Browse files Browse the repository at this point in the history
…into scottx611x/django_1.6_upgrade
  • Loading branch information
scottx611x committed Feb 11, 2016
2 parents 1548f6c + b7a4512 commit cc2648e
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 7 deletions.
2 changes: 1 addition & 1 deletion deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ web-stack: web.json .PHONY
aws cloudformation create-stack --stack-name refinery-web-$$(date +%Y%m%dT%H%M) --template-body file://web.json

volume.json: .PHONY
cfn_py_generate volume_cfn.py volume.json
python volume_cfn.py > volume.json

volume-stack: volume.json .PHONY
aws cloudformation create-stack --stack-name refinery-volume-$$(date +%Y%m%dT%H%M) --template-body file://volume.json
Expand Down
6 changes: 5 additions & 1 deletion deployment/aws-config/10default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@

# The name of the pre-existing RDS instance to connect to.
# (must use the PostgreSQL engine)
# RDS_SUPERUSER_NAME: "rds-refinery"
# RDS_NAME: "rds-refinery"

# The name of the RDS superuser account.
# RDS_SUPERUSER_NAME:
# FIXED to "root"

# The password for the RDS superuser account.
# RDS_SUPERUSER_PASSWORD: "mypassword"

# The name of the PostgreSQL role to create.
RDS_ROLE: "refinery"
9 changes: 9 additions & 0 deletions deployment/aws-tags/hms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# AWS tags,
# as per https://github.com/parklab/refinery-platform/issues/839
# Other groups may want to remove this file and use it as a
# suggestion for their own tagging scheme.
department: dbmi
environment: dev
project: scc
product: refinery
subproduct: platform
7 changes: 6 additions & 1 deletion deployment/aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ cd /srv/refinery-platform/deployment

# Discover IP endpoint for our PostgreSQL RDS, and place it in
# environment variables for puppet/facter to use
bin/aws-rds-endpoint db20160111 > /home/ubuntu/rds
: ${RDS_NAME?RDS_NAME must be set}
bin/aws-rds-endpoint "$RDS_NAME" > /home/ubuntu/rds

# FACTER environment variables become facts for puppet;
# see https://puppetlabs.com/blog/facter-part-1-facter-101
export FACTER_RDS_HOST=$(jq -r .Address /home/ubuntu/rds)
export FACTER_RDS_PORT=$(jq -r .Port /home/ubuntu/rds)
export FACTER_RDS_ROLE="$RDS_ROLE"

# Create RDS user and database here, instead of using puppet
# (because drj couldn't work out how to do it in puppet)
Expand Down
3 changes: 2 additions & 1 deletion deployment/bin/ensure-postgresql-role
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

USER=ubuntu
# Name and password of PostgreSQL role to create.
USER=${RDS_ROLE:-refinery}
PASSWORD=${PASSWORD-password}

HOST=$(jq -r .Address /home/ubuntu/rds)
Expand Down
5 changes: 4 additions & 1 deletion deployment/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
# https://pypi.python.org/pypi/PyYAML/3.11
import yaml

import tags

# Simulate the environment that "cfn_generate" runs scripts in.
# http://cfn-pyplates.readthedocs.org/en/latest/advanced.html#generating-templates-in-python
from cfn_pyplates.core import *
Expand Down Expand Up @@ -70,6 +72,7 @@ def main():
"#!/bin/sh\n",
"RDS_NAME=", config['RDS_NAME'], "\n",
"RDS_SUPERUSER_PASSWORD=", config['RDS_SUPERUSER_PASSWORD'], "\n",
"RDS_ROLE=", config['RDS_ROLE'], "\n",
"GIT_BRANCH=", commit, "\n",
"\n",
open('bootstrap.sh').read(),
Expand All @@ -83,7 +86,7 @@ def main():
'UserData': base64(user_data_script),
'KeyName': 'id_rsa',
'IamInstanceProfile': 'refinery-web',
'Tags': [{'Key': 'refinery', 'Value': 'refinery'}],
'Tags': tags.load(),
})
)

Expand Down
31 changes: 31 additions & 0 deletions deployment/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python

"""
Tags local module.
"""

import glob
import os # for os.popen

import yaml

# Get the local user's email address
email = os.popen("git config --get user.email").read().rstrip()


def load():
"""
Tags come from the YAML files in the aws-tags directory,
additionally, the tag `owner` if it is not set by those YAML
files, will be set to the email address of the local git
user.
"""

tags = {}
for filename in sorted(glob.glob("aws-tags/*")):
with open(filename) as f:
tags.update(yaml.load(f))
if 'owner' not in tags:
tags['owner'] = email

return [{'Key': k, 'Value': v} for k, v in tags.items()]
14 changes: 13 additions & 1 deletion deployment/volume_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@
# AWS Cloudformation
# https://aws.amazon.com/cloudformation/

import glob
import os # for os.popen

import yaml

import tags

# Simulate the environment that "cfn_generate" runs scripts in.
# http://cfn-pyplates.readthedocs.org/en/latest/advanced.html#generating-templates-in-python
from cfn_pyplates.core import *
from cfn_pyplates.functions import *

cft = CloudFormationTemplate(description="refinery EBS volume.")

# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-ebs-volume.html
Expand All @@ -26,10 +36,12 @@
'AvailabilityZone': 'us-east-1b',
'Encrypted': True,
'Size': 10,
# 'Tags': foo,
'Tags': tags.load(),
'VolumeType': 'gp2'
})
)

cft.outputs.ebs = Output(
"Volume", ref('RefineryData'), "Volume ID")

print(str(cft))
2 changes: 1 addition & 1 deletion refinery/config/config.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"NAME": "refinery",
"PASSWORD": "<%= @rds_role_password %>",
"PORT": "<%= @rds_port %>",
"USER": "<%= @app_user || "vagrant" %>"
"USER": "<%= @rds_role || "vagrant" %>"
}
},
"DEFAULT_FROM_EMAIL": "webmaster@localhost",
Expand Down

0 comments on commit cc2648e

Please sign in to comment.