Skip to content

Commit

Permalink
reworks snap build with docker (VictoriaMetrics#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
f41gh7 authored Dec 8, 2021
1 parent 896fa9b commit a581a93
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ all: \

include app/*/Makefile
include deployment/*/Makefile
include snap/local/Makefile


clean:
rm -rf bin/*
Expand Down Expand Up @@ -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 && \
Expand Down Expand Up @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions snap/local/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}"

31 changes: 31 additions & 0 deletions snap/local/Makefile
Original file line number Diff line number Diff line change
@@ -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'

10 changes: 6 additions & 4 deletions snap/local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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/`
Data folder located at `/var/snap/victoriametrics/current/var/lib/victoriametrics/`
7 changes: 5 additions & 2 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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: |
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a581a93

Please sign in to comment.