Skip to content

Commit

Permalink
Configure deploy step
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Oct 27, 2017
1 parent e9a1275 commit 90e7847
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 3 deletions.
38 changes: 35 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- restore_cache:
keys:
- v1-meteor-{{ checksum ".meteor/release" }}
- v2-meteor-{{ checksum ".meteor/release" }}

- run:
name: Install Meteor
Expand Down Expand Up @@ -51,6 +51,7 @@ jobs:
- run:
name: Build Rocket.Chat
command: |
if [[ $CIRCLE_TAG ]]; then meteor reset; fi
set +e
meteor add rocketchat:lib
set -e
Expand All @@ -59,6 +60,9 @@ jobs:
- 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
Expand All @@ -83,15 +87,15 @@ jobs:
- ./packages/rocketchat-livechat/app/.meteor/local

- save_cache:
key: v1-meteor-{{ checksum ".meteor/release" }}
key: v2-meteor-{{ checksum ".meteor/release" }}
paths:
- /home/circleci/.meteor
- /usr/local/bin/meteor

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

test-with-oplog:
<<: *defaults
Expand Down Expand Up @@ -179,6 +183,30 @@ jobs:
command: |
npm test
deploy:
<<: *defaults
machine:
enabled: true

steps:
- checkout

- run: |
aws
if [[ $CIRCLE_PULL_REQUESTS ]]; then exit 0; fi;
source .circleci/setartname.sh
source .circleci/setdeploydir.sh
bash .circleci/setupsig.sh
bash .circleci/namefiles.sh
echo ".circleci/sandstorm.sh"
aws s3 sync $ROCKET_DEPLOY_DIR/ s3://download.rocket.chat/
bash .circleci/docker.sh
bash .circleci/update-releases.sh
bash .circleci/snap.sh
workflows:
version: 2
build-and-test:
Expand All @@ -190,3 +218,7 @@ workflows:
- test-without-oplog:
requires:
- build
- deploy:
requires:
- test-with-oplog
- test-without-oplog
15 changes: 15 additions & 0 deletions .circleci/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -x
set -euvo pipefail
IFS=$'\n\t'

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

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"
9 changes: 9 additions & 0 deletions .circleci/namefiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -x
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"
6 changes: 6 additions & 0 deletions .circleci/setartname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if [[ $CIRCLE_TAG ]]
then
export ARTIFACT_NAME="$(meteor npm run version --silent)"
else
export ARTIFACT_NAME="$(meteor npm run version --silent).$CIRCLE_BUILD_NUM"
fi
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
9 changes: 9 additions & 0 deletions .circleci/setupsig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -x
set -euvo pipefail
IFS=$'\n\t'

cp .circleci/sign.key.gpg /tmp
gpg --yes --batch --passphrase=$mypass /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.
54 changes: 54 additions & 0 deletions .circleci/snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -euvo pipefail
IFS=$'\n\t'

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

git config user.name "CI Bot"
git config user.email "[email protected]"

# Determine the channel to push snap to.
if [[ $CIRCLE_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]]; then
CHANNEL=candidate
RC_VERSION=$CIRCLE_TAG
elif [[ $CIRCLE_TAG ]]; then
CHANNEL=stable
RC_VERSION=$CIRCLE_TAG
else
CHANNEL=edge
RC_VERSION=0.59.0-develop
fi

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

cd $PWD/.snapcraft

# Decrypt key
openssl aes-256-cbc -K $encrypted_f5c8ae370556_key -iv $encrypted_f5c8ae370556_iv -in launchpadkey.enc -out launchpadkey -d

# Change permissions
chmod 0600 launchpadkey

# We need some meta data so it'll actually commit. This could be useful to have for debugging later.
echo "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_SSH_COMMAND="ssh -i launchpadkey" git clone -b $CHANNEL git+ssh://[email protected]/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

cd launchpad
git add resources snapcraft.yaml buildinfo

# 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_SSH_COMMAND="ssh -i ../launchpadkey" git push origin $CHANNEL

# Clean up
cd ..
rm -rf launchpadkey launchpad
8 changes: 8 additions & 0 deletions .circleci/update-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -x
set -euvo pipefail
IFS=$'\n\t'

CURL_URL="https://rocket.chat/releases/update"

curl -X POST "$CURL_URL"

0 comments on commit 90e7847

Please sign in to comment.