Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Automated package testing (#179)
Browse files Browse the repository at this point in the history
* Pin Travis distribution to Ubuntu 18.04

* Add Heroku and CF CLI dependencies to Travis build

* Attempt to install Heroku CLI during install phase

* Force the issue

* Remove failing install attempt

* Do the quick thing first

* First attempt at automating Heroku deploy and upgrade in pipeline

* Use Heroku credentials from encrypted file

* Attempt to reencrypt file

* Move the decrypt command

* Reencrypt against correct repo

* Shorten application names (max 30 chars on Heroku)

* Use a long-lived token

Also unset the HEROKU_API_KEY in Travis, not part of the code.

* Add automated CF option

* Ensure package.zip exists if not explicitly skipped

* Remove redundant API URL from CF deploy

* It's all relative

* Test package on before_deploy

* Re-encrypt Heroku credentials for pivotal/postfacto repo
  • Loading branch information
textbook authored and Brian Butz committed Aug 13, 2019
1 parent 1b8ccb9 commit b09ea2f
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package.zip
node_modules/
docker_node_modules/
*.log
.heroku-netrc
Binary file added .heroku-netrc.enc
Binary file not shown.
21 changes: 19 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
language: minimal
dist: bionic

addons:
apt:
sources:
- sourceline: 'deb https://packages.cloudfoundry.org/debian stable main'
key_url: 'https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key'
packages:
- cf-cli
services:
- docker
- docker

script:
- docker run -v "$TRAVIS_BUILD_DIR":/postfacto postfacto/dev:2.6.3-12.6.0 /bin/bash -c "cd /postfacto && npm config set user 0 && npm config set unsafe-perm true && ./deps.sh && EPHEMERAL_CONTAINER=true ./test.sh && ./package.sh"
- docker run -v "$TRAVIS_BUILD_DIR":/postfacto postfacto/dev:2.6.3-12.6.0 /bin/bash -c "cd /postfacto && npm config set user 0 && npm config set unsafe-perm true && ./deps.sh && EPHEMERAL_CONTAINER=true ./test.sh && ./package.sh"

before_deploy:
- openssl aes-256-cbc -K $encrypted_5e88d222d606_key -iv $encrypted_5e88d222d606_iv -in .heroku-netrc.enc -out .heroku-netrc -d
- cat .heroku-netrc >> $HOME/.netrc
- cf login -a $CF_ENDPOINT -u $CF_USERNAME -p $CF_PASSWORD
- ./test-package.sh --skip-package

deploy:
provider: releases
draft: true
Expand Down
150 changes: 150 additions & 0 deletions test-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#! /bin/bash
#
# Postfacto, a free, open-source and self-hosted retro tool aimed at helping
# remote teams.
#
# Copyright (C) 2016 - Present Pivotal Software, Inc.
#
# This program is free software: you can redistribute it and/or modify
#
# it under the terms of the GNU Affero General Public License as
#
# published by the Free Software Foundation, either version 3 of the
#
# License, or (at your option) any later version.
#
#
#
# This program is distributed in the hope that it will be useful,
#
# but WITHOUT ANY WARRANTY; without even the implied warranty of
#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#
# GNU Affero General Public License for more details.
#
#
#
# You should have received a copy of the GNU Affero General Public License
#
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

if [[ ! $* =~ --skip-package ]];
then
"$SCRIPT_DIR/package.sh"
fi

if [[ ! $* =~ --skip-heroku ]];
then
heroku whoami \
|| (echo 'You need to have the Heroku CLI installed and be logged in' \
&& exit 1)
fi

if [[ ! $* =~ --skip-cf ]];
then
cf target \
|| (echo 'You need to have the CF CLI installed and be logged in' \
&& exit 1)
fi

curl -L -o "$SCRIPT_DIR/last-release.zip" 'https://github.com/pivotal/postfacto/releases/latest/download/package.zip'
unzip "$SCRIPT_DIR/package.zip"
unzip "$SCRIPT_DIR/last-release.zip" -d "$SCRIPT_DIR/last-release"
echo 'Setup complete'

NOW=$(date +%s)

OLD_WEB="postfacto-old-web-${NOW}"
OLD_API="postfacto-old-api-${NOW}"
NEW_WEB="postfacto-new-web-${NOW}"
NEW_API="postfacto-new-api-${NOW}"

if [[ ! $* =~ --skip-cf ]];
then
echo '####### Cloud Foundry'

SPACE="postfacto-space-${NOW}"

cf create-space $SPACE
cf target -s $SPACE

cf create-service \
${REDIS_SERVICE:-'p-redis'} \
${REDIS_PLAN:-'shared-vm'} \
postfacto-redis

cf create-service \
${DB_SERVICE:-'p.mysql'} \
${DB_PLAN:-'db-small'} \
postfacto-db

while [[ $(cf services) =~ 'create in progress' ]];
do
echo 'Service creation in progress'
sleep 5
done

pushd "$SCRIPT_DIR/last-release/package/pcf"
echo 'Deploying old version to Cloud Foundry'
./deploy.sh $OLD_WEB $OLD_API 'apps.pcfone.io'
popd

pushd "$SCRIPT_DIR/package/pcf"
echo 'Upgrading old version on Cloud Foundry'
./upgrade.sh $OLD_WEB $OLD_API 'apps.pcfone.io'

echo 'Deploying new version to Cloud Foundry'
./deploy.sh $NEW_WEB $NEW_API 'apps.pcfone.io'
popd

echo 'Cleaning up Cloud Foundry'
for APP in $OLD_WEB $OLD_API $NEW_WEB $NEW_API
do
cf delete $APP -f -r
done

for SERVICE in 'postfacto-redis' 'postfacto-db'
do
cf delete-service $SERVICE -f
done

while [[ $(cf services) =~ 'delete in progress' ]];
do
echo 'Service deletion in progress'
sleep 5
done

cf delete-space $SPACE -f
fi

if [[ ! $* =~ --skip-heroku ]];
then
echo '####### Heroku'

pushd "$SCRIPT_DIR/last-release/package/heroku"
echo 'Deploying old version to Heroku'
./deploy.sh $OLD_WEB $OLD_API
popd

pushd "$SCRIPT_DIR/package/heroku"
echo 'Upgrading old version on Heroku'
./upgrade.sh $OLD_WEB $OLD_API

echo 'Deploying new version to Heroku'
./deploy.sh $NEW_WEB $NEW_API
popd

echo 'Cleaning up Heroku'
for APP in $OLD_WEB $OLD_API $NEW_WEB $NEW_API
do
heroku apps:delete -a $APP -c $APP
done
fi

echo 'Cleaning up working directory'
rm -rf "$SCRIPT_DIR/last-release" "$SCRIPT_DIR/last-release.zip" "$SCRIPT_DIR/package"

0 comments on commit b09ea2f

Please sign in to comment.