Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
Initial docker workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiouzelac committed Aug 8, 2019
1 parent d8aa220 commit c916711
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 31 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dynalite
*.out

# OSX
.DS_Store

# doit
.doit.db

# Virtual Environment
venv

# Eggs
.eggs
subhub.egg-info

# Node
node_modules

# Visual Studio Code
.vscode

# PyCharm
.idea

.vscode/
.tox
venv
.doit.db
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ env:
- USER_TABLE: testing
- DEPLOY_ENV: dev
- secure: ldfVKFlO/kQLAmXFTf+UIsj1OzGV+EtfF1mEqp9ArD9eZg0EiM6mr2LTWMAKUyUlD3uCXSkF0xmIUIxNSUB+FwDxSNZdtO+Fx3hmF6I6ofX2NGEDdz2l/F7LeC3MfyPU7qwL9IL15gX2w6got78eDtdGMlhmt2s8dNsWDbLlAMjGZtCvfcXjY5GJS96Pe4lNHbCNlAi+x8E2UsyOBAEAySXfCfbS1JLW9XqiBKk1hinE+f2j47Wb6DJVX3JKfYLgdRdO+4JVa5dJvBIGhmO3lTi+vwDpTx+QbI+/oaoLpqSBpPwcpycZSPCJ0Oo+HfR8DCQRmT8NB6uc/wD44hrYlOXfXudaUH1TzQ2eT+ZT6BY5ikCArHpRDFHzlu2XmbTRq+phzArlV54H8xd46sIrMkLlVP4UHQ1GVOnXWTlG6wkrXxyPUFPAFeSKOiiK2UoHgz6j7yOTwKkuYH3/96GzH+YmoNZPFaDCh31YDFW4+ynlHFWA96U9+GKVS66f52aNMf7El6SwYSeuOzfOnKo5h5opKkkjO83KVrfzwBwpYkXHtyMG2o8hhJUDBF6VozPusJllkZfdyapdQgdTtH5R4Es1QNkzLAfX/iNGfr1yMc+I6O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KMe7oOs+WivqmFtsOV6JywDDR4brBQI3lUtRK2yIrBhdhC/BAogol8g1A5asPL2uGPJtrc4O4E1x5mGgDJLtpefM3zWOqdXiL6YGz0MYZA3hgZxLj2uVHj97pzxPZbZgyrwO6LtH0hbwTxF1L9/Ha42jPEtnjmu6fvygSaQXtjot6saCSIMZBGwYWmk5ckcZ3zgI+G9R9G0eIRwap/mKElmgQX46BqsC/npQWHTQNcv5UmMtFAFRdT76gnWS9NanvOZO3mxreo9q+cyt7yz7TS2bZpNesU1GqLF6mmyWjvJP4FsEB1JhzW+yfAK8+1xnIcRxw8n/XA6x5ZAiJLD5+2M4ukucwj8aM=

before_install:
- python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL);
Expand Down
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM python:3.7-alpine
MAINTAINER Stewart Henderson <shenderson@mozilla.com>

ARG STRIPE_API_KEY
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG STRIPE_LOG
ARG STRIPE_API_MOCK
ARG LOCAL_FLASK_PORT
ARG SUPPORT_API_KEY

ENV STRIPE_API_KEY=$STRIPE_API_KEY
ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
ENV STRIPE_LOG=$STRIPE_LOG
ENV STRIPE_API_MOCK=$STRIPE_API_MOCK
ENV LOCAL_FLASK_PORT=$LOCAL_FLASK_PORT
ENV SUPPORT_API_KEY=$SUPPORT_API_KEY

# Enable Flask debug mode
ENV FLASK_ENV=development

EXPOSE $LOCAL_FLASK_PORT

# Alpine Registry for package versions, https://pkgs.alpinelinux.org/packages
RUN apk update
RUN apk add build-base
RUN apk add libgit2-dev
RUN apk add bash==5.0.0-r0
RUN apk add libc-dev
RUN apk add python3-dev
RUN apk add libffi-dev
RUN apk add openssl-dev
RUN apk add zeromq-dev
RUN apk add linux-headers
RUN apk add nodejs
RUN apk add curl
RUN apk add yarn
RUN apk add gcc==8.3.0-r0
RUN apk add g++
RUN apk add musl-dev
RUN apk add pkgconfig
RUN apk add git
RUN apk add sudo

RUN pip install awscli

COPY ./automation_requirements.txt automation_requirements.txt
RUN pip install -r automation_requirements.txt

RUN mkdir -p /app
WORKDIR /app
COPY . /app
RUN yarn install

RUN addgroup -g 10001 app && \
adduser -D -G app -h /app -u 10001 app

