From c91dab5ac3234bebeeed03cca5e27f20429c1293 Mon Sep 17 00:00:00 2001 From: Kristina Spring Date: Mon, 2 Dec 2019 14:40:58 -0800 Subject: [PATCH 1/2] Updated svalinn's release pipeline to use travis --- .travis.yml | 39 +++++++++++++++++++++----- CHANGELOG.md | 53 ++--------------------------------- Makefile | 17 ----------- README.md | 10 ++++++- deploy/packaging/svalinn.spec | 20 +++++++------ release_notes.md | 1 - rpkg.macros | 19 +++++++++++++ 7 files changed, 74 insertions(+), 85 deletions(-) delete mode 100644 release_notes.md create mode 100644 rpkg.macros diff --git a/.travis.yml b/.travis.yml index ffd4db7..eb33741 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,19 @@ language: go go: - - 1.12.x + - 1.13.x + - tip os: - linux - - osx services: - docker -matrix: - allow_failures: - - go: tip - fast_finish: true - branches: only: - master + - /^v[0-9]+\.[0-9]+\.[0-9]+$/ script: - make style codecov @@ -26,5 +22,34 @@ jobs: include: - stage: integration name: "Integration Tests" + if: branch = master script: - make it + - stage: tag + name: "Tag For Release" + if: branch = master + before_script: + - echo -e "machine github.com\n login $GH_TOKEN" > ~/.netrc + script: + - export OLD_VERSION=$(make version) + - git config --global user.name "kristinaspring" + - git config --global user.email "kmspring57@gmail.com" + - export TAG=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1" if /.*## \[Unreleased\]\s+## \[(v\d+.\d+.\d+)\].*/s') + - export TODAY=`date +'%m/%d/%Y'` + - export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$ENV{TODAY}\n\n$1\n" if /.*## \[$ENV{TAG}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s') + - if [[ "$TAG" != "" && "$TAG" != "$OLD_VERSION" ]]; then git tag -a "$TAG" -m "$NOTES"; git push origin --tags; echo $?; fi + - stage: release + name: "Make a Release" + if: branch != master + script: skip + before_deploy: + - make release-artifacts + deploy: + on: + all_branches: true + tags: true + provider: releases + api_key: "$GH_TOKEN" + file: ./.ignore/* + skip_cleanup: true + \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f0c0f0..7455552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,23 +5,17 @@ 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] +- Updated release pipeline to use travis ## [v0.12.1] - Bumped db package to v0.3.2 - - ## [v0.12.0] - switched database configuration from postgres to cassandra - bumped codex-db to v0.2.0 - - ## [v0.11.2] - - - ## [v0.11.0] - updated urls and imports - Removed acquirer code and use the bascule acquirer instead @@ -30,24 +24,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Updated yaml and documentation - Added docs folder for more in depth documentation - - ## [v0.10.2] - - - ## [v0.10.0] - Store the birthdate and deathdate as Unix with Nanosecond precision. - - ## [v0.9.1] - Added deathdate check - Bumped codex - - ## [v0.9.0] - Modified event parsing: if the eventType is state, parse the event destination to find the device id. Otherwise, take the event Source as the @@ -57,19 +42,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Refactored code to separate rules and requestParser into their own packages. Also moved batchInserter to codex and refactored that. - ## [v0.8.0] - Added ability to turn off max batch size - Bumped codex to v0.5.0 - Return 429 status code on full queue - - ## [v0.7.1] - close request body after reading it - - ## [v0.7.0] - Stopped building other services for integ tests - Added error check for making the request for getting the SAT @@ -79,25 +59,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added `wrp-go` - Store the wrp message as Msgpack - - ## [v0.6.1] - fixed cipher yaml loading - - ## [v0.6.0] - bumped codex to v0.4.0 for cipher upgrades - - ## [v0.5.1] - Create timestamp if it doesn't exist in payload - If request for acquiring SAT for webhook registration receives a non 200, return an error - Bumped codex-common to v0.3.3 - - ## [v0.5.0] - Added Blacklist - Removed pruning @@ -105,42 +77,28 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - bumped codex to v0.3.2 - bumped webpa-common to v1.0.0 - ## [v0.4.0] - adding basic level of encryption - store event as wrp.Message - - ## [v0.3.0] - modified health metric to reflect unhealthy when pinging the database fails - device IDs are inserted into the db in lowercase - - ## [v0.2.7] - replace dep with modules - bumped codex - - - ## [v0.2.6] - Bumped codex common - Converted times to Unix for the `db` package - - ## [v0.2.5] - Bumped codex version - - ## [v0.2.4] - Bumped codex - - ## [v0.2.3] - Limited number of goroutine workers running at one time - Enabled pprof @@ -148,23 +106,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added metrics - Added batching insertion to database - ## [v0.2.2] Bug Fix: Webhook authorization config loading - - ## [v0.2.1] Bug Fix Caduceus config loading - - - ## [v0.2.0] - added metrics - fixed signature validation - Created `webhook` package and created sat and basic token acquirers - - Added unit tests ## [v0.1.1] @@ -176,7 +127,7 @@ Bug Fix Caduceus config loading - Bumped codex version, modified code to match changes [Unreleased]: https://github.com/xmidt-org/svalinn/compare/v0.12.1...HEAD -[v0.12.1]: https://github.com/xmidt-org/svalinn/compare/v0.12.1-rc.2...v0.12.1 +[v0.12.1]: https://github.com/xmidt-org/svalinn/compare/v0.12.0...v0.12.1 [v0.12.0]: https://github.com/xmidt-org/svalinn/compare/v0.11.2...v0.12.0 [v0.11.2]: https://github.com/xmidt-org/svalinn/compare/v0.11.0...v0.11.2 [v0.11.0]: https://github.com/xmidt-org/svalinn/compare/v0.10.2...v0.11.0 diff --git a/Makefile b/Makefile index 359ac2b..f917b2c 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,8 @@ DEFAULT: build GO ?= go GOFMT ?= $(GO)fmt APP := svalinn -FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) -BINARY := $(FIRST_GOPATH)/bin/$(APP) PROGVER = $(shell git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/') -RPM_VERSION=$(shell echo $(PROGVER) | sed 's/\(.*\)-\(.*\)/\1/') -RPM_RELEASE=$(shell echo $(PROGVER) | sed -n 's/.*-\(.*\)/\1/p' | grep . && (echo "$(echo $(PROGVER) | sed 's/.*-\(.*\)/\1/')") || echo "1") BUILDTIME = $(shell date -u '+%Y-%m-%d %H:%M:%S') GITCOMMIT = $(shell git rev-parse --short HEAD) @@ -20,19 +16,6 @@ go-mod-vendor: build: go-mod-vendor $(GO) build -o $(APP) -ldflags "-X 'main.BuildTime=$(BUILDTIME)' -X main.GitCommit=$(GITCOMMIT) -X main.Version=$(PROGVER)" -rpm: - mkdir -p ./.ignore/SOURCES - tar -czvf ./.ignore/SOURCES/$(APP)-$(RPM_VERSION)-$(RPM_RELEASE).tar.gz . --exclude ./.git --exclude ./.ignore --exclude ./conf --exclude ./deploy --exclude ./vendor - cp conf/$(APP).service ./.ignore/SOURCES/ - cp conf/$(APP).yaml ./.ignore/SOURCES/ - cp LICENSE ./.ignore/SOURCES/ - cp NOTICE ./.ignore/SOURCES/ - cp CHANGELOG.md ./.ignore/SOURCES/ - rpmbuild --define "_topdir $(CURDIR)/.ignore" \ - --define "_version $(RPM_VERSION)" \ - --define "_release $(RPM_RELEASE)" \ - -ba deploy/packaging/$(APP).spec - .PHONY: version version: @echo $(PROGVER) diff --git a/README.md b/README.md index c0b882f..8e7e52a 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,6 @@ make build The Makefile has the following options you may find helpful: * `make build`: builds the Svalinn binary -* `make rpm`: builds an rpm containing Svalinn * `make docker`: builds a docker image for Svalinn, making sure to get all dependencies * `make local-docker`: builds a docker image for Svalinn with the assumption @@ -205,6 +204,15 @@ The Makefile has the following options you may find helpful: * `make test`: runs unit tests with coverage for Svalinn * `make clean`: deletes previously-built binaries and object files +### RPM + +First have a local clone of the source and go into the root directory of the +repository. Then use rpkg to build the rpm: +```bash +rpkg srpm --spec / +rpkg -C /.config/rpkg.conf sources --outdir ' +``` + ### Docker The docker image can be built either with the Makefile or by running a docker diff --git a/deploy/packaging/svalinn.spec b/deploy/packaging/svalinn.spec index 30bf3d4..86328d4 100644 --- a/deploy/packaging/svalinn.spec +++ b/deploy/packaging/svalinn.spec @@ -1,9 +1,9 @@ -%define AutoReqProv: no %define __os_install_post %{nil} +%define debug_package %{nil} Name: svalinn -Version: %{_version} -Release: %{_release}%{?dist} +Version: {{{ git_tag_version }}} +Release: 1%{?dist} Summary: The receiver of data from XMiDT Caduceus. Vendor: Comcast @@ -11,17 +11,21 @@ Packager: Comcast Group: System Environment/Daemons License: ASL 2.0 URL: https://github.com/xmidt-org/svalinn -Source0: %{name}-%{_version}-%{_release}.tar.gz +Source0: %{name}-%{_version}.tar.gz Prefix: /opt BuildRoot: %{_tmppath}/%{name} BuildRequires: systemd BuildRequires: golang >= 1.11 +BuildRequires: git %description The shield to protect our users from incoming events for the codex project. aka. The receiver of data from XMiDT Caduceus +%prep +%setup -q + %build GO111MODULE=on go build -ldflags "-X 'main.BuildTime=`date -u '+%Y-%m-%d %H:%M:%S'`' -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=%{_version}" -o $RPM_SOURCE_DIR/%{name} %{_topdir}/.. @@ -34,13 +38,13 @@ echo rm -rf %{buildroot} %{__install} -d %{buildroot}%{_localstatedir}/run/%{name} %{__install} -d %{buildroot}%{_unitdir} -%{__install} -p $RPM_SOURCE_DIR/%{name} %{buildroot}%{_bindir} -%{__install} -p $RPM_SOURCE_DIR/%{name}.service %{buildroot}%{_unitdir}/%{name}.service -%{__install} -p $RPM_SOURCE_DIR/%{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml +%{__install} -p %{name} %{buildroot}%{_bindir} +%{__install} -p conf/%{name}.service %{buildroot}%{_unitdir}/%{name}.service +%{__install} -p %{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml %files %defattr(644, root, root, 755) -%doc $RPM_SOURCE_DIR/LICENSE $RPM_SOURCE_DIR/CHANGELOG.md $RPM_SOURCE_DIR/NOTICE +%doc LICENSE CHANGELOG.md NOTICE %attr(755, root, root) %{_bindir}/%{name} diff --git a/release_notes.md b/release_notes.md deleted file mode 100644 index 8b13789..0000000 --- a/release_notes.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/rpkg.macros b/rpkg.macros new file mode 100644 index 0000000..45baa75 --- /dev/null +++ b/rpkg.macros @@ -0,0 +1,19 @@ +function git_short_hash { + short_hash="$(cached git_short_hash)" + + if [ -z "$short_hash" ]; then + short_hash="$(git rev-parse --short HEAD)" + fi + + output "$short_hash" +} + +function git_tag_version { + tag="$(cached git_tag_version)" + + if [ -z "$tag" ]; then + tag="$(git describe --tags --abbrev=0)" + fi + + output "$tag" +} \ No newline at end of file From 3b318bcb76407fadb1846d91c055030c9089f47b Mon Sep 17 00:00:00 2001 From: Kristina Spring Date: Mon, 2 Dec 2019 15:03:14 -0800 Subject: [PATCH 2/2] fixed build command --- deploy/packaging/svalinn.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/packaging/svalinn.spec b/deploy/packaging/svalinn.spec index 86328d4..5df3daf 100644 --- a/deploy/packaging/svalinn.spec +++ b/deploy/packaging/svalinn.spec @@ -27,14 +27,14 @@ aka. The receiver of data from XMiDT Caduceus %setup -q %build -GO111MODULE=on go build -ldflags "-X 'main.BuildTime=`date -u '+%Y-%m-%d %H:%M:%S'`' -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=%{_version}" -o $RPM_SOURCE_DIR/%{name} %{_topdir}/.. +GO111MODULE=on GOPROXY=https://proxy.golang.org go build -ldflags "-linkmode=external -X 'main.BuildTime=`date -u '+%Y-%m-%d %H:%M:%S'`' -X main.GitCommit={{{ git_short_hash }}} -X main.Version=%{version}" -o %{name} . %install echo rm -rf %{buildroot} %{__install} -d %{buildroot}%{_bindir} %{__install} -d %{buildroot}%{_initddir} %{__install} -d %{buildroot}%{_sysconfdir}/%{name} -%{__install} -d %{buildroot}%{_localstatedir}/log/%{name} +%{__install} -d %{buildroot}%{_localstatedir}/log/%{name}˜ %{__install} -d %{buildroot}%{_localstatedir}/run/%{name} %{__install} -d %{buildroot}%{_unitdir}