Skip to content

Commit

Permalink
Merge 560f779 into 152bac3
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg committed Nov 9, 2017
2 parents 152bac3 + 560f779 commit 0727038
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 70 deletions.
19 changes: 3 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@ sudo: false
go:
- 1.9.1
install:
- go get -v github.com/Masterminds/glide
- cd $GOPATH/src/github.com/Masterminds/glide && git checkout v0.12.3 && go install
&& cd -
- go get -v github.com/mitchellh/gox
- cd $GOPATH/src/github.com/mitchellh/gox && git checkout v0.3.0 && go install &&
cd -
- glide install
- gem install --no-ri --no-rdoc fpm
- make install-fpm
script:
- go test -short -v $(glide novendor)
- CGO_ENABLED=0 gox -osarch "linux/386 linux/amd64 darwin/amd64 windows/386 windows/amd64" -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}"
-ldflags="-X github.com/racker/rackspace-monitoring-poller/version.Version=$(git
symbolic-ref -q --short HEAD || git describe --tags --exact-match)"
- go test -v github.com/racker/rackspace-monitoring-poller/integrationcli
- make package-deb-local
- make test build test-integrationcli package-debs-local
after_script:
- go get github.com/mattn/goveralls
- bash contrib/combine-coverage.sh --coveralls
- make coverage
deploy:
provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
Expand Down
161 changes: 121 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ SRC_DIR := pkg
GENERIC_SRC_DIR := ${SRC_DIR}/generic
DEB_SRC_DIR := ${SRC_DIR}/debian
DEB_REPO_DIR := ${DEB_SRC_DIR}/repo
CLOUDFILES_REPO_NAME := poller-$(GIT_TAG)
BUILD_DIR := build
BUILD_REPOS_DIR := build/repos
DEB_BUILD_DIR := ${BUILD_DIR}/debian
EXE := rackspace-monitoring-poller
APP_NAME := rackspace-monitoring-poller

CLOUDFILES_REPO_NAME := poller-$(GIT_TAG)
# switching new, per-distro repos to all be organized under a consolidated swift container `poller-repos`
# ...a container per version is unweildy especially in the MyCloud UI
CF_POLLER_CONTAINER := poller-repos
RCLONE_ARGS :=

PROJECT_VENDOR := github.com/racker/rackspace-monitoring-poller/vendor

PKGDIR_BIN := usr/bin
Expand All @@ -21,29 +28,33 @@ BIN_URL := https://github.com/racker/rackspace-monitoring-poller/releases/downlo
VENDOR := Rackspace US, Inc.
LICENSE := Apache v2

PKG_DEB := ${BUILD_DIR}/${APP_NAME}_${GIT_TAG}-${TAG_DISTANCE}_${ARCH}.deb

# TODO: should poller get its own specific file?
APP_CFG := ${PKGDIR_ETC}/rackspace-monitoring-poller.cfg
SYSTEMD_CONF := ${PKGDIR_ETC}/init/${APP_NAME}
UPSTART_CONF := ${PKGDIR_ETC}/init/${APP_NAME}.conf
SYSTEMD_CONF := lib/systemd/system/${APP_NAME}.service
UPSTART_CONF := ${PKGDIR_ETC}/init/${APP_NAME}
UPSTART_DEFAULT := ${PKGDIR_ETC}/default/${APP_NAME}
LOGROTATE_CFG := ${PKGDIR_ETC}/logrotate.d/${APP_NAME}

OWNED_DIRS :=
DEB_CONFIG_FILES := ${APP_CFG} ${LOGROTATE_CFG}
DEB_ALL_FILES := ${DEB_CONFIG_FILES} ${UPSTART_CONF} ${UPSTART_DEFAULT} ${SYSTEMD_CONF}

PKG_VERSION := ${GIT_TAG}-${TAG_DISTANCE}
PKG_BASE := ${APP_NAME}_${PKG_VERSION}_${ARCH}
FPM_IDENTIFIERS := -n ${APP_NAME} --license "${LICENSE}" --vendor "${VENDOR}" \
-v ${GIT_TAG} --iteration ${TAG_DISTANCE}

ifdef DONT_SIGN
SED_DISTRIBUTIONS = -e "/SignWith/ d" -e "p"
else
SED_DISTRIBUTIONS = -e "p"
endif

