Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.

Commit b450f65

Browse files
Add deb/rpm package building and publishing (#80)
* Add deb/rpm package building and publishing Basically copied segmentio/chamber#129 * split linux dist/publish
1 parent 41223b9 commit b450f65

File tree

6 files changed

+264
-44
lines changed

6 files changed

+264
-44
lines changed

.circleci/config.yml

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,76 @@
11
version: 2
22
jobs:
3-
build:
3+
test:
44
docker:
55
- image: circleci/golang:1.10
66
working_directory: /go/src/github.com/segmentio/aws-okta
77
steps:
88
- checkout
99
- run:
10-
name: Build
10+
name: Test
1111
command: |
12-
make govendor dist
12+
make test
13+
14+
dist-linux:
15+
docker:
16+
- image: circleci/golang:1.10
17+
working_directory: /go/src/github.com/segmentio/aws-okta
18+
steps:
19+
- checkout
20+
- run:
21+
name: Install nfpm, rpmbuild
22+
command: |
23+
sudo make -f Makefile.tools nfpm-debian rpmbuild-debian
24+
- run:
25+
name: Make distributables
26+
command: |
27+
make -f Makefile.release dist-linux
1328
- persist_to_workspace:
1429
root: .
1530
paths: ['dist/*']
1631

17-
release:
32+
publish-linux:
1833
docker:
1934
- image: circleci/golang:1.10
2035
working_directory: /go/src/github.com/segmentio/aws-okta
2136
steps:
2237
- checkout
2338
- attach_workspace: { at: . }
39+
- run:
40+
name: Install tools
41+
command: |
42+
make -f Makefile.tools github-release
43+
# this is all for package_cloud :/
44+
sudo apt update -q
45+
sudo apt install -yq ruby ruby-dev build-essential
46+
# fixes https://askubuntu.com/questions/872399/error-failed-to-build-gem-native-extension-when-trying-to-download-rubocop
47+
sudo gem install rake
48+
sudo make -f Makefile.tools package_cloud
2449
- run:
2550
name: Release
26-
# TODO: cache from build step
2751
command: |
28-
make release
52+
make -f Makefile.release publish-linux
2953
3054
workflows:
3155
version: 2
32-
test-deploy:
56+
# currently we only build/publish for linux: macOS builds require non-FOSS
57+
# Keychain libs that require a macOS host to build on
58+
# https://github.com/segmentio/aws-okta/issues/81
59+
test-dist-publish-linux:
3360
jobs:
34-
- build
35-
- release:
61+
- test
62+
- dist-linux:
63+
# needed to ensure dist happens on tag events
64+
filters:
65+
tags:
66+
only: /.*/
67+
- publish-linux:
3668
requires:
37-
- build
69+
- dist-linux
3870
filters:
71+
# never publish from a branch event
3972
branches:
4073
ignore: /.*/
74+
# release only on tag push events like vX[.Y.Z...][-whatever]
4175
tags:
42-
only: /v[0-9]+(\.[0-9]+)*/
76+
only: /v[0-9]+(\.[0-9]+)*(-[a-zA-Z0-9-]+)?/

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*~
2+
*.sw[a-z]
3+
vendor/*/
4+
dist/
5+
packagecloud.conf.json

Makefile

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,33 @@
1+
# Goals:
2+
# - user can build binaries on their system without having to install special tools
3+
# - user can fork the canonical repo and expect to be able to run CircleCI checks
4+
#
5+
# This makefile is meant for humans
6+
17
VERSION := $(shell git describe --tags --always --dirty="-dev")
28
LDFLAGS := -ldflags='-X "main.Version=$(VERSION)"'
39

4-
release: gh-release govendor clean dist
5-
github-release release \
6-
--security-token $$GH_LOGIN \
7-
--user segmentio \
8-
--repo aws-okta \
9-
--tag $(VERSION) \
10-
--name $(VERSION)
11-
12-
github-release upload \
13-
--security-token $$GH_LOGIN \
14-
--user segmentio \
15-
--repo aws-okta \
16-
--tag $(VERSION) \
17-
--name aws-okta-$(VERSION)-linux-amd64 \
18-
--file dist/aws-okta-$(VERSION)-linux-amd64
19-
20-
release-mac: gh-release govendor clean dist-mac
21-
github-release upload \
22-
--security-token $$GH_LOGIN \
23-
--user segmentio \
24-
--repo aws-okta \
25-
--tag $(VERSION) \
26-
--name aws-okta-$(VERSION)-darwin-amd64 \
27-
--file dist/aws-okta-$(VERSION)-darwin-amd64
10+
test: | govendor
11+
govendor sync
12+
go test -v ./...
13+
14+
all: dist/aws-okta-$(VERSION)-darwin-amd64 dist/aws-okta-$(VERSION)-linux-amd64
2815

2916
clean:
3017
rm -rf ./dist
3118

32-
dist:
33-
mkdir dist
34-
govendor sync
35-
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/aws-okta-$(VERSION)-linux-amd64
19+
dist/:
20+
mkdir -p dist
3621

37-
dist-mac:
38-
mkdir dist
22+
dist/aws-okta-$(VERSION)-darwin-amd64: | govendor dist/
3923
govendor sync
40-
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/aws-okta-$(VERSION)-darwin-amd64
24+
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $@
4125

42-
gh-release:
43-
go get -u github.com/aktau/github-release
26+
dist/aws-okta-$(VERSION)-linux-amd64: | govendor dist/
27+
govendor sync
28+
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $@
4429

4530
govendor:
4631
go get -u github.com/kardianos/govendor
32+
33+
.PHONY: clean all govendor

Makefile.release

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Goals:
2+
# - Linux releases can be published to Github automatically by CircleCI
3+
#
4+
# This Makefile is meant for machines
5+
6+
include Makefile
7+
8+
# set --pre-release if not tagged or tree is dirty or there's a `-` in the tag
9+
ifneq (,$(findstring -,$(VERSION)))
10+
GITHUB_RELEASE_FLAGS := "--pre-release"
11+
PACKAGECLOUD_NAME_SUFFIX := "-prerelease"
12+
endif
13+
14+
PACKAGECLOUD_DEB_DISTROS := \
15+
debian/stretch \
16+
ubuntu/trusty \
17+
ubuntu/xenial \
18+
ubuntu/bionic
19+
20+
PACKAGECLOUD_RPM_DISTROS := \
21+
fedora/27 \
22+
fedora/28
23+
24+
publish: publish-github publish-packagecloud
25+
26+
# note: this doesn't include sha256sums
27+
publish-linux: publish-github-linux publish-packagecloud
28+
29+
publish-github: publish-github-darwin publish-github-linux publish-github-sha256sums
30+
31+
publish-github-darwin: publish-github-darwin-bin
32+
33+
publish-github-linux: publish-github-linux-bin publish-github-deb publish-github-rpm
34+
35+
publish-packagecloud: publish-packagecloud-deb publish-packagecloud-rpm
36+
37+
github-release:
38+
github-release release \
39+
--security-token $$GH_LOGIN \
40+
--user segmentio \
41+
--repo aws-okta \
42+
$(GITHUB_RELEASE_FLAGS) \
43+
--tag $(VERSION) \
44+
--name $(VERSION)
45+
46+
publish-github-darwin-bin: dist/aws-okta-$(VERSION)-darwin-amd64 | github-release
47+
github-release upload \
48+
--security-token $$GH_LOGIN \
49+
--user segmentio \
50+
--repo aws-okta \
51+
--tag $(VERSION) \
52+
--name aws-okta-$(VERSION)-darwin-amd64 \
53+
--file $<
54+
55+
publish-github-linux-bin: dist/aws-okta-$(VERSION)-linux-amd64 | github-release
56+
github-release upload \
57+
--security-token $$GH_LOGIN \
58+
--user segmentio \
59+
--repo aws-okta \
60+
--tag $(VERSION) \
61+
--name aws-okta-$(VERSION)-linux-amd64 \
62+
--file $<
63+
64+
publish-github-deb: dist/aws-okta_$(VERSION)_amd64.deb | github-release
65+
github-release upload \
66+
--security-token $$GH_LOGIN \
67+
--user segmentio \
68+
--repo aws-okta \
69+
--tag $(VERSION) \
70+
--name aws-okta_$(VERSION)_amd64.deb \
71+
--file $<
72+
73+
publish-github-rpm: dist/aws-okta_$(VERSION)_amd64.rpm | github-release
74+
github-release upload \
75+
--security-token $$GH_LOGIN \
76+
--user segmentio \
77+
--repo aws-okta \
78+
--tag $(VERSION) \
79+
--name aws-okta_$(VERSION)_amd64.rpm \
80+
--file $<
81+
82+
publish-github-sha256sums: dist/aws-okta-$(VERSION).sha256sums | github-release
83+
github-release upload \
84+
--security-token $$GH_LOGIN \
85+
--user segmentio \
86+
--repo aws-okta \
87+
--tag $(VERSION) \
88+
--name aws-okta-$(VERSION).sha256sums \
89+
--file dist/aws-okta-$(VERSION).sha256sums
90+
91+
packagecloud.conf.json:
92+
@echo "{\"url\":\"https://packagecloud.io\",\"token\":\"$${PACKAGECLOUD_TOKEN}\"}" > $@
93+
94+
# package_cloud prints the last 4 chars of our token :(
95+
# so we attempt to filter that out
96+
97+
publish-packagecloud-deb: dist/aws-okta_$(VERSION)_amd64.deb packagecloud.conf.json
98+
@for v in $(PACKAGECLOUD_DEB_DISTROS); do \
99+
package_cloud push --config packagecloud.conf.json segment/aws-okta$(PACKAGECLOUD_NAME_SUFFIX)/$$v $< | \
100+
grep -v 'with token:' ; \
101+
done
102+
103+
publish-packagecloud-rpm: dist/aws-okta_$(VERSION)_amd64.rpm packagecloud.conf.json
104+
@for v in $(PACKAGECLOUD_RPM_DISTROS); do \
105+
package_cloud push --config packagecloud.conf.json segment/aws-okta$(PACKAGECLOUD_NAME_SUFFIX)/$$v $< | \
106+
grep -v 'with token:' ; \
107+
done
108+
109+
dist: dist-darwin dist-linux dist/aws-okta-$(VERSION).sha256sums
110+
111+
dist-darwin: dist/aws-okta-$(VERSION)-darwin-amd64
112+
113+
dist-linux: dist/aws-okta-$(VERSION)-linux-amd64 dist/aws-okta_$(VERSION)_amd64.deb dist/aws-okta_$(VERSION)_amd64.rpm
114+
115+
dist/aws-okta-$(VERSION).sha256sums: dist/aws-okta-$(VERSION)-darwin-amd64 dist/aws-okta-$(VERSION)-linux-amd64 dist/aws-okta_$(VERSION)_amd64.deb dist/aws-okta_$(VERSION)_amd64.rpm
116+
sha256sum $^ | sed 's|dist/||g' > $@
117+
118+
dist/nfpm-$(VERSION).yaml: | dist/
119+
sed -e "s/\$${VERSION}/$(VERSION)/g" -e "s|\$${DIST_BIN}|dist/aws-okta-$(VERSION)-linux-amd64|g" < nfpm.yaml.tmpl > $@
120+
121+
dist/aws-okta_$(VERSION)_amd64.deb: dist/nfpm-$(VERSION).yaml dist/aws-okta-$(VERSION)-linux-amd64
122+
nfpm -f $< pkg --target $@
123+
124+
dist/aws-okta_$(VERSION)_amd64.rpm: dist/nfpm-$(VERSION).yaml dist/aws-okta-$(VERSION)-linux-amd64
125+
nfpm -f $< pkg --target $@
126+
127+
.PHONY: \
128+
dist \
129+
dist-darwin \
130+
dist-linux \
131+
publish \
132+
publish-github \
133+
publish-github-linux \
134+
publish-github-linux-bin \
135+
publish-github-rpm \
136+
publish-github-deb \
137+
publish-github-darwin \
138+
publish-github-darwin-bin \
139+
github-release

Makefile.tools

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Tools installation recipes
2+
#
3+
# These are fragile, non-portable, and often require root
4+
#
5+
NFPM_VERSION := 0.9.3
6+
#from https://github.com/goreleaser/nfpm/releases/download/v0.9.3/nfpm_0.9.3_checksums.txt
7+
NFPM_SHA256 := f875ac060a30ec5c164e5444a7278322b276707493fa0ced6bfdd56640f0a6ea
8+
9+
nfpm-debian:
10+
cd /tmp && \
11+
curl -Ls https://github.com/goreleaser/nfpm/releases/download/v${NFPM_VERSION}/nfpm_${NFPM_VERSION}_Linux_x86_64.tar.gz > nfpm.tar.gz && \
12+
echo "${NFPM_SHA256} nfpm.tar.gz" | \
13+
sha256sum -c && \
14+
tar xzvf nfpm.tar.gz && \
15+
mv nfpm /usr/local/bin
16+
17+
rpmbuild-debian:
18+
apt update -q && apt install rpm -yq
19+
20+
rpmbuild-darwin:
21+
brew install rpm
22+
23+
sha256sum-darwin:
24+
brew install coreutils && ln -s $$(which gsha256sum) /usr/local/bin/sha256sum`
25+
26+
github-release:
27+
go get -u github.com/aktau/github-release
28+
29+
package_cloud:
30+
gem install package_cloud
31+
32+
.PHONY: nfpm-debian \
33+
rpmbuild-debian \
34+
rpmbuild-darwin \
35+
sha256sum-darwin \
36+
github-release \
37+
package_cloud

nfpm.yaml.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "aws-okta"
2+
arch: "amd64"
3+
platform: "linux"
4+
version: "${VERSION}"
5+
section: "default"
6+
priority: "extra"
7+
provides:
8+
- aws-okta
9+
vendor: 'Segment, Inc.'
10+
maintainer: [email protected]
11+
homepage: "https://github.com/segmentio/aws-okta"
12+
license: "MIT"
13+
# IMHO packages should install to /usr/bin
14+
bindir: /usr/bin
15+
files:
16+
"${DIST_BIN}": "/usr/bin/aws-okta"
17+
description: >
18+
aws-okta allows you to authenticate with AWS using your Okta credentials.

0 commit comments

Comments
 (0)