From b642ac0296d1b9c077f3188efcbcc6d6cfd1621c Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Thu, 6 Jun 2019 14:30:11 -0700 Subject: [PATCH 1/6] Add systemd and centos7 support. --- Makefile | 91 ++++++++++++++++++++++++ build_rpm.sh | 48 ++++++++++++- petasos.spec => etc/init.d/petasos.spec | 0 etc/systemd/petasos.service | 17 +++++ etc/systemd/petasos.spec | 94 +++++++++++++++++++++++++ 5 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 Makefile rename petasos.spec => etc/init.d/petasos.spec (100%) create mode 100644 etc/systemd/petasos.service create mode 100644 etc/systemd/petasos.spec diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bfa29cd --- /dev/null +++ b/Makefile @@ -0,0 +1,91 @@ +DEFAULT: build + +GOPATH := ${CURDIR} +GOFMT ?= gofmt +APP := petasos +FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH))) +BINARY := $(FIRST_GOPATH)/bin/$(APP) + +PROGVER = $(shell grep 'applicationVersion.*= ' src/$(APP)/$(APP).go | awk '{print $$3}' | sed -e 's/\"//g') +RELEASE = 1 + +.PHONY: glide-install +glide-install: + export GOPATH=$(GOPATH) && cd src && glide install --strip-vendor + +.PHONY: build +build: glide-install + export GOPATH=$(GOPATH) && cd src/$(APP) && go build + +rpm: + mkdir -p ./.ignore/SOURCES + tar -czf ./.ignore/SOURCES/$(APP)-$(PROGVER).tar.gz --transform 's/^\./$(APP)-$(PROGVER)/' --exclude ./keys --exclude ./.git --exclude ./.ignore --exclude ./conf --exclude ./deploy --exclude ./vendor --exclude ./src/vendor . + cp etc/systemd/$(APP).service ./.ignore/SOURCES/ + cp etc/$(APP)/$(APP).yaml ./.ignore/SOURCES/ + rpmbuild --define "_topdir $(CURDIR)/.ignore" \ + --define "_ver $(PROGVER)" \ + --define "_releaseno $(RELEASE)" \ + -ba etc/systemd/$(APP).spec + +.PHONY: version +version: + @echo $(PROGVER) + + +# If the first argument is "update-version"... +ifeq (update-version,$(firstword $(MAKECMDGOALS))) + # use the rest as arguments for "update-version" + RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # ...and turn them into do-nothing targets + $(eval $(RUN_ARGS):;@:) +endif + +.PHONY: update-version +update-version: + @echo "Update Version $(PROGVER) to $(RUN_ARGS)" + sed -i "s/$(PROGVER)/$(RUN_ARGS)/g" src/$(APP)/$(APP).go + + +.PHONY: install +install: + echo go build -o $(BINARY) $(PROGVER) + +.PHONY: release-artifacts +release-artifacts: glide-install + mkdir -p ./.ignore + export GOPATH=$(GOPATH) && cd src/$(APP) && GOOS=darwin GOARCH=amd64 go build -o ../../.ignore/$(APP)-$(PROGVER).darwin-amd64 + export GOPATH=$(GOPATH) && cd src/$(APP) && GOOS=linux GOARCH=amd64 go build -o ../../.ignore/$(APP)-$(PROGVER).linux-amd64 + +.PHONY: docker +docker: + docker build -f ./deploy/Dockerfile -t $(APP):$(PROGVER) . + +# build docker without running modules +.PHONY: local-docker +local-docker: + GOOS=linux GOARCH=amd64 go build -o $(APP)_linux_amd64 + docker build -f ./deploy/Dockerfile.local -t $(APP):local . + +.PHONY: style +style: + ! gofmt -d $$(find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' + +.PHONY: test +test: + go test -o $(BINARY) -v -race -coverprofile=cover.out $(go list ./... | grep -v "/vendor/") + +.PHONY: test-cover +test-cover: test + go tool cover -html=cover.out + +.PHONY: codecov +codecov: test + curl -s https://codecov.io/bash | bash + +.PHONEY: it +it: + ./it.sh + +.PHONY: clean +clean: + rm -rf ./$(APP) ./.ignore ./coverage.txt ./vendor ./src/vendor diff --git a/build_rpm.sh b/build_rpm.sh index c521600..dccce7f 100755 --- a/build_rpm.sh +++ b/build_rpm.sh @@ -2,6 +2,41 @@ NAME=petasos +RPM_BUILD_ROOT=/root +SIGN=1 + + +usage() +{ + echo "usage: build_rpm.sh [--rpm-build-root path] [--no-sign]" + echo " --rpm-build-root - the path where /rpmbuild exists for your user" + echo " --no-sign - don't try to sign the build" +} + +while [ "$1" != "" ]; do + case $1 in + --rpm-build-root ) shift + RPM_BUILD_ROOT=$1 + ;; + + --no-sign ) SIGN=0 + ;; + + --build-number ) shift + BUILD_NUMBER=$1 + ;; + + -h | --help ) usage + exit + ;; + + * ) usage + exit 1 + + esac + shift +done + echo "Adjusting build number..." taglist=`git tag -l` @@ -26,20 +61,29 @@ echo "Building the ${NAME} rpm..." pushd .. cp -r ${NAME} ${NAME}-$release tar -czvf ${NAME}-$new_release.tar.gz ${NAME}-$release -mv ${NAME}-$new_release.tar.gz /root/rpmbuild/SOURCES +mv ${NAME}-$new_release.tar.gz ${RPM_BUILD_ROOT}/rpmbuild/SOURCES rm -rf ${NAME}-$release popd # Merge the changelog into the spec file so we're consistent +cat ${NAME}.spec.in > ${NAME}.spec cat ChangeLog >> ${NAME}.spec -yes "" | rpmbuild -ba --sign \ +if [ 0 == $SIGN ]; then + yes "" | rpmbuild -ba \ + --define "_ver $release" \ + --define "_releaseno ${BUILD_NUMBER}" \ + --define "_fullver $new_release" \ + ${NAME}.spec +else + yes "" | rpmbuild -ba --sign \ --define "_signature gpg" \ --define "_gpg_name Comcast Xmidt Team " \ --define "_ver $release" \ --define "_releaseno ${BUILD_NUMBER}" \ --define "_fullver $new_release" \ ${NAME}.spec +fi pushd .. echo "$new_release" > versionno.txt diff --git a/petasos.spec b/etc/init.d/petasos.spec similarity index 100% rename from petasos.spec rename to etc/init.d/petasos.spec diff --git a/etc/systemd/petasos.service b/etc/systemd/petasos.service new file mode 100644 index 0000000..4d48e61 --- /dev/null +++ b/etc/systemd/petasos.service @@ -0,0 +1,17 @@ +[Unit] +Description=The Xmidt HTTP redirector server. +After=network.target remote-fs.target nss-lookup.target + +[Service] +Type=simple +PIDFile=/run/petasos.pid +ExecStartPre=/usr/bin/rm -f /run/petasos.pid +ExecStart=/usr/bin/petasos +ExecReload=/bin/kill -s HUP $MAINPID +TimeoutStopSec=10 +KillMode=process +PrivateTmp=true +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/etc/systemd/petasos.spec b/etc/systemd/petasos.spec new file mode 100644 index 0000000..f35348e --- /dev/null +++ b/etc/systemd/petasos.spec @@ -0,0 +1,94 @@ +%define debug_package %{nil} + +Name: petasos +Version: %{_ver} +Release: %{_releaseno}%{?dist} +Summary: The Xmidt HTTP redirector server. + +Group: System Environment/Daemons +License: ASL 2.0 +URL: https://github.com/Comcast/%{name} +Source0: %{name}-%{version}.tar.gz + +BuildRequires: golang >= 1.11 + +Provides: %{name} + +%description +The Xmidt HTTP redirector server. + +%prep +%setup -q + +%build +export GOPATH=$(pwd) +pushd src +glide i --strip-vendor +cd %{name} +go build %{name} +popd + +%install + +# Install Binary +%{__install} -D -p -m 755 src/%{name}/%{name} %{buildroot}%{_bindir}/%{name} + +# Install Service +%{__install} -D -p -m 644 etc/systemd/%{name}.service %{buildroot}%{_unitdir}/%{name}.service + +# Install Configuration +%{__install} -D -p -m 644 etc/%{name}/%{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml + + +# Create Logging Location +%{__install} -d %{buildroot}%{_localstatedir}/log/%{name} + +# Create Runtime Details Location +%{__install} -d %{buildroot}%{_localstatedir}/run/%{name} + +%files +%defattr(-, %{name}, %{name}, -) + +# Binary +%attr(755, %{name}, %{name}) %{_bindir}/%{name} + +# Configuration +%dir %{_sysconfdir}/%{name} +%config(noreplace) %{_sysconfdir}/%{name}/%{name}.yaml + +# Service Files +%{_unitdir}/%{name}.service + +# Logging Location +%dir %{_localstatedir}/log/%{name} + +# Runtime Details Location +%dir %{_localstatedir}/run/%{name} + +%pre +# If app user does not exist, create +id %{name} >/dev/null 2>&1 +if [ $? != 0 ]; then + /usr/sbin/groupadd -r %{name} >/dev/null 2>&1 + /usr/sbin/useradd -d /var/run/%{name} -r -g %{name} %{name} >/dev/null 2>&1 +fi + + +%post +%systemd_post %{name}.service + +%preun +%systemd_preun %{name}.service + +%postun +%systemd_postun %{name}.service + +# Do not remove anything if this is not an uninstall +if [ $1 = 0 ]; then + /usr/sbin/userdel -r %{name} >/dev/null 2>&1 + /usr/sbin/groupdel %{name} >/dev/null 2>&1 + # Ignore errors from above + true +fi + +%changelog From d16ca42734878c6a5da294021dedf17afae0a03c Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 10 Jun 2019 18:48:20 -0700 Subject: [PATCH 2/6] Make the shipper happy for now. --- release_notes.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 release_notes.md diff --git a/release_notes.md b/release_notes.md new file mode 100644 index 0000000..fc64f7c --- /dev/null +++ b/release_notes.md @@ -0,0 +1 @@ +Jack is very helpful. From 2cb2aa856c7ae9896fa678030330cc9994e15b22 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 10 Jun 2019 19:20:51 -0700 Subject: [PATCH 3/6] Add a changelog file. --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4256b25 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [Unreleased] +### Added +- Initial creation + +[Unreleased]: https://github.com/Comcast/petasos/compare/0.0.0...HEAD From d568b24795e11f49e038068ba715c4056cdac002 Mon Sep 17 00:00:00 2001 From: Weston Schmidt Date: Mon, 10 Jun 2019 19:25:43 -0700 Subject: [PATCH 4/6] Work on the changelog files for the new release process. --- CHANGELOG.md | 7 ++++++- src/petasos/petasos.go | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4256b25..264e958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added +- Update the relse process + +## [0.1.1] +### Added - Initial creation -[Unreleased]: https://github.com/Comcast/petasos/compare/0.0.0...HEAD +[Unreleased]: https://github.com/Comcast/petasos/compare/0.1.1...HEAD +[0.1.1]: https://github.com/Comcast/petasos/compare/0.0.0...0.1.1 diff --git a/src/petasos/petasos.go b/src/petasos/petasos.go index ca6f29a..cc53ab9 100644 --- a/src/petasos/petasos.go +++ b/src/petasos/petasos.go @@ -39,9 +39,10 @@ import ( ) const ( - applicationName = "petasos" - release = "Developer" - defaultVnodeCount int = 211 + applicationName = "petasos" + release = "Developer" + defaultVnodeCount int = 211 + applicationVersion = "0.1.2" ) // petasos is the driver function for Petasos. It performs everything main() would do, From 7a923a0ee146a4ab0143fd34c0487cbfed29b15a Mon Sep 17 00:00:00 2001 From: Jack Murdock Date: Tue, 11 Jun 2019 10:25:35 -0700 Subject: [PATCH 5/6] fix changelog --- CHANGELOG.md | 2 +- ChangeLog | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 ChangeLog diff --git a/CHANGELOG.md b/CHANGELOG.md index 264e958..28f2b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Added -- Update the relse process +- Update the release process ## [0.1.1] ### Added diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index fddb8d1..0000000 --- a/ChangeLog +++ /dev/null @@ -1,2 +0,0 @@ -* Tue Mar 28 2017 Weston Schmidt - 0.1.1 -- initial creation From c60f5465cd7db1309af4fd770eb9f3e8e18fd45c Mon Sep 17 00:00:00 2001 From: Concourse CI Date: Tue, 11 Jun 2019 17:32:11 +0000 Subject: [PATCH 6/6] [skip ci] release v0.1.2 --- CHANGELOG.md | 5 +++++ release_notes.md | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28f2b5d..004e927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [v0.1.2] +Jack is very helpful. + + ### Added - Update the release process diff --git a/release_notes.md b/release_notes.md index fc64f7c..8b13789 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1 +1 @@ -Jack is very helpful. +