Commit 9f067f66 authored by Philip Paetz's avatar Philip Paetz
Browse files

feat: replaced obsolete BBK_RUNTIME_ENVIRONMENT with NODE_ENV

parent da2328dc
Pipeline #28825 passed with stages
in 34 seconds
process.env.BBK_RUNTIME_ENVIRONMENT =
process.env.BBK_RUNTIME_ENVIRONMENT || 'production'
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const config = require('@brickblock/strong-config').load()
module.exports = {
......
......@@ -10,7 +10,7 @@
"db:migrate:rollback": "knex migrate:rollback",
"db:seed": "knex seed:run",
"----- AUTOGENERATED DB SECTION END -----": "----- THIS SECTION IS MAINTAINED BY BBK-DEVTOOLS -----",
"start": "export NODE_ENV=development BBK_RUNTIME_ENVIRONMENT=development; nodemon ./src/index.js | bunyan -o short"
"start": "export NODE_ENV=development; nodemon ./src/index.js | bunyan -o short"
},
"dependencies": {
"knex": "^0.17.6",
......
......@@ -10,9 +10,17 @@ build_image:
dependencies:
- build
script:
- docker login --username gitlab-ci-token --password $CI_BUILD_TOKEN $CI_REGISTRY
- >
docker login $CI_REGISTRY
--username gitlab-ci-token
--password $CI_BUILD_TOKEN
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG || true
- docker build --cache-from $CI_REGISTRY_IMAGE:$TAG --tag $CI_REGISTRY_IMAGE:$TAG --build-arg BBK_RUNTIME_ENVIRONMENT=${BBK_RUNTIME_ENVIRONMENT} --build-arg COMMIT_SHA=$CI_COMMIT_SHORT_SHA .
- >
docker build .
--cache-from $CI_REGISTRY_IMAGE:$TAG
--tag $CI_REGISTRY_IMAGE:$TAG
--build-arg NODE_ENV=${NODE_ENV}
--build-arg COMMIT_SHA=$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:$TAG
tags:
- docker
......@@ -2,6 +2,8 @@
tag:
stage: tag
image: docker:latest
only:
- tags
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
......@@ -11,31 +13,36 @@ tag:
- docker
extends: .skip-artifacts
script:
- docker login --username gitlab-ci-token --password $CI_BUILD_TOKEN $CI_REGISTRY
- >
docker login $CI_REGISTRY
--username gitlab-ci-token
--password $CI_BUILD_TOKEN
- docker pull $CI_REGISTRY_IMAGE:latest
# if the branch is master, use the latest tag. When the repository is tagged (git tag), the docker image tag should reflect that.
# if the branch is master, use the latest tag. When the repository is tagged (git tag),
# the docker image tag should reflect that.
- docker tag $CI_REGISTRY_IMAGE:latest $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
production:
stage: deploy
image: registry.brickblock.sh/devops/deploy
variables:
BBK_RUNTIME_ENVIRONMENT: production
NODE_ENV: production
GOOGLE_PROJECT: bbk-production
JQ_TRANSFORMATION: '
if .deployAt.${BBK_RUNTIME_ENVIRONMENT} | type=="array"
then .deployAt.${BBK_RUNTIME_ENVIRONMENT}
| [.[] | { host: .host, path: (.path // "/") }]
else [ { host: "${PRODUCTION_SUBDOMAIN}.${PRODUCTION_DOMAIN}", path: "/" } ]
end
| { "ingresses": . }'
if .deployAt.${NODE_ENV} | type=="array" then .deployAt.${NODE_ENV} | [.[]
| { host: .host, path: (.path // "/") }] else [ { host:
"${PRODUCTION_SUBDOMAIN}.${PRODUCTION_DOMAIN}", path: "/" } ] end | {
"ingresses": . }'
JQ_FIRST_INGRESS: '.ingresses[0] | (.host + .path)'
DEPLOYMENT_NAME: ${CI_PROJECT_PATH_SLUG}
extends: .use-gcloud
retry: 1
environment:
name: production
url: https://${FIRST_INGRESS}
only:
- tags
script:
- jq "${JQ_TRANSFORMATION}" brickblock.json > terraform.tfvars.json
- export FIRST_INGRESS=$(jq "${JQ_FIRST_INGRESS}" terraform.tfvars.json)
......@@ -54,7 +61,7 @@ production:
group = "${NAMESPACE_SLUG}"
image = "${CI_REGISTRY_IMAGE}"
image_tag = "${CI_COMMIT_REF_NAME}"
runtime_environment = "${BBK_RUNTIME_ENVIRONMENT}"
runtime_environment = "${NODE_ENV}"
replicas = "${REPLICAS}"
port = "${APP_PORT}"
commit_sha = "${CI_COMMIT_SHORT_SHA}"
......@@ -68,18 +75,17 @@ production:
variable "ingresses" {}
EOF
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl apply -f -
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl
apply -f -
- terraform init
- terraform workspace new ${DEPLOYMENT_NAME} || true
- terraform workspace select ${DEPLOYMENT_NAME}
- terraform refresh
- terraform plan -input=false
- terraform apply -auto-approve
- kubectl wait --for=condition=available --timeout=3m deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- CI_PROJECT_NAME=${CI_PROJECT_NAME} npx @brickblock/slack-changelog-notifier || true
- echo -e "\n\n ✅ Successfully deployed to:\n\n\n" | cat - terraform.tfvars.json
environment:
name: production
url: https://${FIRST_INGRESS}
only:
- tags
- kubectl wait --for=condition=available --timeout=3m
deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- CI_PROJECT_NAME=${CI_PROJECT_NAME} npx
@brickblock/slack-changelog-notifier || true
- echo -e "\n\n ✅ Successfully deployed to:\n\n\n" | cat -
terraform.tfvars.json
......@@ -2,30 +2,40 @@ register_graphql_production:
stage: post-deploy
only:
- master
- tags
variables:
BBK_RUNTIME_ENVIRONMENT: production
NODE_ENV: production
ENGINE_API_KEY: ${ENGINE_API_KEY}
dependencies:
- build
before_script:
- npm install -g apollo
script:
- apollo service:push --key="${ENGINE_API_KEY}" --serviceName="${CI_PROJECT_NAME}" --serviceRevision="${CI_COMMIT_TAG}" --serviceURL="http://${CI_PROJECT_PATH_SLUG}.${CI_PROJECT_NAMESPACE}:${APP_PORT}/graphql" --localSchemaFile=src/schema.gql --tag=${BBK_RUNTIME_ENVIRONMENT}
only:
- tags
- >
apollo service:push
--key="${ENGINE_API_KEY}"
--serviceName="${CI_PROJECT_NAME}"
--serviceRevision="${CI_COMMIT_TAG}"
--serviceURL="http://${CI_PROJECT_PATH_SLUG}.${CI_PROJECT_NAMESPACE}:${APP_PORT}/graphql"
--localSchemaFile=src/schema.gql
--tag=${NODE_ENV}
register_graphql_staging:
stage: post-deploy
only:
- master
variables:
BBK_RUNTIME_ENVIRONMENT: staging
NODE_ENV: staging
ENGINE_API_KEY: ${ENGINE_API_KEY}
dependencies:
- build
before_script:
- npm install -g apollo
script:
- apollo service:push --key="${ENGINE_API_KEY}" --serviceName="${CI_PROJECT_NAME}" --serviceRevision="${CI_COMMIT_REF_SLUG}" --serviceURL="http://${CI_PROJECT_PATH_SLUG}.${CI_PROJECT_NAMESPACE}:${APP_PORT}/graphql" --localSchemaFile=src/schema.gql --tag=${BBK_RUNTIME_ENVIRONMENT}
only:
- master
\ No newline at end of file
- >
apollo service:push --key="${ENGINE_API_KEY}"
--serviceName="${CI_PROJECT_NAME}"
--serviceRevision="${CI_COMMIT_REF_SLUG}"
--serviceURL="http://${CI_PROJECT_PATH_SLUG}.${CI_PROJECT_NAMESPACE}:${APP_PORT}/graphql"
--localSchemaFile=src/schema.gql
--tag=${NODE_ENV}
......@@ -2,17 +2,14 @@ review:
stage: review
image: registry.brickblock.sh/devops/deploy
variables:
BBK_RUNTIME_ENVIRONMENT: review
GOOGLE_PROJECT: bbk-review
NODE_ENV: review
GOOGLE_PROJECT: bbk-review
ISSUER_SUBDOMAIN: demo
JQ_TRANSFORMATION: '
if .deployAt.${BBK_RUNTIME_ENVIRONMENT} | type=="array"
then .deployAt.${BBK_RUNTIME_ENVIRONMENT}
| [.[] | { host: .host, path: (.path // "/") }]
else [ { host: "${CI_ENVIRONMENT_SLUG}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}", path: "/" } ]
end
| { "ingresses": . }'
if .deployAt.${NODE_ENV} | type=="array" then .deployAt.${NODE_ENV} | [.[]
| { host: .host, path: (.path // "/") }] else [ { host:
"${CI_ENVIRONMENT_SLUG}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}", path: "/" }
] end | { "ingresses": . }'
JQ_FIRST_INGRESS: '.ingresses[0] | (.host + .path)'
DEPLOYMENT_NAME: ${CI_ENVIRONMENT_SLUG}
extends:
......@@ -44,7 +41,7 @@ review:
group = "${NAMESPACE_SLUG}"
image = "${CI_REGISTRY_IMAGE}"
image_tag = "${CI_COMMIT_REF_SLUG}"
runtime_environment = "${BBK_RUNTIME_ENVIRONMENT}"
runtime_environment = "${NODE_ENV}"
replicas = "${REPLICAS}"
port = "${APP_PORT}"
commit_sha = "${CI_COMMIT_SHORT_SHA}"
......@@ -58,15 +55,18 @@ review:
variable "ingresses" {}
EOF
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl apply -f -
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl
apply -f -
- terraform init
- terraform workspace new ${DEPLOYMENT_NAME} || true
- terraform workspace select ${DEPLOYMENT_NAME}
- terraform refresh
- terraform plan -input=false
- terraform apply -auto-approve
- kubectl wait --for=condition=available --timeout=3m deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully deployed to https://${DEPLOYMENT_NAME}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}\n\n"
- kubectl wait --for=condition=available --timeout=3m
deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully deployed to
https://${DEPLOYMENT_NAME}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}\n\n"
environment:
name: $CI_COMMIT_REF_SLUG
url: https://${DEPLOYMENT_NAME}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}
......@@ -77,17 +77,14 @@ stop_review:
image: registry.brickblock.sh/devops/deploy
variables:
GIT_STRATEGY: fetch
BBK_RUNTIME_ENVIRONMENT: review
GOOGLE_PROJECT: bbk-review
NODE_ENV: review
GOOGLE_PROJECT: bbk-review
ISSUER_SUBDOMAIN: demo
JQ_TRANSFORMATION: '
if .deployAt.${BBK_RUNTIME_ENVIRONMENT} | type=="array"
then .deployAt.${BBK_RUNTIME_ENVIRONMENT}
| [.[] | { host: .host, path: (.path // "/") }]
else [ { host: "${CI_ENVIRONMENT_SLUG}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}", path: "/" } ]
end
| { "ingresses": . }'
if .deployAt.${NODE_ENV} | type=="array" then .deployAt.${NODE_ENV} | [.[]
| { host: .host, path: (.path // "/") }] else [ { host:
"${CI_ENVIRONMENT_SLUG}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}", path: "/" }
] end | { "ingresses": . }'
JQ_FIRST_INGRESS: '.ingresses[0] | (.host + .path)'
DEPLOYMENT_NAME: ${CI_ENVIRONMENT_SLUG}
extends:
......@@ -118,7 +115,7 @@ stop_review:
group = "${NAMESPACE_SLUG}"
image = "${CI_REGISTRY_IMAGE}"
image_tag = "${CI_COMMIT_REF_SLUG}"
runtime_environment = "${BBK_RUNTIME_ENVIRONMENT}"
runtime_environment = "${NODE_ENV}"
replicas = "${REPLICAS}"
port = "${APP_PORT}"
commit_sha = "${CI_COMMIT_SHORT_SHA}"
......@@ -136,9 +133,12 @@ stop_review:
- terraform workspace new ${DEPLOYMENT_NAME} || true
- terraform workspace select ${DEPLOYMENT_NAME}
- terraform destroy -force
- terraform workspace select default && terraform workspace delete -force ${DEPLOYMENT_NAME}
- kubectl wait --for=delete --timeout=3m deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully destroyed review app formerly deployed to https://${DEPLOYMENT_NAME}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}\n\n"
- terraform workspace select default && terraform workspace delete -force
${DEPLOYMENT_NAME}
- kubectl wait --for=delete --timeout=3m deployment/${DEPLOYMENT_NAME} -n
${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully destroyed review app formerly deployed to
https://${DEPLOYMENT_NAME}.${ISSUER_SUBDOMAIN}.${REVIEW_DOMAIN}\n\n"
when: manual
environment:
name: $CI_COMMIT_REF_SLUG
......@@ -148,9 +148,8 @@ master_deploy_to_review:
stage: deploy
image: registry.brickblock.sh/devops/deploy
variables:
BBK_RUNTIME_ENVIRONMENT: review
GOOGLE_PROJECT: bbk-review
NODE_ENV: review
GOOGLE_PROJECT: bbk-review
JQ_TRANSFORMATION: '
[ { host: "${CI_PROJECT_PATH_SLUG}.master.${REVIEW_DOMAIN}", path: "/" } ]
| { "ingresses": . }'
......@@ -182,7 +181,7 @@ master_deploy_to_review:
group = "${NAMESPACE_SLUG}"
image = "${CI_REGISTRY_IMAGE}"
image_tag = "latest"
runtime_environment = "${BBK_RUNTIME_ENVIRONMENT}"
runtime_environment = "${NODE_ENV}"
replicas = "${REPLICAS}"
port = "${APP_PORT}"
commit_sha = "${CI_COMMIT_SHORT_SHA}"
......@@ -196,14 +195,17 @@ master_deploy_to_review:
variable "ingresses" {}
EOF
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl apply -f -
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl
apply -f -
- terraform init
- terraform workspace new ${DEPLOYMENT_NAME} || true
- terraform workspace select ${DEPLOYMENT_NAME}
- terraform plan -input=false
- terraform apply -auto-approve
- kubectl wait --for=condition=available --timeout=3m deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully deployed to https://${CI_PROJECT_PATH_SLUG}.master.${REVIEW_DOMAIN}\n\n"
- kubectl wait --for=condition=available --timeout=3m
deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- printf "\n\n ✅ Successfully deployed to
https://${CI_PROJECT_PATH_SLUG}.master.${REVIEW_DOMAIN}\n\n"
environment:
name: review-master-deployments
url: https://${CI_PROJECT_PATH_SLUG}.master.${REVIEW_DOMAIN}
sentry_release_production:
stage: post-deploy
variables:
BBK_RUNTIME_ENVIRONMENT: production
NODE_ENV: production
SENTRY_AUTH_TOKEN: ${SENTRY_AUTH_TOKEN}
SENTRY_ORG: brickblock
SENTRY_PROJECT: ${CI_PROJECT_NAME}
......@@ -9,14 +9,14 @@ sentry_release_production:
- build
script:
- yarn global add @sentry/cli
- sentry-cli releases deploys "$CI_COMMIT_SHORT_SHA" new -e "$BBK_RUNTIME_ENVIRONMENT"
- sentry-cli releases deploys "$CI_COMMIT_SHORT_SHA" new -e "$NODE_ENV"
only:
- tags
sentry_release_staging:
stage: post-deploy
variables:
BBK_RUNTIME_ENVIRONMENT: staging
NODE_ENV: staging
SENTRY_AUTH_TOKEN: ${SENTRY_AUTH_TOKEN}
SENTRY_ORG: brickblock
SENTRY_PROJECT: ${CI_PROJECT_NAME}
......@@ -26,9 +26,10 @@ sentry_release_staging:
script:
- yarn global add @sentry/cli
- sentry-cli releases new "$CI_COMMIT_SHORT_SHA"
- sentry-cli releases files "$CI_COMMIT_SHORT_SHA" upload-sourcemaps --rewrite ./build
- sentry-cli releases files "$CI_COMMIT_SHORT_SHA" upload-sourcemaps
--rewrite ./build
- sentry-cli releases set-commits --auto "$CI_COMMIT_SHORT_SHA"
- sentry-cli releases finalize "$CI_COMMIT_SHORT_SHA"
- sentry-cli releases deploys "$CI_COMMIT_SHORT_SHA" new -e "$BBK_RUNTIME_ENVIRONMENT"
- sentry-cli releases deploys "$CI_COMMIT_SHORT_SHA" new -e "$NODE_ENV"
only:
- master
......@@ -7,36 +7,45 @@ variables:
# made since the last job ran.“
GIT_STRATEGY: fetch
# .set-env-and-tag and .use-gcloud are mutual exclusive since both define `before_script`. Currently, the deep-merge of templates via `extend` does not concat arrays as seen in `before_script`.
# .set-env-and-tag and .use-gcloud are mutually exclusive since both define `before_script`.
# Currently, the deep-merge of templates via `extend` does not concat arrays as seen in `before_script`.
.set-env-and-tag:
before_script:
- >
- >
if [ -n "$CI_COMMIT_TAG" ]; then
export BBK_RUNTIME_ENVIRONMENT=production
export NODE_ENV=production
export TAG=$CI_COMMIT_TAG
export GOOGLE_PROJECT=bbk-production
elif [ "$CI_COMMIT_REF_SLUG" == "master" ]; then
export BBK_RUNTIME_ENVIRONMENT=staging
export NODE_ENV=staging
export TAG=latest
export GOOGLE_PROJECT=bbk-staging
else
export BBK_RUNTIME_ENVIRONMENT=review
export NODE_ENV=review
export TAG=$CI_COMMIT_REF_SLUG
export GOOGLE_PROJECT=bbk-review
fi
- echo -e "\n\n✅ Using variables:\n\tBBK_RUNTIME_ENVIRONMENT = $BBK_RUNTIME_ENVIRONMENT\n\tTAG = $TAG\n\tGOOGLE_PROJECT = $GOOGLE_PROJECT"
- echo -e "\n\n✅ Using variables:\n\tNODE_ENV = $NODE_ENV\n\tTAG =
$TAG\n\tGOOGLE_PROJECT = $GOOGLE_PROJECT"
# .set-env-and-tag and .use-gcloud are mutual exclusive since both define `before_script`. Currently, the deep-merge of templates via `extend` does not concat arrays as seen in `before_script`.
# .set-env-and-tag and .use-gcloud are mutually exclusive since both define `before_script`.
# Currently, the deep-merge of templates via `extend` does not concat arrays as seen in `before_script`.
.use-gcloud:
before_script:
- echo -e "machine git.brickblock.sh\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
- echo -e "machine git.brickblock.sh\nlogin gitlab-ci-token\npassword
${CI_JOB_TOKEN}" > ~/.netrc
- echo $GCLOUD_AUTH | base64 -d > ./gcloud-auth.json
- export GOOGLE_APPLICATION_CREDENTIALS=$PWD/gcloud-auth.json
- gcloud auth activate-service-account ${SERVICE_ACCOUNT} --key-file ./gcloud-auth.json
- gcloud auth activate-service-account ${SERVICE_ACCOUNT} --key-file
./gcloud-auth.json
- gcloud config set project ${GOOGLE_PROJECT}
- export VARIANT=$(gcloud projects describe ${GOOGLE_PROJECT} --format "value(labels.variant)")
- export NAMESPACE_SLUG=$(echo "$CI_PROJECT_NAMESPACE" | sed -r 's/[^a-zA-Z0-9]+/-/g')
- gcloud container clusters get-credentials ${GOOGLE_PROJECT}-${VARIANT}-cluster --zone ${ZONE} --project $GOOGLE_PROJECT
- export VARIANT=$(gcloud projects describe ${GOOGLE_PROJECT} --format
"value(labels.variant)")
- export NAMESPACE_SLUG=$(echo "$CI_PROJECT_NAMESPACE" | sed -r
's/[^a-zA-Z0-9]+/-/g')
- gcloud container clusters get-credentials
${GOOGLE_PROJECT}-${VARIANT}-cluster --zone ${ZONE} --project
$GOOGLE_PROJECT
.except-ci-release:
except:
......@@ -71,10 +80,10 @@ variables:
.release:
stage: release
variables:
GIT_USER_NAME: "gitlab-bot"
GIT_USER_EMAIL: "gitlab-bot@brickblock.io"
GIT_HOST: "git.brickblock.sh"
REPOSITORY_PATH: "${CI_PROJECT_PATH}"
GIT_USER_NAME: 'gitlab-bot'
GIT_USER_EMAIL: 'gitlab-bot@brickblock.io'
GIT_HOST: 'git.brickblock.sh'
REPOSITORY_PATH: '${CI_PROJECT_PATH}'
extends:
- .except-ci-release
- .cache-pull-only
......@@ -88,6 +97,8 @@ variables:
- git config --global user.email ${GIT_USER_EMAIL}
- git config --global push.default current
- yarn release
- git push https://${GIT_USER_NAME}:${SECRET_GITLAB_BOT_CI_TOKEN}@${GIT_HOST}/${REPOSITORY_PATH} HEAD:master --follow-tags
- git push
https://${GIT_USER_NAME}:${SECRET_GITLAB_BOT_CI_TOKEN}@${GIT_HOST}/${REPOSITORY_PATH}
HEAD:master --follow-tags
after_script:
- npx @brickblock/slack-changelog-notifier --projectName $CI_PROJECT_NAME
......@@ -2,15 +2,13 @@ staging:
stage: deploy
image: registry.brickblock.sh/devops/deploy
variables:
BBK_RUNTIME_ENVIRONMENT: staging
NODE_ENV: staging
GOOGLE_PROJECT: bbk-staging
JQ_TRANSFORMATION: '
if .deployAt.${BBK_RUNTIME_ENVIRONMENT} | type=="array"
then .deployAt.${BBK_RUNTIME_ENVIRONMENT}
| [.[] | { host: .host, path: (.path // "/") }]
else [ { host: "${STAGING_SUBDOMAIN}.${STAGING_DOMAIN}", path: "/" } ]
end
| { "ingresses": . }'
if .deployAt.${NODE_ENV} | type=="array" then .deployAt.${NODE_ENV} | [.[]
| { host: .host, path: (.path // "/") }] else [ { host:
"${STAGING_SUBDOMAIN}.${STAGING_DOMAIN}", path: "/" } ] end | {
"ingresses": . }'
JQ_FIRST_INGRESS: '.ingresses[0] | (.host + .path)'
DEPLOYMENT_NAME: ${CI_PROJECT_PATH_SLUG}
extends:
......@@ -20,6 +18,9 @@ staging:
only:
- master
retry: 1
environment:
name: staging
url: https://${FIRST_INGRESS}
script:
- jq "${JQ_TRANSFORMATION}" brickblock.json > terraform.tfvars.json
- export FIRST_INGRESS=$(jq "${JQ_FIRST_INGRESS}" terraform.tfvars.json)
......@@ -38,7 +39,7 @@ staging:
group = "${NAMESPACE_SLUG}"
image = "${CI_REGISTRY_IMAGE}"
image_tag = "latest"
runtime_environment = "${BBK_RUNTIME_ENVIRONMENT}"
runtime_environment = "${NODE_ENV}"
replicas = "${REPLICAS}"
port = "${APP_PORT}"
commit_sha = "${CI_COMMIT_SHORT_SHA}"
......@@ -52,15 +53,15 @@ staging:
variable "ingresses" {}
EOF
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl apply -f -
- kubectl create namespace ${NAMESPACE_SLUG} --dry-run -o yaml | kubectl
apply -f -
- terraform init
- terraform workspace new ${DEPLOYMENT_NAME} || true
- terraform workspace select ${DEPLOYMENT_NAME}
- terraform refresh
- terraform plan -input=false
- terraform apply -auto-approve
- kubectl wait --for=condition=available --timeout=3m deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- echo -e "\n\n ✅ Successfully deployed to:\n\n\n" | cat - terraform.tfvars.json
environment:
name: staging
url: https://${FIRST_INGRESS}
- kubectl wait --for=condition=available --timeout=3m
deployment/${DEPLOYMENT_NAME} -n ${NAMESPACE_SLUG}
- echo -e "\n\n ✅ Successfully deployed to:\n\n\n" | cat -
terraform.tfvars.json
......@@ -2,7 +2,7 @@ FROM node:10 as build
WORKDIR /app
# Needed to tell webpack what environment to build for
ARG BBK_RUNTIME_ENVIRONMENT=production
ARG NODE_ENV=production
# Needed for tagging sentry releases
ARG COMMIT_SHA
......
......@@ -17,19 +17,19 @@ const setupSentry = async () => {
const config = await loadConfig()
if (
config.runtimeEnvironment === 'staging' ||
config.runtimeEnvironment === 'production'
config.runtimeEnv === 'staging' ||
config.runtimeEnv === 'production'
) {
let release: string
// On staging, we use the latest git commit sha as the release name in sentry
if (config.runtimeEnvironment === 'staging') {
if (config.runtimeEnv === 'staging') {
const gitShaShort = getEnvVar('REACT_APP_COMMIT_SHA')
release = gitShaShort
}
// On production, we use the latest tag as the release name in sentry
if (config.runtimeEnvironment === 'production') {
if (config.runtimeEnv === 'production') {
release = version
}
......
{
"scripts": {
"----- AUTOGENERATED REST API SECTION START -----": "----- THIS SECTION IS MAINTAINED BY BBK-DEVTOOLS -----",
"start": "BBK_RUNTIME_ENVIRONMENT=development nodemon ./src/index.js | bunyan -o short",
"start": "NODE_ENV=development nodemon ./src/index.js | bunyan -o short",
"start:prod": "NODE_PATH='./build' node build/index.js",
"start:debug": "yarn build && node inspect ./build/index.js",
"build": "yarn build:clean && COMMIT_SHA=${COMMIT_SHA:-$(git rev-parse --short HEAD)} flow-remove-types --pretty src/ --out-dir build/",
......
......@@ -20,21 +20,17 @@ const bunyan = require('bunyan')
* Set up Sentry.
* https://github.com/getsentry/sentry-javascript/tree/master/packages/node
*/
if (
config.runtimeEnvironment === 'staging' ||
config.runtimeEnvironment === 'production'
) {
if (config.runtimeEnv === 'staging' || config.runtimeEnv === 'production') {
const release =
config.runtimeEnvironment === 'staging' ? process.env.COMMIT_SHA : version
config.runtimeEnv === 'staging' ? process.env.COMMIT_SHA : version
Sentry.init({
dsn: config.sentry.dsnSecret,
environment: config.runtimeEnvironment,
environment: config.runtimeEnv,
release,
})
}
// Services we will add to the koa context
const services: ServiceMapT = {
// $FlowIgnore because log levels are typed as numbers in the bunyan types, but strings are more readable
......@@ -45,6 +41,6 @@ const services: ServiceMapT = {
const { app }: { app: Application } = startServer(config.server.port, services)
// Report uncaught errors to Sentry
app.on('error', error => {
app.on('error', (error) => {
reportError(services.logger, error, 'Caught an unhandled error in koa')
})
// @flow
process.env['BBK_RUNTIME_ENVIRONMENT'] = 'development'
process.env.NODE_ENV = 'development'
const config = require('@brickblock/strong-config').load()
const axios = require('axios')
......@@ -26,7 +26,9 @@ describe('/hello', () => {
})
it('should return a friendly hello', async () => {
const response = await axios.get(`http://localhost:${config.server.port}/hello`)
const response = await axios.get(
`http://localhost:${config.server.port}/hello`
)
expect(response.headers && response.headers['content-type']).toMatch(
/application\/json/
......
......@@ -42,9 +42,7 @@ const startServer: StartServerT = (port, services) => {
koaJsonError({
postFormat: (error, obj) =>
// remove stack trace in non-dev environments
config.runtimeEnvironment === 'development'
? obj
: delete obj.stack && obj,
config.runtimeEnv === 'development' ? obj : delete obj.stack && obj,
})
)
......
// @flow
import type { Logger } from 'bunyan'
const { runtimeEnvironment } = require('@brickblock/strong-config').load()
const { runtimeEnv } = require('@brickblock/strong-config').load()
const Sentry = require('@sentry/node')
type ReportErrorT = (Logger, error: Error, message: ?string) => void
......@@ -10,7 +10,7 @@ const reportError: ReportErrorT = (logger, error, message) => {
? logger.error(`${message}\n`, error)
: logger.error(error)