From 6a5675cbc0911d6ab2bec93c006c9f05d9dc74a6 Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Wed, 24 Oct 2018 18:00:17 +1100 Subject: [PATCH] fix(monorepo): Update CI config for oauth-server import. --- .circleci/config.yml | 75 +++++++++++++++++++++ .dockerignore | 1 + .travis.yml | 74 +++++++++++++++------ fxa-oauth-server/.circleci/config.yml | 95 --------------------------- fxa-oauth-server/.travis.yml | 46 ------------- fxa-oauth-server/lib/routes/root.js | 2 +- 6 files changed, 131 insertions(+), 162 deletions(-) delete mode 100644 fxa-oauth-server/.circleci/config.yml delete mode 100644 fxa-oauth-server/.travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index aa5c6c3cf..58a868d1b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,6 +66,76 @@ jobs: docker push ${DOCKERHUB_REPO}:${DOCKER_TAG} fi + + build-oauth: + docker: + - image: circleci/node + + steps: + - checkout + - setup_remote_docker + + - run: + name: Create version.json + command: > + printf '{"version":{"hash":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}}\n' + "$CIRCLE_SHA1" + "$CIRCLE_TAG" + "$CIRCLE_PROJECT_USERNAME" + "fxa-oauth-server" + "$CIRCLE_BUILD_URL" + | tee fxa-oauth-server/config/version.json fxa-oauth-server/version.json + - store_artifacts: + path: version.json + + - run: + name: Build deployment container image + command: cd fxa-oauth-server && docker build -f Dockerfile-build -t fxa-oauth-server:build . + + - run: + name: Check npm install + command: cd fxa-oauth-server && docker run --rm -it fxa-oauth-server:build npm ls --production + + - run: + name: Build test container image + command: cd fxa-oauth-server && docker build -f Dockerfile-test -t fxa-oauth-server:test . + + - run: + name: Run MySQL + command: docker run -d --name=mydb -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_ROOT_HOST=% -p 3306:3306 mysql/mysql-server:5.6 + background: true + + - run: + name: Run Memory DB Tests + command: cd fxa-oauth-server && docker run fxa-oauth-server:test npm test + + - run: + name: Run MySQL DB Tests + command: cd fxa-oauth-server && docker run --net=host -p 3306:3306 -e DB="mysql" fxa-oauth-server:test npm test + + - run: + name: Push to Dockerhub + command: | + if [ "${CIRCLE_BRANCH}" == "master" ]; then + DOCKER_TAG="latest" + fi + + if [[ "${CIRCLE_BRANCH}" == feature* ]] || [[ "${CIRCLE_BRANCH}" == dockerpush* ]]; then + DOCKER_TAG="${CIRCLE_BRANCH}" + fi + + if [ -n "${CIRCLE_TAG}" ]; then + DOCKER_TAG="$CIRCLE_TAG" + fi + + if [ -n "${DOCKER_TAG}" ]; then + echo "$DOCKER_OAUTH_PASS" | docker login -u "$DOCKER_OAUTH_USER" --password-stdin + echo ${DOCKERHUB_OAUTH_REPO}:${DOCKER_TAG} + docker tag fxa-oauth-server:build ${DOCKERHUB_OAUTH_REPO}:${DOCKER_TAG} + docker images + docker push ${DOCKERHUB_OAUTH_REPO}:${DOCKER_TAG} + fi + workflows: version: 2 @@ -83,3 +153,8 @@ workflows: filters: tags: only: /.*/ + + - build-oauth: + filters: + tags: + only: /.*/ diff --git a/.dockerignore b/.dockerignore index 6b8710a71..173012b5e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ .git +fxa-oauth-server diff --git a/.travis.yml b/.travis.yml index 9eb96aa21..84993be45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ node_js: - "8" dist: trusty +sudo: true services: - redis-server @@ -13,15 +14,11 @@ addons: sources: - ubuntu-toolchain-r-test packages: + - g++-4.8 - mysql-server-5.6 - mysql-client-core-5.6 - mysql-client-5.6 -env: - matrix: - - DB=memory - - DB=mysql - notifications: email: - rfkelly@mozilla.com @@ -32,19 +29,56 @@ notifications: use_notice: false skip_join: false -before_install: - - npm i -g npm@6 - - npm config set spin false - -install: - - npm ci +_aliases: + - &test + before_install: + - npm i -g npm@6 + - npm config set spin false + - &fxa-auth-memory-test + env: DB=memory + <<: *test + - &fxa-auth-mysql-test + env: DB=mysql + <<: *test + - &fxa-oauth-memory-test + env: CXX=g++-4.8 NODE_ENV=test DB=memory + <<: *test + - &fxa-oauth-mysql-test + env: CXX=g++-4.8 NODE_ENV=test DB=mysql + <<: *test -script: - - if [ $DB == "mysql" ]; then ./scripts/start-travis-auth-db-mysql.sh; fi - - npm run test-ci - - npm run test-e2e - - npm run test-scripts - # Test fxa-auth-mailer - - grunt templates && git status -s | (! grep 'M lib/senders/templates/') - - grunt l10n-extract - - npm run lint:deps +jobs: + include: + - stage: + node_js: 8 + <<: *fxa-auth-memory-test + install: + - npm ci + script: + - npm run test-ci + - npm run test-e2e + - npm run test-scripts + - grunt templates && git status -s | (! grep 'M lib/senders/templates/') + - grunt l10n-extract + - npm run lint:deps + - stage: + node_js: 8 + <<: *fxa-auth-mysql-test + install: + - npm ci + script: + - ./scripts/start-travis-auth-db-mysql.sh + - npm run test-ci + - npm run test-e2e + - stage: + node_js: 8 + <<: *fxa-oauth-memory-test + install: + - cd fxa-oauth-server && npm ci && cd .. + script: cd fxa-oauth-server && npm test + - stage: + node_js: 8 + <<: *fxa-oauth-memory-test + install: + - cd fxa-oauth-server && npm ci && cd .. + script: cd fxa-oauth-server && npm test diff --git a/fxa-oauth-server/.circleci/config.yml b/fxa-oauth-server/.circleci/config.yml deleted file mode 100644 index 45bd06502..000000000 --- a/fxa-oauth-server/.circleci/config.yml +++ /dev/null @@ -1,95 +0,0 @@ -# These environment variables must be set in CircleCI UI -# -# DOCKERHUB_REPO - docker hub repo, format: / -# DOCKER_EMAIL - login info for docker hub -# DOCKER_USER -# DOCKER_PASS -# -version: 2 -jobs: - build: - docker: - - image: circleci/node - - steps: - - checkout - - setup_remote_docker - - - run: - name: Create version.json - command: > - printf '{"version":{"hash":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}}\n' - "$CIRCLE_SHA1" - "$CIRCLE_TAG" - "$CIRCLE_PROJECT_USERNAME" - "$CIRCLE_PROJECT_REPONAME" - "$CIRCLE_BUILD_URL" - | tee config/version.json version.json - - store_artifacts: - path: version.json - - - run: - name: Build deployment container image - command: docker build -f Dockerfile-build -t fxa-oauth-server:build . - - - run: - name: Check npm install - command: docker run --rm -it fxa-oauth-server:build npm ls --production - - - run: - name: Build test container image - command: docker build -f Dockerfile-test -t fxa-oauth-server:test . - - - run: - name: Run MySQL - command: docker run -d --name=mydb -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_ROOT_HOST=% -p 3306:3306 mysql/mysql-server:5.6 - background: true - - - run: - name: Run Memory DB Tests - command: docker run fxa-oauth-server:test npm test - - - run: - name: Run MySQL DB Tests - command: docker run --net=host -p 3306:3306 -e DB="mysql" fxa-oauth-server:test npm test - - - run: - name: Push to Dockerhub - command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - DOCKER_TAG="latest" - fi - - if [[ "${CIRCLE_BRANCH}" == feature* ]] || [[ "${CIRCLE_BRANCH}" == dockerpush* ]]; then - DOCKER_TAG="${CIRCLE_BRANCH}" - fi - - if [ -n "${CIRCLE_TAG}" ]; then - DOCKER_TAG="$CIRCLE_TAG" - fi - - if [ -n "${DOCKER_TAG}" ]; then - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin - echo ${DOCKERHUB_REPO}:${DOCKER_TAG} - docker tag fxa-oauth-server:build ${DOCKERHUB_REPO}:${DOCKER_TAG} - docker images - docker push ${DOCKERHUB_REPO}:${DOCKER_TAG} - fi - -workflows: - version: 2 - - # workflow jobs are _not_ run in tag builds by default - # we use filters to whitelist jobs that should be run for tags - - # workflow jobs are run in _all_ branch builds by default - # we use filters to blacklist jobs that shouldn't be run for a branch - - # see: https://circleci.com/docs/2.0/workflows/#git-tag-job-execution - - build-test-push: - jobs: - - build: - filters: - tags: - only: /.*/ diff --git a/fxa-oauth-server/.travis.yml b/fxa-oauth-server/.travis.yml deleted file mode 100644 index 7cf1bcd60..000000000 --- a/fxa-oauth-server/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -language: node_js - -node_js: - - '8' - -dist: trusty -sudo: true - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 - - mysql-server-5.6 - - mysql-client-core-5.6 - - mysql-client-5.6 - -notifications: - email: - smcarthur@mozilla.com - jrgm@mozilla.com - irc: - channels: - - 'irc.mozilla.org#fxa-bots' - use_notice: false - skip_join: false - -env: - - CXX=g++-4.8 NODE_ENV=test DB=memory - - CXX=g++-4.8 NODE_ENV=test DB=mysql - -before_install: - - npm i -g npm@6 - - npm config set spin false - -before_script: - - "mysql -u root -NBe 'select version()'" - - "mysql -u root -e 'DROP DATABASE IF EXISTS fxa_oauth;'" - - "mysql -u root -e 'CREATE DATABASE fxa_oauth CHARACTER SET utf8 COLLATE utf8_unicode_ci;'" - -script: - - npm run outdated - - npm test - # HACK: ignore npm audit errors for now until we get them all fixed - - npm audit || true diff --git a/fxa-oauth-server/lib/routes/root.js b/fxa-oauth-server/lib/routes/root.js index 280937b5e..0c76bd929 100644 --- a/fxa-oauth-server/lib/routes/root.js +++ b/fxa-oauth-server/lib/routes/root.js @@ -34,7 +34,7 @@ module.exports = { function runGitCmd() { return new Promise((resolve) => { // figure it out from .git - var gitDir = path.resolve(__dirname, '..', '..', '.git'); + var gitDir = path.resolve(__dirname, '..', '..', '..', '.git'); exec('git rev-parse HEAD', { cwd: gitDir }, function(err, stdout) { commitHash = stdout.replace(/\s+/, ''); var configPath = path.join(gitDir, 'config');