MOCK_POLLER := LogPrefixGetter,ConnectionStream,Connection,Session,CheckScheduler,CheckExecutor,Scheduler,ChecksReconciler

WGET := wget
FPM := fpm
REPREPRO := reprepro

.PHONY: default repackage package package-deb package-repo-upload package-upload-deb package-deb-local \
clean generate-mocks stage-deb-exe-local prep \
generate-callgraphs regenerate-callgraphs clean-callgraphs

default: clean package

generate-mocks:
Expand All @@ -53,10 +64,35 @@ generate-mocks:
sed -i '' s,$(PROJECT_VENDOR)/,, check/pinger_mock_test.go
mockgen -destination mock_golang/mock_conn.go -package mock_golang net Conn

prep:
curl https://glide.sh/get | sh
test: vendor
go test -short -v $(shell glide novendor)

test-integrationcli: build
go test -v github.com/racker/rackspace-monitoring-poller/integrationcli

build: ${GOPATH}/bin/gox vendor
CGO_ENABLED=0 ${GOPATH}/bin/gox \
-osarch "linux/386 linux/amd64 darwin/amd64 windows/386 windows/amd64" \
-output="${BUILD_DIR}/{{.Dir}}_{{.OS}}_{{.Arch}}"

coverage: ${GOPATH}/bin/goveralls
contrib/combine-coverage.sh --coveralls

vendor: ${GOPATH}/bin/glide glide.yaml glide.lock
${GOPATH}/bin/glide install

install-fpm:
gem install --no-ri --no-rdoc fpm

${GOPATH}/bin/glide :
curl https://glide.sh/get | sh

${GOPATH}/bin/gox :
go get -v github.com/mitchellh/gox

${GOPATH}/bin/goveralls :
go get -v github.com/mattn/goveralls

regenerate-callgraphs : clean-callgraphs generate-callgraphs

generate-callgraphs : docs/poller_callgraph.png docs/endpoint_callgraph.png
Expand All @@ -73,60 +109,105 @@ clean-callgraphs :
${GOPATH}/bin/go-callvis :
go get -u github.com/TrueFurby/go-callvis

package: package-deb
package: package-debs

package-repo-upload: package-deb reprepro-deb package-upload-deb
package-repo-upload: package reprepro-debs package-upload-deb

package-upload-deb:
rclone mkdir rackspace:${CLOUDFILES_REPO_NAME}/debian
rclone copy ${DEB_REPO_DIR}/ rackspace:${CLOUDFILES_REPO_NAME}/debian
rclone ${RCLONE_ARGS} mkdir rackspace:${CF_POLLER_CONTAINER}/${GIT_TAG}
rclone ${RCLONE_ARGS} copy ${BUILD_REPOS_DIR} rackspace:${CF_POLLER_CONTAINER}/${GIT_TAG}
# retain "old" structure to enable incrementally converting over the repo web servicing
rclone ${RCLONE_ARGS} mkdir rackspace:${CLOUDFILES_REPO_NAME}/debian
rclone ${RCLONE_ARGS} copy ${BUILD_REPOS_DIR}/debian rackspace:${CLOUDFILES_REPO_NAME}/debian

reprepro-debs: \
${BUILD_REPOS_DIR}/ubuntu-14.04-x86_64 \
${BUILD_REPOS_DIR}/ubuntu-16.04-x86_64 \
${BUILD_REPOS_DIR}/debian

clean-repos:
rm -rf ${BUILD_REPOS_DIR}

# NOTE make 4.1 supports the proper syntax, which is
# define buildReprepro =
define buildReprepro
mkdir -p $@/conf
sed -n ${SED_DISTRIBUTIONS} pkg/debian/repo/conf/distributions > $@/conf/distributions
${REPREPRO} -b $@ includedeb cloudmonitoring $<
endef

