Skip to content

Commit

Permalink
Merge pull request #1 from RocketChat/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
myfonj committed Jun 7, 2018
2 parents 1418bb6 + 44548c5 commit d408337
Show file tree
Hide file tree
Showing 2,597 changed files with 233,823 additions and 70,700 deletions.
281 changes: 281 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
defaults: &defaults
working_directory: ~/repo

version: 2
jobs:
build:
<<: *defaults
docker:
- image: circleci/node:8.9

steps:
- checkout

# - restore_cache:
# keys:
# - node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}

# - restore_cache:
# keys:
# - meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}

- run:
name: Install Meteor
command: |
# Restore bin from cache
set +e
METEOR_SYMLINK_TARGET=$(readlink ~/.meteor/meteor)
METEOR_TOOL_DIRECTORY=$(dirname "$METEOR_SYMLINK_TARGET")
set -e
LAUNCHER=$HOME/.meteor/$METEOR_TOOL_DIRECTORY/scripts/admin/launch-meteor
if [ -e $LAUNCHER ]
then
echo "Cached Meteor bin found, restoring it"
sudo cp "$LAUNCHER" "/usr/local/bin/meteor"
else
echo "No cached Meteor bin found."
fi
# only install meteor if bin isn't found
command -v meteor >/dev/null 2>&1 || curl https://install.meteor.com | sed s/--progress-bar/-sL/g | /bin/sh
- run:
name: Versions
command: |
npm --versions
node -v
meteor --version
meteor npm --versions
meteor node -v
git version
- run:
name: Meteor npm install
command: |
# rm -rf node_modules
# rm -f package-lock.json
meteor npm install
- run:
name: Lint
command: |
meteor npm run lint
meteor npm run stylelint
- run:
name: Unit Test
command: |
meteor npm run testunit
# - restore_cache:
# keys:
# - meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}

# - restore_cache:
# keys:
# - livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}

# - restore_cache:
# keys:
# - livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}

- run:
name: Build Rocket.Chat
command: |
if [[ $CIRCLE_TAG ]]; then meteor reset; fi
set +e
meteor add rocketchat:lib
set -e
meteor build --server-only --directory /tmp/build-test
- run:
name: Prepare build
command: |
mkdir /tmp/build/
cd /tmp/build-test
tar czf /tmp/build/Rocket.Chat.tar.gz bundle
cd /tmp/build-test/bundle/programs/server
npm install
# - save_cache:
# key: node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "package.json" }}
# paths:
# - ./node_modules

# - save_cache:
# key: meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/versions" }}
# paths:
# - ./.meteor/local

# - save_cache:
# key: livechat-node-modules-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/package.json" }}
# paths:
# - ./packages/rocketchat-livechat/app/node_modules

# - save_cache:
# key: livechat-meteor-cache-{{ checksum ".circleci/config.yml" }}-{{ checksum "packages/rocketchat-livechat/app/.meteor/versions" }}
# paths:
# - ./packages/rocketchat-livechat/app/.meteor/local

# - save_cache:
# key: meteor-{{ checksum ".circleci/config.yml" }}-{{ checksum ".meteor/release" }}
# paths:
# - ~/.meteor

- persist_to_workspace:
root: /tmp/
paths:
- build-test
- build

- store_artifacts:
path: /tmp/build

test-with-oplog:
<<: *defaults
docker:
- image: circleci/node:8.9-browsers
- image: mongo:3.4
command: [mongod, --nojournal, --noprealloc, --smallfiles, --replSet=rs0]

environment:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/testwithoplog
MONGO_OPLOG_URL: mongodb://localhost:27017/local

steps:
- attach_workspace:
at: /tmp

- checkout

- run:
name: Install dependencies
command: |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org-shell
- run:
name: Configure Replica Set
command: |
mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"}]})'
mongo --eval 'rs.status()'
- run:
name: NPM install
command: |
npm install
- run:
name: Run Tests
command: |
for i in $(seq 1 5); do npm test && s=0 && break || s=$? && sleep 1; done; (exit $s)
- store_artifacts:
path: .screenshots/

test-without-oplog:
<<: *defaults
docker:
- image: circleci/node:8.9-browsers
- image: circleci/mongo:3.4

environment:
TEST_MODE: "true"
MONGO_URL: mongodb://localhost:27017/testwithoplog

steps:
- attach_workspace:
at: /tmp

- checkout

- run:
name: NPM install
command: |
npm install
- run:
name: Run Tests
command: |
for i in $(seq 1 5); do npm test && s=0 && break || s=$? && sleep 1; done; (exit $s)
- store_artifacts:
path: .screenshots/

deploy:
<<: *defaults
docker:
- image: circleci/node:8.9

steps:
- attach_workspace:
at: /tmp

- checkout

