Skip to content

Commit

Permalink
Merge pull request #644 from deniszh/dzhdanov/pkg-fix
Browse files Browse the repository at this point in the history
Migrate to nfpm, get rid of gox
  • Loading branch information
deniszh authored Oct 11, 2024
2 parents a8c1c8b + 733c5c3 commit 0787a9b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.58.2
version: v1.61.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,11 @@ jobs:
env:
CGO_ENABLED: 1

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7" # Version range or exact version of a Ruby version to use, using semvers version range syntax.
- name: Install packaging dependencies
run: |
gem install dotenv -v 2.8.1
gem install rake fpm:1.10.2 package_cloud
GO111MODULE=off go get github.com/mitchellh/gox
- name: Build packages
id: build
run: |
make gox-build fpm-deb fpm-rpm
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
make nfpm-deb nfpm-rpm
make sum-files
ARTIFACTS=
# Upload all deb and rpm packages
Expand Down
13 changes: 2 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,10 @@ jobs:
run: |
make image
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Install packaging dependencies
run: |
gem install rake fpm package_cloud
go install github.com/mitchellh/gox@latest
- name: Check packaging
run: |
make DEVEL=1 gox-build fpm-deb fpm-rpm
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
make DEVEL=1 nfpm-deb nfpm-rpm
make sum-files
- name: Upload Artifact
Expand Down
81 changes: 24 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
NAME:=go-carbon
MAINTAINER:="Roman Lomonosov <[email protected]>"
DESCRIPTION:="Golang implementation of Graphite/Carbon server"
MODULE:=github.com/go-graphite/go-carbon

Expand All @@ -21,6 +20,8 @@ endif
RPM_VERSION:=$(subst -,_,$(VERSION))
BUILD ?= $(shell git describe --abbrev=4 --dirty --always --tags)

SRCS:=$(shell find . -name '*.go')

all: $(NAME)

$(NAME):
Expand All @@ -40,12 +41,14 @@ test:
make run-test COMMAND="vet"
make run-test COMMAND="test -race"

gox-build:
rm -rf out
gox-build: out/$(NAME)-linux-386 out/$(NAME)-linux-amd64 out/$(NAME)-linux-arm64

ARCH = 386 amd64 arm64
out/$(NAME)-linux-%: out $(SRCS)
GOOS=linux GOARCH=$* $(GO) build -ldflags '-X main.BuildVersion=$(VERSION)' -o $@ $(MODULE)

out:
mkdir -p out
cd out && $(GO) build $(MODULE) && cd ..
gox -os="linux" -arch="amd64" -arch="386" -arch="arm64" -output="out/$(NAME)-{{.OS}}-{{.Arch}}" $(MODULE)
ls -la ./out/

