Skip to content

Commit

Permalink
Fix some packaging issues.
Browse files Browse the repository at this point in the history
- Rework all the before/after install/remove scripts for the RPM and DEB
  packages so that upgrades and uninstalls are more properly handled.
  Most notably, upgrades of DEBs could lead to a broken installation
  with some missing symlinks for /usr/bin/api-umbrella. This also
  resolves a number of idiosyncrasies between how these scripts get
  called in different order and with different arguments depending on
  RPM vs DEB and upgrades vs fresh installs.
- Fix the "before-remove" script accidentally referencing the
  script intended for "after-remove".
- Fix the RPM packages leaving a bunch of empty directories in
  /opt/api-umbrella/embedded after uninstall.
- Add test coverage to our serverspec suite to actually test package
  uninstall, package purge (deb only), and the upgrade process between
  older versions of API Umbrella and the current version. These tests
  aren't fast, but given all the combinations of platforms and upgrade
  possibilities, this helps ensure we have a clean upgrade path when
  building new packages.
- Allow the "api-umbrella status" and "api-umbrella stop" commands to
  work properly against a legacy installation of the NodeJS app. This is
  needed so we can cleanly handle package upgrades.
- Better error handling for if you try to start api-umbrella when it's
  already started or stop api-umbrella when it's already stopped.
- Better error handling for the "run_command" function in case the shell
  gets killed early.
  • Loading branch information
GUI committed Dec 15, 2015
1 parent c7c8b8a commit 629dc34
Show file tree
Hide file tree
Showing 17 changed files with 839 additions and 270 deletions.
108 changes: 83 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ LUACHECK_VERSION:=0.11.1-1
test \
check_shared_objects \
download_deps \
download_verify_package_deps \
package \
verify_package \
package_docker_centos6 \
Expand Down Expand Up @@ -1125,47 +1126,104 @@ clean:
check_shared_objects:
find $(EMBEDDED_DIR) -type f | xargs ldd 2>&1 | grep " => " | grep -o "^[^(]*" | sort | uniq

$(DEPS_DIR)/verify_package/centos-6/api-umbrella-0.8.0-1.el6.x86_64.rpm:
mkdir -p $(shell dirname $@)
curl -L -o $@ http://sourceforge.net/projects/api-umbrella/files/el/6/api-umbrella-0.8.0-1.el6.x86_64.rpm/download

$(DEPS_DIR)/verify_package/centos-6/api-umbrella-0.9.0-1.el6.x86_64.rpm:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-el6/api-umbrella-0.9.0-1.el6.x86_64.rpm

$(DEPS_DIR)/verify_package/centos-7/api-umbrella-0.8.0-1.el7.x86_64.rpm:
mkdir -p $(shell dirname $@)
curl -L -o $@ http://sourceforge.net/projects/api-umbrella/files/el/7/api-umbrella-0.8.0-1.el7.x86_64.rpm/download

$(DEPS_DIR)/verify_package/centos-7/api-umbrella-0.9.0-1.el7.x86_64.rpm:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-el7/api-umbrella-0.9.0-1.el7.x86_64.rpm

$(DEPS_DIR)/verify_package/ubuntu-12.04/api-umbrella_0.8.0-1_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ http://sourceforge.net/projects/api-umbrella/files/ubuntu/12.04/api-umbrella_0.8.0-1_amd64.deb/download

$(DEPS_DIR)/verify_package/ubuntu-12.04/api-umbrella_0.9.0-1~precise_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-ubuntu/pool/main/a/api-umbrella/api-umbrella_0.9.0-1%7Eprecise_amd64.deb

$(DEPS_DIR)/verify_package/ubuntu-14.04/api-umbrella_0.8.0-1_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ http://sourceforge.net/projects/api-umbrella/files/ubuntu/14.04/api-umbrella_0.8.0-1_amd64.deb/download

$(DEPS_DIR)/verify_package/ubuntu-14.04/api-umbrella_0.9.0-1~trusty_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-ubuntu/pool/main/a/api-umbrella/api-umbrella_0.9.0-1%7Etrusty_amd64.deb

$(DEPS_DIR)/verify_package/debian-7/api-umbrella_0.8.0-1_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ http://sourceforge.net/projects/api-umbrella/files/debian/7/api-umbrella_0.8.0-1_amd64.deb/download

$(DEPS_DIR)/verify_package/debian-7/api-umbrella_0.9.0-1~wheezy_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-debian/pool/main/a/api-umbrella/api-umbrella_0.9.0-1%7Ewheezy_amd64.deb