- run:
name: Install AWS cli
command: |
if [[ $CIRCLE_PULL_REQUESTS ]]; then exit 0; fi;
sudo apt-get -y -qq update
sudo apt-get -y -qq install python3.4-dev
curl -O https://bootstrap.pypa.io/get-pip.py
python3.4 get-pip.py --user
export PATH=~/.local/bin:$PATH
pip install awscli --upgrade --user
- run:
name: Publish assets
command: |
if [[ $CIRCLE_PULL_REQUESTS ]]; then exit 0; fi;
export PATH=~/.local/bin:$PATH
export CIRCLE_TAG=${CIRCLE_TAG:=}
source .circleci/setartname.sh
source .circleci/setdeploydir.sh
bash .circleci/setupsig.sh
bash .circleci/namefiles.sh
# echo ".circleci/sandstorm.sh"
aws s3 cp $ROCKET_DEPLOY_DIR/ s3://download.rocket.chat/build/ --recursive
bash .circleci/update-releases.sh
bash .circleci/docker.sh
bash .circleci/snap.sh
bash .circleci/redhat-registry.sh
workflows:
version: 2
build-and-test:
jobs:
- build:
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
- test-with-oplog:
requires:
- build
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
- test-without-oplog:
requires:
- build
filters:
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/
- deploy:
requires:
- test-with-oplog
- test-without-oplog
filters:
branches:
only: develop
tags:
only: /^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$/

13 changes: 13 additions & 0 deletions .circleci/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

CURL_URL="https://registry.hub.docker.com/u/rocketchat/rocket.chat/trigger/$DOCKER_TRIGGER_TOKEN/"

if [[ $CIRCLE_TAG ]]; then
CURL_DATA='{"source_type":"Tag","source_name":"'"$CIRCLE_TAG"'"}';
else
CURL_DATA='{"source_type":"Branch","source_name":"'"$CIRCLE_BRANCH"'"}';
fi

curl -H "Content-Type: application/json" --data "$CURL_DATA" -X POST "$CURL_URL"
8 changes: 8 additions & 0 deletions .circleci/namefiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

FILENAME="$ROCKET_DEPLOY_DIR/rocket.chat-$ARTIFACT_NAME.tgz";

ln -s /tmp/build/Rocket.Chat.tar.gz "$FILENAME"
gpg --armor --detach-sign "$FILENAME"
12 changes: 12 additions & 0 deletions .circleci/redhat-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

if [[ $CIRCLE_TAG ]]; then
curl -X POST \
https://connect.redhat.com/api/v2/projects/$REDHAT_REGISTRY_PID/build \
-H "Authorization: Bearer $REDHAT_REGISTRY_KEY" \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{"tag":"'$CIRCLE_TAG'"}'
fi
23 changes: 23 additions & 0 deletions .circleci/setartname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if [[ $CIRCLE_TAG ]]; then
export ARTIFACT_NAME="$(npm run version --silent)"
else
export ARTIFACT_NAME="$(npm run version --silent).$CIRCLE_BUILD_NUM"
fi

if [[ $CIRCLE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]]; then
SNAP_CHANNEL=candidate
RC_RELEASE=candidate
RC_VERSION=$CIRCLE_TAG
elif [[ $CIRCLE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
SNAP_CHANNEL=stable
RC_RELEASE=stable
RC_VERSION=$CIRCLE_TAG
else
SNAP_CHANNEL=edge
RC_RELEASE=develop
RC_VERSION=0.60.0-develop
fi

export SNAP_CHANNEL
export RC_RELEASE
export RC_VERSION
2 changes: 2 additions & 0 deletions .circleci/setdeploydir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ROCKET_DEPLOY_DIR="/tmp/deploy"
mkdir -p $ROCKET_DEPLOY_DIR
8 changes: 8 additions & 0 deletions .circleci/setupsig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

cp .circleci/sign.key.gpg /tmp
gpg --yes --batch --passphrase=$GPG_PASSWORD /tmp/sign.key.gpg
gpg --allow-secret-key-import --import /tmp/sign.key
rm /tmp/sign.key
Binary file added .circleci/sign.key.gpg
Binary file not shown.
38 changes: 38 additions & 0 deletions .circleci/snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

# Add launchpad to known hosts
ssh-keyscan -t rsa -H git.launchpad.net > ~/.ssh/known_hosts

echo "Preparing to trigger a snap release for $SNAP_CHANNEL channel"

cd $PWD/.snapcraft

# We need some meta data so it'll actually commit. This could be useful to have for debugging later.
echo -e "Tag: $CIRCLE_TAG\r\nBranch: $CIRCLE_BRANCH\r\nBuild: $CIRCLE_BUILD_NUM\r\nCommit: $CIRCLE_SHA1" > buildinfo

# Clone launchpad repo for the channel down.
git clone -b $SNAP_CHANNEL git+ssh://rocket.chat.buildmaster@git.launchpad.net/rocket.chat launchpad

# Rarely will change, but just incase we copy it all
cp -r resources buildinfo launchpad/
sed s/#{RC_VERSION}/$RC_VERSION/ snapcraft.yaml > launchpad/snapcraft.yaml
sed s/#{RC_VERSION}/$RC_VERSION/ resources/prepareRocketChat > launchpad/resources/prepareRocketChat

cd launchpad
git add resources snapcraft.yaml buildinfo

# Set commit author details
git config user.email "buildmaster@rocket.chat"
git config user.name "CircleCI"

# Another place where basic meta data will live for at a glance info
git commit -m "CircleCI Build: $CIRCLE_BUILD_NUM CircleCI Commit: $CIRCLE_SHA1"

# Push up up to the branch of choice.
git push origin $SNAP_CHANNEL

# Clean up
cd ..
rm -rf launchpad
Loading

0 comments on commit d408337

Please sign in to comment.