Skip to content

Commit 6ee1660

Browse files
authored
Merge pull request #352 from isb-cgc/prod-sp
API v4
2 parents e205014 + 146d9cf commit 6ee1660

File tree

172 files changed

+5623
-25028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+5623
-25028
lines changed

.circleci/config.yml

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
1-
version: 2
1+
version: 2.1
2+
commands:
3+
deployment_setup:
4+
steps:
5+
- run:
6+
name: "Set the Tier"
7+
command: |
8+
TIER=DEV
9+
if [[ ${CIRCLE_BRANCH} =~ (prod|uat|test).* ]]; then
10+
TIER=$(awk -F[\-_] '{print toupper($1)}' \<<< ${CIRCLE_BRANCH})
11+
fi
12+
echo "export TIER=${TIER}" >> $BASH_ENV
13+
echo "Tier was identified as ${TIER} for branch ${CIRCLE_BRANCH}"
14+
- run:
15+
name: "Assign Project-level vars"
16+
command: |
17+
if [ ! -f deployment.key.json ]; then
18+
echo "Deployment JSON keyfile not found - loading from CircleCI."
19+
KEY=${DEPLOYMENT_KEY_ISB_CGC}
20+
else
21+
echo "Deployment JSON keyfile found."
22+
KEY="NA"
23+
fi
24+
CLIENT_EMAIL=${DEPLOYMENT_CLIENT_EMAIL_ISB_CGC}
25+
PROJECT_ID=${DEPLOYMENT_PROJECT_ID_ISB_CGC}
26+
BUCKET=${DEPLOYMENT_BUCKET_ISB_CGC}
27+
if [[ ${TIER} == "PROD" ]] || [[ ${TIER} == "DEV" ]]; then
28+
BUCKET="${BUCKET}/${TIER,,}"
29+
echo "Using default project ${PROJECT_ID} and related deployment SA and bucket."
30+
elif [[ ${TIER} == "UAT" ]]; then
31+
KEY=${DEPLOYMENT_KEY_ISB_CGC_UAT}
32+
CLIENT_EMAIL=${DEPLOYMENT_CLIENT_EMAIL_ISB_CGC_UAT}
33+
PROJECT_ID=${DEPLOYMENT_PROJECT_ID_ISB_CGC_UAT}
34+
BUCKET=${DEPLOYMENT_BUCKET_ISB_CGC_UAT}
35+
elif [[ ${TIER} == "TEST" ]]; then
36+
KEY=${DEPLOYMENT_KEY_ISB_CGC_TEST}
37+
CLIENT_EMAIL=${DEPLOYMENT_CLIENT_EMAIL_ISB_CGC_TEST}
38+
PROJECT_ID=${DEPLOYMENT_PROJECT_ID_ISB_CGC_TEST}
39+
BUCKET=${DEPLOYMENT_BUCKET_ISB_CGC_TEST}
40+
else
41+
echo "[ERROR] - Unrecognized tier: ${TIER} - exitng."
42+
exit 1
43+
fi
44+
45+
echo "export DEPLOYMENT_KEY=\"${KEY}\"" >> $BASH_ENV
46+
echo "export DEPLOYMENT_CLIENT_EMAIL=${CLIENT_EMAIL}" >> $BASH_ENV
47+
echo "export DEPLOYMENT_PROJECT_ID=${PROJECT_ID}" >> $BASH_ENV
48+
echo "export DEPLOYMENT_BUCKET=${BUCKET}" >> $BASH_ENV
49+
50+
deployment_config:
51+
steps:
52+
- run:
53+
name: "Set tier-specific configuration file"
54+
command: |
55+
sudo -E /bin/bash ./shell/pull_config.sh
56+
xargs -a deployment_config.txt -I{} echo "export {}" >> $BASH_ENV
57+
58+
auth:
59+
steps:
60+
- run:
61+
name: "Service Account Auth and Project Settings"
62+
command: |
63+
sudo -E /bin/bash ./shell/gcloud_authenticate.sh
64+
65+
install_cloud_sdk:
66+
steps:
67+
- run:
68+
name: "Install CloudSDK"
69+
command: |
70+
echo "export CLOUDSDK_CORE_DISABLE_PROMPTS=1" >> $BASH_ENV
71+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
72+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
73+
sudo apt-get update && sudo apt-get -y --allow-downgrades install google-cloud-sdk=251.0.0-0
74+
275
jobs:
376
build_job:
477
environment:
578
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
6-
name: Building Deployment Container
779
working_directory: ~/ISB-CGC-API
880
docker:
9-
- image: circleci/python:2.7.14
81+
- image: circleci/python:3.7.0-stretch
1082
- image: circleci/mysql:5.7
1183
environment:
1284
MYSQL_ROOT_HOST: "%"
@@ -33,30 +105,22 @@ jobs:
33105
key: isb-cgc-api-lib-{{ checksum "requirements.txt" }}
34106
paths:
35107
- ./lib
36-
- save_cache:
37-
key: isb-cgc-api-google-deps-{{ checksum "./shell/install-deps.sh" }}
38-
paths:
39-
- ./google-cloud-sdk
40-
- ./google_appengine
108+
- deployment_setup
109+
- auth
110+
- deployment_config
41111
- run:
42-
name: Auth and Staging
112+
name: Staging
43113
command: |
44-
sudo -E /bin/sh ./shell/gcloud_authenticate.sh
45114
sudo -E /bin/bash ./shell/gcloud-pull-staging-files.sh
46115
- save_cache:
47116
key: isb-cgc-api-{{ epoch }}
48117
paths:
49-
- ./api
50-
- ./api_3
51-
- ./bq_data_access
118+
- ./apiv4
52119
- ./shell
53120
- ./ISB-CGC-Common
54-
- ./saml
55-
- ./lib
56-
- ./appengine_config.py
57-
- ./cgc_api.py
121+
- ./Dockerfile
58122
- ./app.yaml
59-
- ./manage.py
123+
- ./openapi-appengine.yaml
60124
- ./settings.py
61125
- ./txt
62126
- ./json
@@ -65,9 +129,8 @@ jobs:
65129
deploy_job:
66130
environment:
67131
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
68-
name: Deploy to AppEngine Standard
69132
docker:
70-
- image: circleci/python:2.7.14
133+
- image: circleci/python:3.7.0-stretch
71134
working_directory: ~/ISB-CGC-API
72135
steps:
73136
- restore_cache:
@@ -76,11 +139,16 @@ jobs:
76139
- restore_cache:
77140
keys:
78141
- isb-cgc-api-google-deps-
142+
- install_cloud_sdk
143+
- deployment_setup
144+
- auth
145+
- deployment_config
79146
- deploy:
147+
nane: Deployment
80148
command: |
81-
sudo -E /bin/bash ./shell/gcloud_authenticate.sh
82149
sudo -E /bin/bash ./shell/unpack_for_deployment.sh
83-
sudo -E ./google-cloud-sdk/bin/gcloud app deploy --verbosity=debug ./app.yaml --quiet
150+
sudo -E gcloud endpoints services deploy ./openapi-appengine.yaml
151+
sudo -E gcloud app deploy --verbosity=debug ./app.yaml --quiet
84152
workflows:
85153
version: 2
86154
build_and_deploy:
@@ -91,4 +159,8 @@ workflows:
91159
- build_job
92160
filters:
93161
branches:
94-
only: prod
162+
only:
163+
- master
164+
- test
165+
- uat
166+
- prod