reprepro-deb:
${REPREPRO} -b ${DEB_REPO_DIR} includedeb cloudmonitoring build/*.deb
${BUILD_REPOS_DIR}/ubuntu-14.04-x86_64 : ${BUILD_DIR}/${PKG_BASE}_upstart.deb
$(buildReprepro)

package-deb: ${PKG_DEB}
${BUILD_REPOS_DIR}/ubuntu-16.04-x86_64 : ${BUILD_DIR}/${PKG_BASE}_systemd.deb
$(buildReprepro)

package-deb-local: stage-deb-exe-local package-deb
${BUILD_REPOS_DIR}/debian : ${BUILD_DIR}/${PKG_BASE}.deb
$(buildReprepro)

${PKG_DEB} : ${DEB_BUILD_DIR}/${PKGDIR_BIN}/${EXE} $(addprefix ${DEB_BUILD_DIR}/,${DEB_ALL_FILES}) ${DEB_BUILD_DIR}
package-debs: ${BUILD_DIR}/${PKG_BASE}.deb \
${BUILD_DIR}/${PKG_BASE}_systemd.deb \
${BUILD_DIR}/${PKG_BASE}_upstart.deb

package-debs-local: stage-deb-exe-local package-debs

${BUILD_DIR}/${PKG_BASE}.deb : $(addprefix ${DEB_BUILD_DIR}/,${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES} ${UPSTART_DEFAULT} ${UPSTART_CONF} ${SYSTEMD_CONF})
rm -f $@
${FPM} -p $@ -s dir -t deb \
-n ${APP_NAME} --license "${LICENSE}" --vendor "${VENDOR}" \
-v ${GIT_TAG} --iteration ${TAG_DISTANCE} \
$(foreach d,${OWNED_DIRS},--directories ${d}) \
$(foreach c,${DEB_CONFIG_FILES},--config-files ${c}) \
${FPM_IDENTIFIERS} \
--deb-default ${DEB_BUILD_DIR}/${UPSTART_DEFAULT} \
--deb-upstart ${DEB_BUILD_DIR}/${UPSTART_CONF} \
--deb-systemd ${DEB_BUILD_DIR}/${SYSTEMD_CONF} \
--no-deb-systemd-restart-after-upgrade \
-C ${DEB_BUILD_DIR} ${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES}

${BUILD_DIR}/${PKG_BASE}_systemd.deb : $(addprefix ${DEB_BUILD_DIR}/,${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES} ${SYSTEMD_CONF})
rm -f $@
${FPM} -p $@ -s dir -t deb \
${FPM_IDENTIFIERS} \
--deb-default ${DEB_BUILD_DIR}/${UPSTART_DEFAULT} \
--deb-systemd ${DEB_BUILD_DIR}/${SYSTEMD_CONF} \
--no-deb-systemd-restart-after-upgrade \
-C ${DEB_BUILD_DIR} ${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES}

${BUILD_DIR}/${PKG_BASE}_upstart.deb : $(addprefix ${DEB_BUILD_DIR}/,${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES} ${UPSTART_DEFAULT} ${UPSTART_CONF})
rm -f $@
${FPM} -p $@ -s dir -t deb \
${FPM_IDENTIFIERS} \
--deb-default ${DEB_BUILD_DIR}/${UPSTART_DEFAULT} \
--deb-upstart ${DEB_BUILD_DIR}/${UPSTART_CONF} \
-C ${DEB_BUILD_DIR} ${PKGDIR_BIN}/${EXE} ${DEB_CONFIG_FILES}

clean:
rm -rf $(BUILD_DIR)

stage-deb-exe-local: | ${DEB_BUILD_DIR}/${PKGDIR_BIN}
stage-deb-exe-local: build
mkdir -p ${DEB_BUILD_DIR}/${PKGDIR_BIN}
cp -p ${BUILD_DIR}/${APP_NAME}_${OS}_${ARCH} ${DEB_BUILD_DIR}/${PKGDIR_BIN}/${EXE}

${DEB_BUILD_DIR}/${PKGDIR_BIN}/${EXE} : | ${DEB_BUILD_DIR}/${PKGDIR_BIN}
${DEB_BUILD_DIR}/${PKGDIR_BIN}/${EXE} :
mkdir -p ${DEB_BUILD_DIR}/${PKGDIR_BIN}
$(WGET) -q --no-use-server-timestamps -O $@ $(BIN_URL)
chmod +x $@

${DEB_BUILD_DIR}/${APP_CFG} : ${SRC_DIR}/generic/sample.cfg ${DEB_BUILD_DIR}/${PKGDIR_ETC}
cp $< $@
${DEB_BUILD_DIR}/${UPSTART_CONF} : ${DEB_SRC_DIR}/service.upstart
${DEB_BUILD_DIR}/${APP_CFG} : ${SRC_DIR}/generic/sample.cfg
${DEB_BUILD_DIR}/${LOGROTATE_CFG} : ${SRC_DIR}/generic/logrotate.cfg
${DEB_BUILD_DIR}/${SYSTEMD_CONF} : ${GENERIC_SRC_DIR}/service.systemd
${DEB_BUILD_DIR}/${UPSTART_DEFAULT} : ${DEB_SRC_DIR}/upstart_default.cfg

${DEB_BUILD_DIR}/${LOGROTATE_CFG} : ${SRC_DIR}/generic/logrotate.cfg ${DEB_BUILD_DIR}/${PKGDIR_ETC}/logrotate.d
# Regular package files
${DEB_BUILD_DIR}/${SYSTEMD_CONF} ${DEB_BUILD_DIR}/${UPSTART_DEFAULT} ${DEB_BUILD_DIR}/${LOGROTATE_CFG} ${DEB_BUILD_DIR}/${APP_CFG} :
mkdir -p $(@D)
cp $< $@

${DEB_BUILD_DIR}/${UPSTART_CONF} : ${DEB_SRC_DIR}/service.upstart ${DEB_BUILD_DIR}/${PKGDIR_ETC}/init
# Executable package files
${DEB_BUILD_DIR}/${UPSTART_CONF} :
mkdir -p $(@D)
cp $< $@
chmod +x $@

${DEB_BUILD_DIR}/${SYSTEMD_CONF} : ${GENERIC_SRC_DIR}/service.systemd ${DEB_BUILD_DIR}/${PKGDIR_ETC}/init
cp $< $@
chmod +x $@

${DEB_BUILD_DIR}/${UPSTART_DEFAULT} : ${DEB_SRC_DIR}/upstart_default.cfg ${DEB_BUILD_DIR}/${PKGDIR_ETC}/default
cp $< $@

${BUILD_DIR} $(addprefix ${DEB_BUILD_DIR}/,${PKGDIR_BIN} ${PKGDIR_ETC} ${PKGDIR_ETC}/logrotate.d ${PKGDIR_ETC}/init ${PKGDIR_ETC}/default) :
mkdir -p $@
# .PHONY tells make to not expect these goals to be actual files produced by the rule
.PHONY: default repackage package package-debs package-repo-upload package-upload-deb package-debs-local reprepro-debs \
clean clean-repos generate-mocks stage-deb-exe-local build test test-integrationcli coverage install-fpm \
generate-callgraphs regenerate-callgraphs clean-callgraphs
2 changes: 1 addition & 1 deletion contrib/combine-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Generate test coverage statistics for Go packages.
#
# Works around the fact that `go test -coverprofile` currently does not work
Expand Down
18 changes: 18 additions & 0 deletions contrib/docker-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:14.04

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
make \
git \
ruby \
ruby-dev \
ruby-ffi \
binutils \
reprepro \
wget \
&& \
apt-get clean

RUN gem install --no-ri --no-rdoc fpm

WORKDIR /home
19 changes: 19 additions & 0 deletions contrib/docker-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This Docker image can be built and used to run `fpm` and `reprepro` for testing on your development machine.

From the workspace directory `rackspace-monitoring-poller`, run the following to build the image

```bash
docker build -t poller-builder contrib/docker-builder
```

With that you can use the image to run `make`, etc using

```bash
docker run -it --rm -v $PWD:/home poller-builder
```

For example, to build the debian packages and populate the apt repo area without signing, run

```bash
make DONT_SIGN=1 reprepro-debs
```
16 changes: 3 additions & 13 deletions pkg/debian/service.upstart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]

pre-start script
. /etc/default/rackspace-monitoring-poller

if [ x"$ENABLED" != xtrue ]; then
echo "Not enabled"
stop
exit 0
fi
end script

respawn

script
. /etc/default/rackspace-monitoring-poller
start-stop-daemon --make-pidfile --pidfile /var/run/rackspace-monitoring-poller.pid \
--exec /usr/bin/rackspace-monitoring-poller \
--start -- serve --config $CONFIG_FILE $POLLER_SERVE_OPTS
if [ "x$ENABLED" = xtrue ]; then
exec /usr/bin/rackspace-monitoring-poller serve --config $CONFIG_FILE $POLLER_SERVE_OPTS
fi
end script

0 comments on commit 0727038

Please sign in to comment.