Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/test'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisveilleux committed Jul 17, 2020
2 parents 2ca7019 + 29cf0c0 commit 22da7cd
Show file tree
Hide file tree
Showing 84 changed files with 3,071 additions and 1,612 deletions.
108 changes: 108 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Multi-stage Dockerfile for running Selene APIs or their test suites.
#
# ASSUMPTION:
# This Dockerfile assumes its resulting containers will run on a Docker network. A Postgres container named
# "selene-db" and a Redis container named "selene-cache" also need to be running on this network. To create the
# network and the Postgres/Redis containers, use the following commands:
# docker network create --driver bridge <network name>
# docker run -d --net <network name> --name selene-cache redis:6
# docker run -d -e POSTGRES_PASSWORD=selene --net <network name> --name selene-db postgres:10
# The DB_HOST environment variable is set to the name of the Postgres container and the REDIS_HOST environment
# variable is set to the name of he Redis container. When running images created from this Dockerfile, include the
# "--net <network name>" argument.

# Build steps that apply to all of the selene applications.
FROM python:3.7-slim as selene-base
RUN apt-get update && apt-get -y install gcc git
RUN python3 -m pip install pipenv
RUN mkdir -p /root/allure /opt/selene/selene-backend /root/code-quality /var/log/mycroft
WORKDIR /opt/selene/selene-backend
ENV DB_HOST selene-db
ENV DB_PASSWORD adam
ENV SELENE_ENVIRONMENT dev
ENV DB_NAME mycroft
ENV DB_USER selene
ENV JWT_ACCESS_SECRET access-secret
ENV JWT_REFRESH_SECRET refresh-secret
ENV SALT testsalt
ENV REDIS_HOST selene-cache
ENV REDIS_PORT 6379
COPY shared shared

# Code quality scripts and user agreements are stored in the MycroftAI/devops repository. This repository is private.
# builds for publicly available images should not use this build stage.
#
# The GitHub API key is sensitive information and can change depending on who is running the application.
# It is used here to clone the private MycroftAI/devops repository.
FROM selene-base as devops-build
ARG github_api_key
ENV GITHUB_API_KEY=$github_api_key
RUN mkdir -p /opt/mycroft
WORKDIR /opt/mycroft
RUN git clone https://[email protected]/MycroftAI/devops.git
WORKDIR /opt/mycroft/devops/jenkins
# TODO: remove when the pull-request-identifier branch is merged.
RUN git checkout bug/pull-request-identifier
RUN pipenv install

# Run a linter and code formatter against the API specified in the build argument
FROM devops-build as api-code-check
ARG api_name
WORKDIR /opt/selene/selene-backend
COPY api/${api_name} api/${api_name}
WORKDIR /opt/selene/selene-backend/api/${api_name}
RUN pipenv install --dev
ENV PYTHONPATH=$PYTHONPATH:/opt/selene/selene-backend/api/${api_name}
WORKDIR /opt/mycroft/devops/jenkins
ENTRYPOINT ["pipenv", "run", "python", "-m", "pipeline.code_check", "--repository", "selene-backend", "--base-dir", "/opt/selene"]

# Bootstrap the Selene database as it will be needed to run any Selene applications.
FROM devops-build as db-bootstrap
ENV POSTGRES_PASSWORD selene
WORKDIR /opt/selene/selene-backend
COPY db db
WORKDIR /opt/selene/selene-backend/db
RUN pipenv install
ENTRYPOINT ["pipenv", "run", "python", "scripts/bootstrap_mycroft_db.py"]

# Run the tests defined in the Account API
FROM selene-base as account-api-test
ARG stripe_api_key
ENV PYTHONPATH=$PYTHONPATH:/opt/selene/selene-backend/api/account
ENV STRIPE_PRIVATE_KEY $stripe_api_key
COPY api/account api/account
WORKDIR /opt/selene/selene-backend/api/account
RUN pipenv install --dev
WORKDIR /opt/selene/selene-backend/api/account/tests
ENTRYPOINT ["pipenv", "run", "behave", "-f", "allure_behave.formatter:AllureFormatter", "-o", "/root/allure/allure-result"]

