reworks snap build with docker (#1910)

This commit is contained in:
Nikolay 2021-12-08 14:05:35 +03:00 committed by GitHub
parent 896fa9bb7c
commit a581a93c9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 9 deletions

View file

@ -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)

9
snap/local/Dockerfile Normal file
View file

@ -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
snap/local/Makefile Normal file
View file

@ -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'

View file

@ -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`

View file

@ -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