$(DEPS_DIR)/verify_package/debian-8/api-umbrella_0.9.0-1~jessie_amd64.deb:
mkdir -p $(shell dirname $@)
curl -L -o $@ https://bintray.com/artifact/download/nrel/api-umbrella-debian/pool/main/a/api-umbrella/api-umbrella_0.9.0-1%7Ejessie_amd64.deb

download_verify_package_deps: \
$(DEPS_DIR)/verify_package/centos-6/api-umbrella-0.8.0-1.el6.x86_64.rpm \
$(DEPS_DIR)/verify_package/centos-6/api-umbrella-0.9.0-1.el6.x86_64.rpm \
$(DEPS_DIR)/verify_package/centos-7/api-umbrella-0.8.0-1.el7.x86_64.rpm \
$(DEPS_DIR)/verify_package/centos-7/api-umbrella-0.9.0-1.el7.x86_64.rpm \
$(DEPS_DIR)/verify_package/ubuntu-12.04/api-umbrella_0.8.0-1_amd64.deb \
$(DEPS_DIR)/verify_package/ubuntu-12.04/api-umbrella_0.9.0-1~precise_amd64.deb \
$(DEPS_DIR)/verify_package/ubuntu-14.04/api-umbrella_0.8.0-1_amd64.deb \
$(DEPS_DIR)/verify_package/ubuntu-14.04/api-umbrella_0.9.0-1~trusty_amd64.deb \
$(DEPS_DIR)/verify_package/debian-7/api-umbrella_0.8.0-1_amd64.deb \
$(DEPS_DIR)/verify_package/debian-7/api-umbrella_0.9.0-1~wheezy_amd64.deb \
$(DEPS_DIR)/verify_package/debian-8/api-umbrella_0.9.0-1~jessie_amd64.deb

package:
$(BUILD_DIR)/package/build

verify_package:
verify_package: download_verify_package_deps
$(BUILD_DIR)/verify_package/run

package_docker_centos6: download_deps
DIST=centos:6 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_centos6: download_deps download_verify_package_deps
DIST=centos-6 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_centos6: download_deps
DIST=centos:6 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_centos6: download_deps download_verify_package_deps
DIST=centos-6 $(BUILD_DIR)/verify_package/run_with_docker

package_docker_centos7: download_deps
DIST=centos:7 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_centos7: download_deps download_verify_package_deps
DIST=centos-7 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_centos7: download_deps
DIST=centos:7 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_centos7: download_deps download_verify_package_deps
DIST=centos-7 $(BUILD_DIR)/verify_package/run_with_docker

package_docker_ubuntu1204: download_deps
DIST=ubuntu:12.04 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_ubuntu1204: download_deps download_verify_package_deps
DIST=ubuntu-12.04 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_ubuntu1204: download_deps
DIST=ubuntu:12.04 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_ubuntu1204: download_deps download_verify_package_deps
DIST=ubuntu-12.04 $(BUILD_DIR)/verify_package/run_with_docker

package_docker_ubuntu1404: download_deps
DIST=ubuntu:14.04 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_ubuntu1404: download_deps download_verify_package_deps
DIST=ubuntu-14.04 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_ubuntu1404: download_deps
DIST=ubuntu:14.04 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_ubuntu1404: download_deps download_verify_package_deps
DIST=ubuntu-14.04 $(BUILD_DIR)/verify_package/run_with_docker

package_docker_debian7: download_deps
DIST=debian:7 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_debian7: download_deps download_verify_package_deps
DIST=debian-7 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_debian7: download_deps
DIST=debian:7 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_debian7: download_deps download_verify_package_deps
DIST=debian-7 $(BUILD_DIR)/verify_package/run_with_docker

package_docker_debian8: download_deps
DIST=debian:8 $(BUILD_DIR)/package/build_and_verify_with_docker
package_docker_debian8: download_deps download_verify_package_deps
DIST=debian-8 $(BUILD_DIR)/package/build_and_verify_with_docker

verify_package_docker_debian8: download_deps
DIST=debian:8 $(BUILD_DIR)/verify_package/run_with_docker
verify_package_docker_debian8: download_deps download_verify_package_deps
DIST=debian-8 $(BUILD_DIR)/verify_package/run_with_docker

all_packages: \
download_deps \
Expand Down
18 changes: 11 additions & 7 deletions build/package/build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ else
ITERATION="0.1.$PRE"
fi

FPM_ARGS=""
FPM_ARGS=()

if command -v yum &> /dev/null; then
PACKAGE_TYPE="rpm"
Expand Down Expand Up @@ -71,7 +71,8 @@ if command -v yum &> /dev/null; then
xz
)
RPM_DIST=$(rpm --query centos-release | grep -o "el[0-9]")
FPM_ARGS="$FPM_ARGS --rpm-dist $RPM_DIST --rpm-compression xz"
FPM_ARGS+=("--rpm-dist" "$RPM_DIST")
FPM_ARGS+=("--rpm-compression" "xz")

