diff --git a/Makefile b/Makefile index 6d5059be8..51f99edf0 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ all: \ include app/*/Makefile include deployment/*/Makefile +include snap/local/Makefile + clean: rm -rf bin/* @@ -84,9 +86,6 @@ vmutils-windows-amd64: \ vmauth-windows-amd64 \ vmctl-windows-amd64 -release-snap: - snapcraft - snapcraft upload "victoriametrics_$(PKG_TAG)_multi.snap" --release beta,edge,candidate publish-release: git checkout $(TAG) && $(MAKE) release publish && \ @@ -180,6 +179,7 @@ release-vmutils-windows-generic: \ vmctl-windows-$(GOARCH)-prod.exe \ > vmutils-windows-$(GOARCH)-$(PKG_TAG)_checksums.txt + pprof-cpu: go tool pprof -trim_path=github.com/VictoriaMetrics/VictoriaMetrics@ $(PPROF_FILE) diff --git a/snap/local/Dockerfile b/snap/local/Dockerfile new file mode 100644 index 000000000..4da9df08e --- /dev/null +++ b/snap/local/Dockerfile @@ -0,0 +1,9 @@ +FROM snapcore/snapcraft:stable +ARG GO_VERSION +RUN apt-get update && apt-get install -y git make wget binutils build-essential bzip2 cpp cpp-5 dpkg-dev fakeroot g++ g++-5 gcc gcc-5 + +RUN cd /usr/local &&\ + wget https://dl.google.com/go/go1.17.3.linux-amd64.tar.gz &&\ + tar -zxvf go$GO_VERSION.linux-amd64.tar.gz && rm go$GO_VERSION.linux-amd64.tar.gz +ENV PATH="/usr/local/go/bin:${PATH}" + diff --git a/snap/local/Makefile b/snap/local/Makefile new file mode 100644 index 000000000..bb109429f --- /dev/null +++ b/snap/local/Makefile @@ -0,0 +1,31 @@ +GO_VERSION ?=1.17.3 +SNAP_BUILDER_IMAGE := local/snap-builder:2.0.0-$(shell echo $(GO_VERSION) | tr :/ __) + + +# truncate pkg_tag, snap has limitations for name length +SNAP_TAG := $(shell echo "$(PKG_TAG)" | cut -b1-31 ) + +snap-builder-image: + (docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(SNAP_BUILDER_IMAGE)$$') \ + || docker build \ + --build-arg GO_VERSION=$(GO_VERSION) \ + --tag $(SNAP_BUILDER_IMAGE) \ + snap/local + +build-snap: snap-builder-image + docker run --rm \ + --mount type=bind,src="$(shell pwd)",dst=/builder \ + -w /builder \ + --env PKG_TAG=$(SNAP_TAG) \ + $(SNAP_BUILDER_IMAGE) \ + bash -c 'snapcraft clean && snapcraft snap -o bin/' + +release-snap: snap-builder-image build-snap + docker run --rm \ + --mount type=bind,src=${HOME}/.snap,dst=/root/.snap \ + --mount type=bind,src="$(shell pwd)",dst=/builder \ + -w /builder \ + --env PKG_TAG=$(SNAP_TAG) \ + $(SNAP_BUILDER_IMAGE) \ + bash -c 'snapcraft login --with /root/.snap/login.json && snapcraft upload "bin/victoriametrics_$(SNAP_TAG)_multi.snap" --release beta,edge,candidate,stable' + diff --git a/snap/local/README.md b/snap/local/README.md index 64952ee25..e7cc1be7c 100644 --- a/snap/local/README.md +++ b/snap/local/README.md @@ -7,12 +7,14 @@ snap link: https://snapcraft.io/victoriametrics #### develop -Install snapcraft and multipass: +Install snapcraft or docker + +build snap package with command + ```text -sudo snap install snapcraft --classic +make build-snap ``` -build victoria-metrics prod binary and run snapcraft ```snapcraft --debug```. It produces snap package with current git version - `victoriametrics_v1.46.0+git1.1bebd021a-dirty_all.snap`. You can install it with command: `snap install victoriametrics_v1.46.0+git1.1bebd021a-dirty_all.snap --dangerous` @@ -44,4 +46,4 @@ echo 'FLAGS="-selfScrapeInterval=10s -search.logSlowQueryDuration=20s"' > /var/s snap restart victoriametrics ``` -Data folder located at `/var/snap/victoriametrics/current/var/lib/victoriametrics/` \ No newline at end of file +Data folder located at `/var/snap/victoriametrics/current/var/lib/victoriametrics/` diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 136859821..2ed7920fe 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,6 +1,6 @@ name: victoriametrics base: core18 -version: git +adopt-info: build icon: logo.png summary: VictoriaMetrics is fast, cost-effective and scalable time-series database. description: | @@ -51,7 +51,7 @@ confinement: strict # use 'strict' once you have the right plugs and slots parts: build: plugin: go - go-channel: 1.16/stable + go-channel: 1.17/stable go-importpath: github.com/VictoriaMetrics/VictoriaMetrics source: . source-type: local @@ -61,6 +61,9 @@ parts: mkdir -p $SNAPCRAFT_PART_INSTALL/bin cp -p $SNAPCRAFT_PART_BUILD/bin/victoria-metrics $SNAPCRAFT_PART_INSTALL/bin/ cp -p $SNAPCRAFT_PART_SRC/snap/local/victoriametrics-wrapper $SNAPCRAFT_PART_INSTALL/bin/ + override-pull: | + snapcraftctl set-version "$PKG_TAG" + snapcraftctl pull apps: victoriametrics: command: bin/victoriametrics-wrapper