.gitignore

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,12 @@ target/
7373
.sass-cache
7474
#*
7575
*.json
76-
!isb_cgc_apiv3_openapiv2.json
77-
!isb_cgc_ccle_apiv3_openapiv2.json
78-
!isb_cgc_target_apiv3_openapiv2.json
79-
!isb_cgc_tcga_apiv3_openapiv2.json
80-
!isb_cgc_apiv3_openapiv3.json
81-
!isb_cgc_ccle_apiv3_openapiv3.json
82-
!isb_cgc_target_apiv3_openapiv3.json
83-
!isb_cgc_tcga_apiv3_openapiv3.json
8476
*.patch
8577
.env
8678
*.env
87-
scripts/metadata_featdef_tables.sql
79+
openapi-appengine.yaml
8880
app.yaml
81+
scripts/metadata_featdef_tables.sql
8982

9083
# dummy datasets
9184
*.tsv

Dockerfile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
###
2+
#
3+
# Copyright 2019, Institute for Systems Biology
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
###
18+
19+
# Dockerfile extending the generic Python image with application files for a
20+
# single application.
21+
FROM gcr.io/google_appengine/python
22+
23+
# Create a virtualenv for dependencies. This isolates these packages from
24+
# system-level packages.
25+
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
26+
RUN virtualenv /env -p python3
27+
28+
# Setting these environment variables are the same as running
29+
# source /env/bin/activate.
30+
ENV VIRTUAL_ENV /env
31+
ENV PATH /env/bin:$PATH
32+
33+
RUN apt-get update
34+
ENV DEBIAN_FRONTEND=noninteractive
35+
RUN apt-get install -y wget
36+
RUN wget "http://repo.mysql.com/mysql-apt-config_0.8.9-1_all.deb" -P /tmp
37+
38+
# install lsb-release (a dependency of mysql-apt-config), since dpkg doesn't
39+
# do dependency resolution
40+
RUN apt-get install -y lsb-release
41+
# add a debconf entry to select mysql-5.7 as the server version when we install
42+
# the mysql config package
43+
RUN echo "mysql-apt-config mysql-apt-config/select-server select mysql-5.7" | debconf-set-selections
44+
# having 'selected' mysql-5.7 for 'server', install the mysql config package
45+
RUN echo 'download mysql public build key'
46+
RUN apt-key del 1550412832
47+
RUN wget -O - -q 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x8C718D3B5072E1F5' | grep -v '>' | grep -v '<' | grep -v '{' > mysql_pubkey.asc
48+
RUN apt-key add mysql_pubkey.asc || exit 1
49+
RUN dpkg --install /tmp/mysql-apt-config_0.8.9-1_all.deb
50+
51+
# fetch the updated package metadata (in particular, mysql-server-5.7)
52+
RUN apt-get update
53+
54+
# aaaand now let's install mysql-server
55+
RUN apt-get install -y mysql-server
56+
57+
# Get pip3 installed
58+
RUN curl --silent https://bootstrap.pypa.io/get-pip.py | python3
59+
60+
RUN apt-get -y install build-essential
61+
RUN apt-get -y install --reinstall python-m2crypto python3-crypto
62+
RUN apt-get -y install libxml2-dev libxmlsec1-dev swig
63+
RUN pip3 install pexpect
64+
65+
RUN apt-get -y install unzip libffi-dev libssl-dev libmysqlclient-dev python3-mysqldb python3-dev libpython3-dev git ruby g++ curl
66+
RUN easy_install -U distribute
67+
68+
ADD . /app
69+
70+
# We need to recompile some of the items because of differences in compiler versions
71+
RUN pip3 install -r /app/requirements.txt -t /app/lib/ --upgrade
72+
RUN pip3 install gunicorn==19.9.0
73+
74+
# Install Cloud SDK
75+
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y
76+
# Install the Python Libraries
77+
RUN apt-get -y install google-cloud-sdk-app-engine-python
78+
79+
ENV PYTHONPATH=/app:/app/apiv4:/app/lib:/app/ISB-CGC-Common:${PYTHONPATH}
80+
81+
CMD gunicorn -b :$PORT apiv4:app -w 3 -t 130

Vagrantfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
Vagrant.configure(2) do |config|
4+
config.vm.box_url = "https://app.vagrantup.com/ubuntu/boxes/xenial64"
5+
config.vm.box = "ubuntu/xenial64"
6+
7+
# API ports
8+
config.vm.network "forwarded_port", guest: 8090, host: 8090
9+
config.vm.network "forwarded_port", guest: 9000, host: 9000
10+
11+
config.vm.synced_folder ".", "/home/vagrant/API"
12+
config.vm.synced_folder "../", "/home/vagrant/parentDir"
13+
14+
# Map Common and lib for API
15+
config.vm.synced_folder "../ISB-CGC-Common", "/home/vagrant/API/ISB-CGC-Common"
16+
17+
config.vm.provision "shell", path: 'shell/install-deps.sh'
18+
config.vm.provision "shell", path: 'shell/vagrant-start-server.sh'
19+
config.vm.provision "shell", path: 'shell/vagrant-set-env.sh'
20+
end

0 commit comments

Comments
 (0)