USER app
ENTRYPOINT ["doit", "local"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ This command will generate a PNG of the dependency graph.
doit draw
```

### Docker
* build: `docker build -t mozilla/subhub .`
* run: `docker run -it mozilla/subhub`

### Docker Compose
* build and run: `docker-compose up --build`
* run: `docker-compose up`

## Postman

A [Postman](https://www.getpostman.com/) URL collection is available for testing, learning,
Expand Down
2 changes: 1 addition & 1 deletion automation_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ tox==3.13.2
black==19.3b0
ruamel.yaml==0.15.97
locustio==0.11.0
doit-graph==0.1.1
# doit-graph==0.1.1
pyparsing==2.4.0
19 changes: 19 additions & 0 deletions bin/aws-credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# NOTE: This script is used to provision both TravisCI and Jenkins, AWS credentials and configuration
# Reference AWS Environment Variables
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

mkdir -p ~/.aws

cat > ~/.aws/credentials << EOL
[default]
aws_access_key_id = ${AWS_ACCESS_KEY_ID:-fake-id}
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY:-fake-key}
EOL

cat >~/.aws/config <<-EOF
[default]
output=json
region=${AWS_DEFAULT_REGION:-us-west-2}
EOF
10 changes: 10 additions & 0 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

# NOTE: This bash script is used as an entry point from this application's docker image.

sudo su

printenv
doit venv
#/app/venv/bin/python -m setup develop
doit local
39 changes: 39 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: "3.7"

services:
subhub:
container_name: subhub
build:
context: .
args:
AWS_ACCESS_KEY_ID: "AKIAIOSFODNN7EXAMPLE"
AWS_SECRET_ACCESS_KEY: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
STRIPE_API_KEY: "sk_test_123"
SUPPORT_API_KEY: "support_test"
# NOTE: This enables debug logging of the Stripe API when running in docker-compose.
STRIPE_LOG: "debug"
STRIPE_API_MOCK: "https://stripe:12112"
LOCAL_FLASK_PORT: 5000
ports:
- "5000:5000"
links:
- dynamodb
- stripe
depends_on:
- stripe
dynamodb:
container_name: dynamodb
image: dwmkerr/dynamodb
command: "-sharedDb"
hostname: dynamo
restart: always
environment:
- reschedule=on-node-failure
stripe:
container_name: stripe
build:
# NOTE: There are interesting rules around docker builds from git repos: https://docs.docker.com/engine/reference/commandline/build/#git-repositories
context: https://github.com/stripe/stripe-mock.git#pull/174/head
ports:
- "12111:12111"
- "12112:12112"
13 changes: 7 additions & 6 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,10 @@ def task_draw():
}

if __name__ == '__main__':
cmd = 'sudo python3 -m pip install -r automation_requirements.txt'
answer = input(cmd + '[Y/n] ')
if answer in ('', 'Y', 'y', 'Yes', 'YES', 'yes'):
os.system(cmd)
else:
print('automation_requirements.txt NOT installed!')
cmd = 'python -m pip install -r automation_requirements.txt'
# answer = input(cmd + '[Y/n]')
os.system(cmd)
# if answer in ('', 'Y', 'y', 'Yes', 'YES', 'yes'):
# os.system(cmd)
# else:
# print('automation_requirements.txt NOT installed!')
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
},
"license": "MPL-2.0",
"devDependencies": {
"dynalite": "^2.2.0",
"serverless": "^1.27.3",
"dynalite": "2.3.2",
"serverless": "1.49.0",
"serverless-dynamodb-local": "0.2.38",
"serverless-domain-manager": "^3.2.1",
"serverless-offline": "5.0.1",
"serverless-plugin-tracing": "^2.0.0",
"serverless-domain-manager": "3.2.6",
"serverless-offline": "5.9.0",
"serverless-plugin-tracing": "2.0.0",
"serverless-python-requirements": "4.3.0"
}
}
9 changes: 0 additions & 9 deletions scripts/aws_credentials.sh

This file was deleted.

19 changes: 13 additions & 6 deletions subhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

logger = get_logger()

if CFG.STRIPE_API_MOCK:
stripe.proxy = CFG.STRIPE_API_MOCK
# NOTE: The below 2 lines are discussion points for our application's configuration in general.
stripe.max_network_retries = 1
stripe.enable_telemetry = False
else:
stripe.proxy = "https://api.stripe.com"

# Setup Stripe Error handlers
def intermittent_stripe_error(e):
logger.error("intermittent stripe error", error=e)
Expand Down Expand Up @@ -59,10 +67,11 @@ def server_stripe_card_error(e):

def create_app(config=None):
logger.info("creating flask app", config=config)
region = "localhost"
host = f"http://localhost:{CFG.DYNALITE_PORT}"
stripe.api_key = CFG.STRIPE_API_KEY
if CFG.AWS_EXECUTION_ENV:
if not CFG.AWS_EXECUTION_ENV:
region = "localhost"
host = f"http://dynamodb:{CFG.DYNALITE_PORT}"
stripe.api_key = CFG.STRIPE_API_KEY
else:
region = "us-west-2"
host = None
options = dict(swagger_ui=CFG.SWAGGER_UI)
Expand Down Expand Up @@ -140,6 +149,4 @@ def after_request(response):

if __name__ == "__main__":
app = create_app()
app.debug = True
app.use_reloader = True
app.run(host="0.0.0.0", port=CFG.LOCAL_FLASK_PORT)
7 changes: 7 additions & 0 deletions subhub/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ def PROFILING_ENABLED(self):
"""
return ast.literal_eval(self("PROFILING_ENABLED", "False"))

@property
def STRIPE_API_MOCK(self):
"""
STRIPE_MOCK
"""
return self("STRIPE_API_MOCK", None)

@property
def DEPLOY_DOMAIN(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions subhub/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ botocore==1.12.184
certifi==2019.6.16
chardet==3.0.4
colorama==0.4.1
connexion==2.3.0
connexion>=2.3.0
connexion[swagger-ui]
docutils==0.14
Flask==1.1.0
Expand All @@ -31,7 +31,7 @@ PyYAML==5.1.1
requests==2.22.0
s3transfer==0.2.1
six==1.12.0
stripe==2.32.1
stripe==2.33.0
structlog==19.1.0
urllib3==1.25.3
pyinstrument==3.0.3
Expand Down

0 comments on commit c916711

Please sign in to comment.