Skip to content

Commit

Permalink
Migrate packages building to nfpm and pure go build
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Oct 9, 2024
1 parent a26d347 commit 4681553
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 87 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,10 @@ jobs:
env:
CGO_ENABLED: 1

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
- name: Install packaging dependencies
run: |
gem install fpm package_cloud
cd && go install github.com/mitchellh/[email protected]
- name: Build packages
id: build
run: |
make gox-build fpm-deb fpm-rpm
make nfpm-deb nfpm-rpm
make sum-files
ARTIFACTS=
# Upload all deb and rpm packages
Expand Down
12 changes: 1 addition & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,9 @@ jobs:
# env:
# CGO_ENABLED: 1

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.

- name: Install packaging dependencies
run: |
gem install fpm package_cloud
go install github.com/mitchellh/gox@latest
- name: Check packaging
run: |
make DEVEL=1 gox-build fpm-deb fpm-rpm
make DEVEL=1 nfpm-deb nfpm-rpm
make sum-files
- name: Artifact
Expand Down
69 changes: 23 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
NAME:=carbon-clickhouse
MAINTAINER:="Roman Lomonosov <[email protected]>"
DESCRIPTION:="Graphite metrics receiver with ClickHouse as storage"
DESCRIPTION:=Graphite metrics receiver with ClickHouse as storage
MODULE:=github.com/lomik/carbon-clickhouse

GO ?= go
Expand Down Expand Up @@ -36,51 +35,29 @@ e2e-test: $(NAME)
test:
$(GO) test -race ./...

gox-build:
rm -rf out
gox-build: out/$(NAME)-linux-amd64 out/$(NAME)-linux-arm64 out/root/etc/$(NAME)/$(NAME).conf

ARCH = amd64 arm64
out/$(NAME)-linux-%: out $(SRCS)
GOOS=linux GOARCH=$* $(GO) build -o $@ $(MODULE)

out:
mkdir -p out
gox -os="linux" -arch="amd64" -arch="arm64" -output="out/$(NAME)-{{.OS}}-{{.Arch}}" github.com/lomik/$(NAME)
ls -la out/
mkdir -p out/root/etc/$(NAME)/
./out/$(NAME)-linux-amd64 -config-print-default > out/root/etc/$(NAME)/$(NAME).conf

fpm-deb:
$(MAKE) fpm-build-deb ARCH=amd64
$(MAKE) fpm-build-deb ARCH=arm64
fpm-rpm:
$(MAKE) fpm-build-rpm ARCH=amd64
$(MAKE) fpm-build-rpm ARCH=arm64

fpm-build-deb:
fpm -s dir -t deb -n $(NAME) -v $(VERSION) \
--deb-priority optional --category admin \
--force \
--url https://github.com/lomik/$(NAME) \
--description $(DESCRIPTION) \
-m $(MAINTAINER) \
--license "MIT" \
-a $(ARCH) \
--config-files /etc/$(NAME)/$(NAME).conf \
--config-files /etc/logrotate.d/$(NAME) \
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME) \
deploy/root/=/ \
out/root/=/


fpm-build-rpm:
fpm -s dir -t rpm -n $(NAME) -v $(VERSION) \
--force \
--rpm-compression bzip2 --rpm-os linux \
--url https://github.com/lomik/$(NAME) \
--description $(DESCRIPTION) \
-m $(MAINTAINER) \
--license "MIT" \
-a $(ARCH) \
--config-files /etc/$(NAME)/$(NAME).conf \
--config-files /etc/logrotate.d/$(NAME) \
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME) \
deploy/root/=/ \
out/root/=/


out/root/etc/$(NAME)/$(NAME).conf: $(NAME)
mkdir -p "$(shell dirname $@)"
./$(NAME) -config-print-default > $@

nfpm-deb: gox-build
$(MAKE) nfpm-build-deb ARCH=amd64
$(MAKE) nfpm-build-deb ARCH=arm64
nfpm-rpm: gox-build
$(MAKE) nfpm-build-rpm ARCH=amd64
$(MAKE) nfpm-build-rpm ARCH=arm64

nfpm-build-%: nfpm.yaml
NAME=$(NAME) DESCRIPTION="$(DESCRIPTION)" ARCH=$(ARCH) VERSION_STRING=$(VERSION) nfpm package --packager $*

.ONESHELL:
RPM_VERSION:=$(subst -,_,$(VERSION))
Expand Down
27 changes: 7 additions & 20 deletions packages.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
#!/bin/sh
#!/bin/sh -e

cd `dirname $0`
cd "$( dirname "$0" )"
ROOT=$PWD

docker run -ti -e "DEVEL=${DEVEL:-0}" --rm -v $ROOT:/root/go/src/github.com/lomik/carbon-clickhouse ubuntu:20.04 bash -c '
docker run -i -e "DEVEL=${DEVEL:-0}" --rm -v "$ROOT:/root/go/src/github.com/lomik/carbon-clickhouse" golang bash -e << 'EOF'
cd /root/
export GO_VERSION=1.15.1
export TZ=Europe/Moscow
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
apt update
DEBIAN_FRONTEND=noninteractive apt install -y rpm ruby ruby-dev wget make git gcc
wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
ln -s /usr/local/go/bin/go /usr/local/bin/go
# newer fpm is broken https://github.com/jordansissel/fpm/issues/1612
gem install rake
gem install fpm:1.10.2
go get github.com/mitchellh/gox
ln -s /root/go/bin/gox /usr/local/bin/gox
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
cd /root/go/src/github.com/lomik/carbon-clickhouse
make gox-build
make fpm-deb
make fpm-rpm
'
make nfpm-deb nfpm-rpm
chmod -R a+w *.deb *.rpm out/
EOF

0 comments on commit 4681553

Please sign in to comment.