diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff175c4..17aafc7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,19 +29,11 @@ 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/gox@v1.0.1 - - name: Build packages id: build run: | - make gox-build fpm-deb fpm-rpm + go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.40.0 + make nfpm-deb nfpm-rpm make sum-files ARTIFACTS= # Upload all deb and rpm packages diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a2f1ecd..65af3b2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -75,19 +75,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 - 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/nfpm@v2.40.0 + make DEVEL=1 nfpm-deb nfpm-rpm make sum-files - name: Artifact diff --git a/Makefile b/Makefile index d616dbc..ad99812 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ NAME:=carbon-clickhouse -MAINTAINER:="Roman Lomonosov " DESCRIPTION:="Graphite metrics receiver with ClickHouse as storage" MODULE:=github.com/lomik/carbon-clickhouse @@ -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)) diff --git a/nfpm.yaml b/nfpm.yaml new file mode 100644 index 0000000..d34218a --- /dev/null +++ b/nfpm.yaml @@ -0,0 +1,34 @@ +--- +name: ${NAME} +description: ${DESCRIPTION} + +# Common packages config +arch: "${ARCH}" # amd64, arm64 +platform: "linux" +version: "${VERSION_STRING}" +maintainer: &m "Roman Lomonosov " +vendor: *m +homepage: "https://github.com/go-graphite/${NAME}" +license: "MIT" +section: "admin" +priority: "optional" + +contents: + - src: deploy/root/usr/ + dst: /usr + expand: true + - src: deploy/root/etc/logrotate.d/${NAME} + dst: /etc/logrotate.d/${NAME} + 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 + # docs + - src: LICENSE + dst: /usr/share/doc/${NAME}/LICENSE + expand: true diff --git a/packages.sh b/packages.sh index c061b4d..390b81d 100755 --- a/packages.sh +++ b/packages.sh @@ -1,30 +1,20 @@ -#!/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/nfpm@v2.40.0 cd /root/go/src/github.com/lomik/carbon-clickhouse - 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