# Run the tests defined in the Single Sign On API
FROM selene-base as sso-api-test
ARG github_client_id
ARG github_client_secret
ENV PYTHONPATH=$PYTHONPATH:/opt/selene/selene-backend/api/sso
ENV JWT_RESET_SECRET reset-secret
# The GitHub client ID and secret are sensitive information and can change depending on who is running the application.
# They are used here to facilitate user authentication using a GitHub account.
ENV GITHUB_CLIENT_ID $github_client_id
ENV GITHUB_CLIENT_SECRET $github_client_secret
COPY api/sso api/sso
WORKDIR /opt/selene/selene-backend/api/sso
RUN pipenv install --dev
WORKDIR /opt/selene/selene-backend/api/sso/tests
ENTRYPOINT ["pipenv", "run", "behave", "-f", "allure_behave.formatter:AllureFormatter", "-o", "/root/allure/allure-result"]

# Run the tests defined in the Public Device API
FROM selene-base as public-api-test
RUN mkdir -p /opt/selene/data
ARG google_stt_key
ARG wolfram_alpha_key
ENV PYTHONPATH=$PYTHONPATH:/opt/selene/selene-backend/api/public
ENV GOOGLE_STT_KEY $google_stt_key
ENV WOLFRAM_ALPHA_KEY $wolfram_alpha_key
ENV WOLFRAM_ALPHA_URL https://api.wolframalpha.com
COPY api/public api/public
WORKDIR /opt/selene/selene-backend/api/public
RUN pipenv install --dev
WORKDIR /opt/selene/selene-backend/api/public/tests
ENTRYPOINT ["pipenv", "run", "behave", "-f", "allure_behave.formatter:AllureFormatter", "-o", "/root/allure/allure-result"]
172 changes: 160 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,170 @@
pipeline {
agent any

options {
// Running builds concurrently could cause a race condition with
// building the Docker image.
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5'))
}
environment {
// Some branches have a "/" in their name (e.g. feature/new-and-cool)
// Some commands, such as those that deal with directories, don't
// play nice with this naming convention. Define an alias for the
// branch name that can be used in these scenarios.
BRANCH_ALIAS = sh(
script: 'echo $BRANCH_NAME | sed -e "s#/#-#g"',
returnStdout: true
).trim()
DOCKER_BUILDKIT=1
//spawns GITHUB_USR and GITHUB_PSW environment variables
GITHUB_API=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190')
GITHUB_CLIENT_ID=credentials('380f58b1-8a33-4a9d-a67b-354a9b0e792e')
GITHUB_CLIENT_SECRET=credentials('71626c21-de59-4450-bfad-5034fd596fb2')
GOOGLE_STT_KEY=credentials('287949f8-2ada-4450-8806-1fe2dd8e4c4d')
STRIPE_KEY=credentials('9980e41f-d418-49af-9d62-341d1246f555')
WOLFRAM_ALPHA_KEY=credentials('f718e0a1-c19c-4c7f-af88-0689738ccaa1')
}
stages {

// Create the virtual environments and install the packages
stage('Build dev branch') {
stage('Lint & Format') {
// Run PyLint and Black to check code quality.
when {
changeRequest target: 'dev'
}
steps {
labelledShell label: 'Account API Setup', script: """
docker build \
--build-arg github_api_key=${GITHUB_API_PSW} \
--build-arg api_name=account \
--target api-code-check --no-cache \
-t selene-linter:${BRANCH_ALIAS} .
"""
labelledShell label: 'Account API Check', script: """
docker run selene-linter:${BRANCH_ALIAS} --pipenv-dir api/account --pull-request=${BRANCH_NAME}
"""
labelledShell label: 'Single Sign On API Setup', script: """
docker build \
--build-arg github_api_key=${GITHUB_API_PSW} \
--build-arg api_name=sso \
--target api-code-check --no-cache \
-t selene-linter:${BRANCH_ALIAS} .
"""
labelledShell label: 'Single Sign On API Check', script: """
docker run selene-linter:${BRANCH_ALIAS} --pipenv-dir api/sso --pull-request=${BRANCH_NAME}
"""
labelledShell label: 'Public API Setup', script: """
docker build \
--build-arg github_api_key=${GITHUB_API_PSW} \
--build-arg api_name=public \
--target api-code-check --no-cache \
-t selene-linter:${BRANCH_ALIAS} .
"""
labelledShell label: 'Public API Check', script: """
docker run selene-linter:${BRANCH_ALIAS} --pipenv-dir api/public --pull-request=${BRANCH_NAME}
"""
}
}
stage('Bootstrap DB') {
when {
anyOf {
branch 'dev'
branch 'master'
changeRequest target: 'dev'
}
}
steps {
labelledShell label: 'Building Docker image', script: """
docker build \
--target db-bootstrap \
--build-arg github_api_key=${GITHUB_API_PSW} \
-t selene-db:${BRANCH_ALIAS} .
"""
timeout(time: 5, unit: 'MINUTES')
{
labelledShell label: 'Run database bootstrap script', script: """
docker run --net selene-net selene-db:${BRANCH_ALIAS}
"""
}
}
}
stage('Account API Tests') {
when {
anyOf {
branch 'dev'
branch 'master'
changeRequest target: 'dev'
}
}
steps {
labelledShell label: 'Building Docker image', script: """
docker build \
--build-arg stripe_api_key=${STRIPE_KEY} \
--target account-api-test \
-t selene-account:${BRANCH_ALIAS} .
"""
timeout(time: 5, unit: 'MINUTES')
{
labelledShell label: 'Running behave tests', script: """
docker run \
--net selene-net \
-v '${HOME}/allure/selene/:/root/allure' \
selene-account:${BRANCH_ALIAS}
"""
}
}
}
stage('Single Sign On API Tests') {
when {
anyOf {
branch 'dev'
branch 'master'
changeRequest target: 'dev'
}
}
steps {
labelledShell label: 'Building Docker image', script: """
docker build \
--build-arg github_client_id=${GITHUB_CLIENT_ID} \
--build-arg github_client_secret=${GITHUB_CLIENT_SECRET} \
--target sso-api-test \
-t selene-sso:${BRANCH_ALIAS} .
"""
timeout(time: 2, unit: 'MINUTES')
{
labelledShell label: 'Running behave tests', script: """
docker run \
--net selene-net \
-v '${HOME}/allure/selene/:/root/allure' \
selene-sso:${BRANCH_ALIAS}
"""
}
}
}
stage('Public Device API Tests') {
when {
branch 'dev'
anyOf {
branch 'dev'
branch 'master'
changeRequest target: 'dev'
}
}
steps {
echo 'Building code in the "dev" branch...'
sh '''
cd api/account
pipenv install
pipenv install --dev
'''
labelledShell label: 'Building Docker image', script: """
docker build \
--build-arg google_stt_key=${GOOGLE_STT_KEY} \
--build-arg wolfram_alpha_key=${WOLFRAM_ALPHA_KEY} \
--target public-api-test \
-t selene-public:${BRANCH_ALIAS} .
"""
timeout(time: 2, unit: 'MINUTES')
{
labelledShell label: 'Running behave tests', script: """
docker run \
--net selene-net \
-v '$HOME/allure/selene/:/root/allure' \
selene-public:${BRANCH_ALIAS}
"""
}
}
}

}
}
2 changes: 2 additions & 0 deletions api/account/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ selene = {editable = true,path = "./../../shared"}
[dev-packages]
behave = "*"
pyhamcrest = "*"
allure-behave = "*"
pylint = "*"

[requires]
python_version = "3.7"
Loading

0 comments on commit 22da7cd

Please sign in to comment.