clean:
rm -f go-carbon build/* *deb *rpm
Expand All @@ -67,68 +70,32 @@ package-tree:
install -m 0644 deploy/$(NAME).logrotate out/root/etc/logrotate.d/$(NAME)
install -m 0755 deploy/$(NAME).init out/root/etc/init.d/$(NAME)

fpm-deb:
make fpm-build-deb ARCH=amd64
make fpm-build-deb ARCH=386
make fpm-build-deb ARCH=arm64

fpm-rpm:
make fpm-build-rpm ARCH=amd64 FILE_ARCH=x86_64
make fpm-build-rpm ARCH=386 FILE_ARCH=386
make fpm-build-rpm ARCH=arm64 FILE_ARCH=arm64

fpm-build-deb:
make package-tree
chmod 0755 out/$(NAME)-linux-$(ARCH)
fpm -s dir -t deb -n $(NAME) -v $(VERSION) \
--deb-priority optional --category admin \
--package $(NAME)_$(VERSION)_$(ARCH).deb \
--force \
--deb-compression bzip2 \
--url https://github.com/go-graphite/$(NAME) \
--description $(DESCRIPTION) \
-m $(MAINTAINER) \
--license "MIT" \
-a $(ARCH) \
--before-install deploy/before_install.sh \
--before-upgrade deploy/before_install.sh \
--after-install deploy/after_install.sh \
--after-upgrade deploy/after_install.sh \
--config-files /etc/ \
out/root/=/ \
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)

fpm-build-rpm:
make package-tree
chmod 0755 out/$(NAME)-linux-$(ARCH)
fpm -s dir -t rpm -n $(NAME) -v $(VERSION) \
--package $(NAME)-$(VERSION)-1.$(FILE_ARCH).rpm \
--force \
--rpm-compression bzip2 --rpm-os linux \
--url https://github.com/go-graphite/$(NAME) \
--description $(DESCRIPTION) \
-m $(MAINTAINER) \
--license "MIT" \
-a $(ARCH) \
--before-install deploy/before_install.sh \
--before-upgrade deploy/before_install.sh \
--after-install deploy/after_install.sh \
--after-upgrade deploy/after_install.sh \
--config-files /etc/ \
out/root/=/ \
out/$(NAME)-linux-$(ARCH)=/usr/bin/$(NAME)
nfpm-deb: gox-build package-tree
$(MAKE) nfpm-build-deb ARCH=386
$(MAKE) nfpm-build-deb ARCH=amd64
$(MAKE) nfpm-build-deb ARCH=arm64

nfpm-rpm: gox-build package-tree
$(MAKE) nfpm-build-rpm ARCH=386
$(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 $*

packagecloud-push-rpm: $(wildcard $(NAME)-$(RPM_VERSION)-1.*.rpm)
for pkg in $^; do
package_cloud push $(REPO)/el/7 $${pkg} || true
package_cloud push $(REPO)/el/8 $${pkg} || true
package_cloud push $(REPO)/el/9 $${pkg} || true
done

packagecloud-push-deb: $(wildcard $(NAME)_$(VERSION)_*.deb)
for pkg in $^; do
package_cloud push $(REPO)/ubuntu/xenial $${pkg} || true
package_cloud push $(REPO)/ubuntu/bionic $${pkg} || true
package_cloud push $(REPO)/ubuntu/focal $${pkg} || true
package_cloud push $(REPO)/ubuntu/jammy $${pkg} || true
package_cloud push $(REPO)/ubuntu/noble $${pkg} || true
package_cloud push $(REPO)/debian/stretch $${pkg} || true
package_cloud push $(REPO)/debian/buster $${pkg} || true
package_cloud push $(REPO)/debian/bullseye $${pkg} || true
Expand Down
47 changes: 47 additions & 0 deletions nfpm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: ${NAME}
description: ${DESCRIPTION}

# Common packages config
arch: "${ARCH}" # 386, amd64, arm64
platform: "linux"
version: "${VERSION_STRING}"
maintainer: &m "Roman Lomonosov <[email protected]>"
vendor: *m
homepage: "https://github.com/go-graphite/${NAME}"
license: "MIT"
section: "admin"
priority: "optional"

scripts:
preinstall: deploy/before_install.sh
postinstall: deploy/after_install.sh

contents:
- src: out/root/etc/init.d/${NAME}
dst: /etc/init.d/${NAME}
type: config|noreplace
expand: true
- src: out/root/lib/systemd/system/${NAME}.service
dst: /lib/systemd/system/${NAME}.service
type: config|noreplace
expand: true
- src: out/root/etc/logrotate.d/${NAME}
dst: /etc/logrotate.d/${NAME}
type: config|noreplace
expand: true
- src: out/root/etc/${NAME}/storage-schemas.conf
dst: /etc/${NAME}/storage-schemas.conf
type: config|noreplace
expand: true
- src: out/root/etc/${NAME}/storage-aggregation.conf
dst: /etc/${NAME}/storage-aggregation.conf
type: config|noreplace
expand: true
- src: out/root/etc/${NAME}/${NAME}.conf
dst: /etc/${NAME}/${NAME}.conf
type: config|noreplace
expand: true
- src: "out/${NAME}-linux-${ARCH}"
dst: /usr/bin/${NAME}
expand: true
27 changes: 10 additions & 17 deletions packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
cd `dirname $0`
ROOT=$PWD

docker run -ti --rm -v $ROOT:/root/go/src/github.com/go-graphite/go-carbon ubuntu:20.04 bash -c '
docker run -i -e "DEVEL=${DEVEL:-0}" --rm -v "$ROOT:/root/go/src/github.com/go-graphite/go-carbon" golang bash -e << 'EOF'
cd /root/
export GO_VERSION=1.17
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get update
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y rpm ruby ruby-dev wget build-essential
export TZ=Europe/Amsterdam
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
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 fpm:1.10.2 package_cloud
go install github.com/mitchellh/gox@latest
ln -s /root/go/bin/gox /usr/bin/gox
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
cd /root/go/src/github.com/go-graphite/go-carbon
make gox-build
make fpm-deb
make fpm-rpm
'
# go reads the VCS state
git config --global --add safe.directory "$PWD"
make nfpm-deb nfpm-rpm
chmod -R a+w *.deb *.rpm out/
EOF

0 comments on commit 0787a9b

Please sign in to comment.