Skip to content

Commit 4847346

Browse files
authored
Merge pull request #447 from deniszh/DZ-Packaging
Fixing packaging
2 parents 1810d3c + 2fd26b5 commit 4847346

File tree

12 files changed

+240
-475
lines changed

12 files changed

+240
-475
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
jobs:
1616
analyze:
1717
name: Analyze
18-
runs-on: ubuntu-20.04
18+
runs-on: ubuntu-latest
1919

2020
strategy:
2121
fail-fast: false

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
golangci:
99
name: lint
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: golangci-lint

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Upload Packages to new release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
env:
13+
BINARY: ${{ github.event.repository.name }}
14+
CGO_ENABLED: 0
15+
16+
outputs:
17+
matrix: ${{ steps.build.outputs.matrix }}
18+
steps:
19+
- name: Set up Go
20+
uses: actions/setup-go@v2
21+
with:
22+
go-version: ^1
23+
24+
- uses: actions/checkout@v2
25+
name: Checkout
26+
27+
- name: Test
28+
run: make test
29+
env:
30+
CGO_ENABLED: 1
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
36+
- name: Install packaging dependencies
37+
run: |
38+
gem install rake fpm:1.10.2 package_cloud
39+
GO111MODULE=off go get github.com/mitchellh/gox
40+
41+
- name: Build packages
42+
id: build
43+
run: |
44+
make gox-build fpm-deb fpm-rpm
45+
make sum-files
46+
ARTIFACTS=
47+
# Upload all deb and rpm packages
48+
for package in *deb *rpm; do ARTIFACTS=${ARTIFACTS}\"$package\",\ ; done
49+
echo ::set-output name=matrix::{\"file\": [${ARTIFACTS} \"sha256sum\", \"md5sum\"]}
50+
51+
- name: Check version
52+
id: check_version
53+
run: |
54+
./out/${BINARY}-linux-amd64 -version
55+
[ v$(./out/${BINARY}-linux-amd64 -version) = ${{ github.event.release.tag_name }} ]
56+
57+
- name: Artifact
58+
id: artifact
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: packages
62+
retention-days: 1
63+
path: |
64+
*.deb
65+
*.rpm
66+
sha256sum
67+
md5sum
68+
69+
- name: Push packages to the stable repo
70+
run: make packagecloud-stable
71+
env:
72+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
73+
74+
upload:
75+
needs: build
76+
runs-on: ubuntu-latest
77+
strategy:
78+
matrix: ${{fromJson(needs.build.outputs.matrix)}}
79+
steps:
80+
- name: Download artifact
81+
uses: actions/download-artifact@v2
82+
with:
83+
name: packages
84+
- name: Upload ${{ matrix.file }}
85+
id: upload
86+
uses: actions/upload-release-asset@v1
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
with:
90+
upload_url: ${{ github.event.release.upload_url }}
91+
asset_path: ${{ matrix.file }}
92+
asset_name: ${{ matrix.file }}
93+
asset_content_type: application/octet-stream

.github/workflows/tests.yml

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
tests:
1212
name: Test code
13-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
1616
go:
@@ -28,20 +28,59 @@ jobs:
2828
- name: Check out code into the Go module directory
2929
uses: actions/checkout@v2
3030

31+
- name: Checkout to the latest tag
32+
run: |
33+
# Fetch all tags
34+
git fetch --depth=1 --tags
35+
# Get the latest tag
36+
VERS=$(git tag -l | sort -Vr | head -n1)
37+
# Fetch everything to the latest tag
38+
git fetch --shallow-since=$(git log $VERS -1 --format=%at)
39+
if: ${{ github.event_name == 'push' }} # only when built from master
40+
41+
- name: Build project
42+
run: make
43+
3144
- name: Test
45+
run: make test
46+
env:
47+
CGO_ENABLED: 1
48+
49+
- name: Check Docker images
3250
run: |
33-
make
34-
make test
51+
make image
52+
53+
- name: Set up Ruby
54+
uses: ruby/setup-ruby@v1
55+
with:
56+
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
57+
3558
- name: Install packaging dependencies
3659
run: |
37-
sudo apt-get install rpm ruby-dev
38-
sudo gem install fpm -v 1.10.2
39-
- name: Check packaging
40-
run: |
60+
gem install rake fpm:1.10.2 package_cloud
4161
GO111MODULE=off go get github.com/mitchellh/gox
42-
make gox-build
43-
make fpm-deb
44-
make fpm-rpm
45-
- name: Check Docker images
62+
63+
- name: Check packaging
4664
run: |
47-
make image
65+
make DEVEL=1 gox-build fpm-deb fpm-rpm
66+
make sum-files
67+
68+
- name: Upload Artifact
69+
if: ${{ matrix.go == '^1' }} # only upload artifact when built with latest go
70+
id: artifact
71+
uses: actions/upload-artifact@v2
72+
with:
73+
name: packages-${{ matrix.go }}
74+
retention-days: 3
75+
path: |
76+
*.deb
77+
*.rpm
78+
sha256sum
79+
md5sum
80+
81+
- name: Push packages to the autobuilds repo
82+
if: ${{ github.event_name == 'push' && matrix.go == '^1' }} # only when built from master with latest go
83+
run: make DEVEL=1 packagecloud-autobuilds
84+
env:
85+
PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
86+

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ _vendor/pkg
44
.vscode
55
_gopath
66
.DS_Store
7-
.idea
7+
.idea
8+
out/
9+
md5sum
10+
sha256sum
11+
*.rpm
12+
*.deb

.travis.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Makefile

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,23 @@ MAINTAINER:="Roman Lomonosov <[email protected]>"
33
DESCRIPTION:="Golang implementation of Graphite/Carbon server"
44
MODULE:=github.com/go-graphite/go-carbon
55

6+
SHELL := bash
7+
.ONESHELL:
8+
.SHELLFLAGS := -eu -o pipefail -c
9+
610
GO ?= go
11+
export GOFLAGS += -mod=vendor
12+
export GO111MODULE := on
713
TEMPDIR:=$(shell mktemp -d)
14+
15+
DEVEL ?= 0
16+
ifeq ($(DEVEL), 0)
817
VERSION:=$(shell sh -c 'grep "const Version" $(NAME).go | cut -d\" -f2')
18+
else
19+
VERSION:=$(shell sh -c 'git describe --always --tags | sed -e "s/^v//i"')
20+
endif
21+
22+
RPM_VERSION:=$(subst -,_,$(VERSION))
923
BUILD ?= $(shell git describe --abbrev=4 --dirty --always --tags)
1024

1125
all: $(NAME)
@@ -25,11 +39,11 @@ test:
2539
make run-test COMMAND="test -race"
2640

2741
gox-build:
28-
rm -rf build
29-
mkdir -p build/root/etc/$(NAME)/
30-
cd build && $(GO) build $(MODULE)
31-
gox -os="linux" -arch="amd64" -arch="386" -arch="arm64" -output="build/$(NAME)-{{.OS}}-{{.Arch}}" $(MODULE)
32-
ls -la ./build/
42+
rm -rf out
43+
mkdir -p out
44+
cd out && $(GO) build $(MODULE) && cd ..
45+
gox -os="linux" -arch="amd64" -arch="386" -arch="arm64" -output="out/$(NAME)-{{.OS}}-{{.Arch}}" $(MODULE)
46+
ls -la ./out/
3347

3448
clean:
3549
rm -f go-carbon build/* *deb *rpm
@@ -39,17 +53,17 @@ image:
3953
docker build -t go-carbon .
4054

4155
package-tree:
42-
install -m 0755 -d build/root/lib/systemd/system
43-
install -m 0755 -d build/root/etc/$(NAME)
44-
install -m 0755 -d build/root/etc/logrotate.d
45-
install -m 0755 -d build/root/etc/init.d
46-
install -m 0644 deploy/$(NAME).service build/root/lib/systemd/system/$(NAME).service
47-
./build/$(NAME)-linux-amd64 -config-print-default > deploy/$(NAME).conf
48-
install -m 0644 deploy/$(NAME).conf build/root/etc/$(NAME)/$(NAME).conf
49-
install -m 0644 deploy/storage-schemas.conf build/root/etc/$(NAME)/storage-schemas.conf
50-
install -m 0644 deploy/storage-aggregation.conf build/root/etc/$(NAME)/storage-aggregation.conf
51-
install -m 0644 deploy/$(NAME).logrotate build/root/etc/logrotate.d/$(NAME)
52-
install -m 0755 deploy/$(NAME).init build/root/etc/init.d/$(NAME)
56+
install -m 0755 -d out/root/lib/systemd/system
57+
install -m 0755 -d out/root/etc/$(NAME)
58+
install -m 0755 -d out/root/etc/logrotate.d
59+
install -m 0755 -d out/root/etc/init.d
60+
install -m 0755 -d out/root/etc/$(NAME)
61+
./out/$(NAME)-linux-amd64 -config-print-default > out/root/etc/$(NAME)/$(NAME).conf
62+
install -m 0644 deploy/$(NAME).service out/root/lib/systemd/system/$(NAME).service
63+
install -m 0644 deploy/storage-schemas.conf out/root/etc/$(NAME)/storage-schemas.conf
64+
install -m 0644 deploy/storage-aggregation.conf out/root/etc/$(NAME)/storage-aggregation.conf
65+
install -m 0644 deploy/$(NAME).logrotate out/root/etc/logrotate.d/$(NAME)
66+
install -m 0755 deploy/$(NAME).init out/root/etc/init.d/$(NAME)
5367

5468
fpm-deb:
5569
make fpm-build-deb ARCH=amd64
@@ -63,7 +77,7 @@ fpm-rpm:
6377

6478
fpm-build-deb:
6579
make package-tree
66-
chmod 0755 build/$(NAME)-linux-$(ARCH)
80+
chmod 0755 out/$(NAME)-linux-$(ARCH)
6781
fpm -s dir -t deb -n $(NAME) -v $(VERSION) \
6882
--deb-priority optional --category admin \
6983
--package $(NAME)_$(VERSION)_$(ARCH).deb \
@@ -79,12 +93,12 @@ fpm-build-deb:
7993
--after-install deploy/after_install.sh \
8094
--after-upgrade deploy/after_install.sh \
8195
--config-files /etc/ \
82-
build/root/=/ \
83-
build/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)
96+
out/root/=/ \
97+
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)
8498

8599
fpm-build-rpm:
86100
make package-tree
87-
chmod 0755 build/$(NAME)-linux-$(ARCH)
101+
chmod 0755 out/$(NAME)-linux-$(ARCH)
88102
fpm -s dir -t rpm -n $(NAME) -v $(VERSION) \
89103
--package $(NAME)-$(VERSION)-1.$(FILE_ARCH).rpm \
90104
--force \
@@ -99,5 +113,39 @@ fpm-build-rpm:
99113
--after-install deploy/after_install.sh \
100114
--after-upgrade deploy/after_install.sh \
101115
--config-files /etc/ \
102-
build/root/=/ \
103-
build/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)
116+
out/root/=/ \
117+
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)
118+
119+
packagecloud-push-rpm: $(wildcard $(NAME)-$(RPM_VERSION)-1.*.rpm)
120+
for pkg in $^; do
121+
package_cloud push $(REPO)/el/7 $${pkg} || true
122+
package_cloud push $(REPO)/el/8 $${pkg} || true
123+
done
124+
125+
packagecloud-push-deb: $(wildcard $(NAME)_$(VERSION)_*.deb)
126+
for pkg in $^; do
127+
package_cloud push $(REPO)/ubuntu/xenial $${pkg} || true
128+
package_cloud push $(REPO)/ubuntu/bionic $${pkg} || true
129+
package_cloud push $(REPO)/ubuntu/focal $${pkg} || true
130+
package_cloud push $(REPO)/debian/stretch $${pkg} || true
131+
package_cloud push $(REPO)/debian/buster $${pkg} || true
132+
package_cloud push $(REPO)/debian/bullseye $${pkg} || true
133+
done
134+
135+
packagecloud-push:
136+
@$(MAKE) packagecloud-push-rpm
137+
@$(MAKE) packagecloud-push-deb
138+
139+
packagecloud-autobuilds:
140+
$(MAKE) packagecloud-push REPO=go-graphite/autobuilds
141+
142+
packagecloud-stable:
143+
$(MAKE) packagecloud-push REPO=go-graphite/stable
144+
145+
sum-files: | sha256sum md5sum
146+
147+
md5sum:
148+
md5sum $(wildcard $(NAME)_$(VERSION)*.deb) $(wildcard $(NAME)-$(VERSION)*.rpm) > md5sum
149+
150+
sha256sum:
151+
sha256sum $(wildcard $(NAME)_$(VERSION)*.deb) $(wildcard $(NAME)-$(VERSION)*.rpm) > sha256sum

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ cd go-carbon
7272
make
7373
```
7474

75+
We are using <a href="https://packagecloud.io/"><img alt="Private Maven, RPM, DEB, PyPi and RubyGem Repository | packagecloud" height="46" src="https://packagecloud.io/images/packagecloud-badge.png" width="158" /></a> to host our packages!
76+
77+
At this moment we are building deb and rpm packages for i386, amd64 and arm64 architectures. Installation guides are available on packagecloud (see the links below).
78+
79+
Stable versions: [Stable repo](https://packagecloud.io/go-graphite/stable/install)
80+
81+
Autobuilds (master, might be unstable): [Autobuild repo](https://packagecloud.io/go-graphite/autobuilds/install)
82+
83+
We're uploading Docker images to [Docker Hub](https://hub.docker.com/repository/docker/gographite/go-carbon/general) and [ghcr.io](https://github.com/go-graphite/go-carbon/pkgs/container/go-carbon)
84+
85+
Also, you can download test packages from build artifacts: Go to list of [test runs](https://github.com/go-graphite/go-carbon/actions/workflows/tests.yml), click on PR name, and click on *"packages-^1"* under *"Artifact"* section.
86+
7587
## Configuration
7688

7789
```

0 commit comments

Comments
 (0)