if [ "$RPM_DIST" == "el6" ]; then
if [ ! -f /etc/yum.repos.d/wandisco-git.repo ]; then
Expand Down Expand Up @@ -130,9 +131,10 @@ elif command -v dpkg &> /dev/null; then
unzip
xz-utils
)
FPM_ARGS="$FPM_ARGS --deb-compression xz"
FPM_ARGS+=("--deb-compression" "xz")
FPM_ARGS+=("--deb-no-default-config-files")

if [ "$DIST" == "debian:7" ]; then
if [ "$DIST" == "debian-7" ]; then
PACKAGE_DEPENDENCIES+=("libffi5")
else
PACKAGE_DEPENDENCIES+=("libffi6")
Expand Down Expand Up @@ -174,7 +176,7 @@ cd $TMP_ROOT_DIR
make install DESTDIR=$TMP_WORK_DIR/package/root

for DEP in "${PACKAGE_DEPENDENCIES[@]}"; do
FPM_ARGS="$FPM_ARGS -d $DEP"
FPM_ARGS+=("-d" "$DEP")
done

# Use FPM to build the binary package.
Expand All @@ -195,9 +197,11 @@ bundle exec fpm \
--iteration "$ITERATION" \
--config-files etc/api-umbrella/api-umbrella.yml \
--after-install $TMP_ROOT_DIR/build/package/scripts/after-install \
--before-remove $TMP_ROOT_DIR/build/package/scripts/after-remove \
--before-remove $TMP_ROOT_DIR/build/package/scripts/before-remove \
--after-remove $TMP_ROOT_DIR/build/package/scripts/after-remove \
$FPM_ARGS \
--directories /etc/api-umbrella \
--directories /opt/api-umbrella \
${FPM_ARGS[*]} \
.

rm -rf $ORIGINAL_ROOT_DIR/build/package/dist/$DIST
Expand Down
2 changes: 1 addition & 1 deletion build/package/build_and_verify_with_docker
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e -u -x

ROOT_DIR="$(dirname $(dirname $(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)))"
DOCKER_IMAGE=$DIST
DOCKER_IMAGE=${DIST/-/:}
CONTAINER_NAME="api-umbrella-package-$DIST"
CONTAINER_NAME=${CONTAINER_NAME//[^a-zA-Z0-9_.-]/}

Expand Down
7 changes: 6 additions & 1 deletion build/package/files/etc/init.d/api-umbrella
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ status() {
return $RETVAL
}

status_quiet() {
status > /dev/null 2>&1
}

case "$1" in
start)
start
Expand All @@ -131,7 +135,8 @@ case "$1" in
reload
;;
condrestart)
status > /dev/null 2>&1 && restart || :
status_quiet || exit 0
restart
;;
*)
echo "Usage: $NAME {start|stop|status|reload|restart|condrestart}"
Expand Down
12 changes: 6 additions & 6 deletions build/package/publish
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ else
fi

PACKAGES=(
build/package/dist/centos:6/api-umbrella-$VERSION-$ITERATION.el6.x86_64.rpm
build/package/dist/centos:7/api-umbrella-$VERSION-$ITERATION.el7.x86_64.rpm
build/package/dist/debian:7/api-umbrella_$VERSION-$ITERATION~wheezy_amd64.deb
build/package/dist/debian:8/api-umbrella_$VERSION-$ITERATION~jessie_amd64.deb
build/package/dist/ubuntu:12.04/api-umbrella_$VERSION-$ITERATION~precise_amd64.deb
build/package/dist/ubuntu:14.04/api-umbrella_$VERSION-$ITERATION~trusty_amd64.deb
build/package/dist/centos-6/api-umbrella-$VERSION-$ITERATION.el6.x86_64.rpm
build/package/dist/centos-7/api-umbrella-$VERSION-$ITERATION.el7.x86_64.rpm
build/package/dist/debian-7/api-umbrella_$VERSION-$ITERATION~wheezy_amd64.deb
build/package/dist/debian-8/api-umbrella_$VERSION-$ITERATION~jessie_amd64.deb
build/package/dist/ubuntu-12.04/api-umbrella_$VERSION-$ITERATION~precise_amd64.deb
build/package/dist/ubuntu-14.04/api-umbrella_$VERSION-$ITERATION~trusty_amd64.deb
)

for PACKAGE in "${PACKAGES[@]}"; do
Expand Down
Loading

0 comments on commit 629dc34

Please sign in to comment.