drop makefile in favor of create_bundles.sh script, drop husky patch

This commit is contained in:
Andreas Gerstmayr 2022-09-13 19:49:21 +02:00
parent 95ac515fcf
commit ed6a83eef2
5 changed files with 92 additions and 128 deletions

View File

@ -1,18 +0,0 @@
From fcea701c10eda55164580edceeecb9fbb43c8e90 Mon Sep 17 00:00:00 2001
From: Andreas Gerstmayr <agerstmayr@redhat.com>
Date: Wed, 22 Jun 2022 18:29:42 +0200
Subject: [PATCH] disable husky git hook
diff --git a/package.json b/package.json
index 9c2e666bf2..a00cc73167 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,6 @@
"ci:test-frontend": "yarn run test:ci && yarn grafana-toolkit node-version-check",
"i18n:extract": "lingui extract",
"i18n:compile": "lingui compile",
- "postinstall": "husky install",
"betterer": "betterer",
"betterer:merge": "betterer merge",
"betterer:stats": "ts-node --transpile-only --project ./scripts/cli/tsconfig.json ./scripts/cli/reportBettererStats.ts"

101
Makefile
View File

@ -1,101 +0,0 @@
VERSION := $(shell rpm --specfile *.spec --qf '%{VERSION}\n' | head -1)
RELEASE := $(shell rpm --specfile *.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
CHANGELOGTIME := $(shell rpm --specfile *.spec --qf '%{CHANGELOGTIME}\n' | head -1)
SOURCE_DATE_EPOCH := $(shell echo $$(( $(CHANGELOGTIME) - $(CHANGELOGTIME) % 86400 )))
NAME := grafana
RPM_NAME := $(NAME)
SOURCE_DIR := $(NAME)-$(VERSION)
SOURCE_TAR := $(NAME)-$(VERSION).tar.gz
VENDOR_TAR := $(RPM_NAME)-vendor-$(VERSION)-$(RELEASE).tar.xz
WEBPACK_TAR := $(RPM_NAME)-webpack-$(VERSION)-$(RELEASE).tar.gz
# patches which must be applied before creating the vendor tarball, for example:
# - changes in dependency versions
# - changes in Go module imports (which affect the vendored Go modules)
PATCHES_PRE_VENDOR := \
0004-remove-unused-backend-dependencies.patch \
0005-remove-unused-frontend-crypto.patch \
0007-disable-husky-git-hook.patch \
# patches which must be applied before creating the webpack, for example:
# - changes in Node.js sources or vendored dependencies
PATCHES_PRE_WEBPACK := \
0005-remove-unused-frontend-crypto.patch \
all: $(SOURCE_TAR) $(VENDOR_TAR) $(WEBPACK_TAR)
$(SOURCE_TAR):
spectool -g $(RPM_NAME).spec
$(VENDOR_TAR): $(SOURCE_TAR)
# Start with a clean state
rm -rf $(SOURCE_DIR)
tar pxf $(SOURCE_TAR)
# Patches to apply before vendoring
for patch in $(PATCHES_PRE_VENDOR); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
# Go
cd $(SOURCE_DIR) && go mod vendor -v
# Generate Go files
cd $(SOURCE_DIR) && make gen-go
# Remove unused crypto
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/bcrypt
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/blowfish
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/cast5
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/elgamal
rm $(SOURCE_DIR)/vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
rm -r $(SOURCE_DIR)/vendor/golang.org/x/crypto/pkcs12/internal/rc2
awk '$$2~/^v/ && $$4 != "indirect" {print "Provides: bundled(golang(" $$1 ")) = " substr($$2, 2)}' $(SOURCE_DIR)/go.mod | \
sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > $@.manifest
# Node.js
cd $(SOURCE_DIR) && yarn install --frozen-lockfile
# Remove files with licensing issues
find $(SOURCE_DIR)/.yarn -name 'node-notifier' -prune -exec rm -r {} \;
find $(SOURCE_DIR)/.yarn -name 'nodemon' -prune -exec rm -r {} \;
#rm -r $(SOURCE_DIR)/node_modules/visjs-network/examples
./list_bundled_nodejs_packages.py $(SOURCE_DIR) >> $@.manifest
# Create tarball
XZ_OPT=-9 tar \
--sort=name \
--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-cJf $@ \
$(SOURCE_DIR)/vendor \
$$(find $(SOURCE_DIR) -type f -name "wire_gen.go" | LC_ALL=C sort) \
$(SOURCE_DIR)/.pnp.cjs \
$(SOURCE_DIR)/.yarn/cache \
$(SOURCE_DIR)/.yarn/unplugged
$(WEBPACK_TAR): $(VENDOR_TAR)
# Start with a clean state
rm -rf $(SOURCE_DIR)
tar pxf $(SOURCE_TAR)
tar pxf $(VENDOR_TAR)
# Patches to apply before creating the webpack
for patch in $(PATCHES_PRE_WEBPACK); do echo applying $$patch ...; patch -d $(SOURCE_DIR) -p1 --fuzz=0 < $$patch; done
# Build frontend
cd $(SOURCE_DIR) && \
../build_frontend.sh
# Create tarball
tar \
--sort=name \
--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-czf $@ \
$(SOURCE_DIR)/plugins-bundled \
$(SOURCE_DIR)/public/build \
$(SOURCE_DIR)/public/img \
$(SOURCE_DIR)/public/lib \
$(SOURCE_DIR)/public/locales \
$(SOURCE_DIR)/public/views
clean:
rm -rf *.tar.gz *.tar.xz *.manifest *.rpm $(NAME)-*/

85
create_bundles.sh Executable file
View File

@ -0,0 +1,85 @@
#!/bin/bash -eux
VERSION=$(rpm --specfile ./*.spec --qf '%{VERSION}\n' | head -1)
RELEASE=$(rpm --specfile ./*.spec --qf '%{RELEASE}\n' | head -1 | cut -d. -f1)
CHANGELOGTIME=$(rpm --specfile ./*.spec --qf '%{CHANGELOGTIME}\n' | head -1)
SOURCE_DATE_EPOCH=$((CHANGELOGTIME - CHANGELOGTIME % 86400))
SOURCE_DIR=grafana-$VERSION
SOURCE_TAR=grafana-$VERSION.tar.gz
VENDOR_TAR=grafana-vendor-$VERSION-$RELEASE.tar.xz
WEBPACK_TAR=grafana-webpack-$VERSION-$RELEASE.tar.gz
## Download and extract source tarball
spectool -g grafana.spec
rm -rf "${SOURCE_DIR}"
tar xf "${SOURCE_TAR}"
## Create vendor bundle
pushd "${SOURCE_DIR}"
# Vendor Go dependencies
patch -p1 --fuzz=0 < ../0004-remove-unused-backend-dependencies.patch
go mod vendor
# Generate Go files
make gen-go
# Remove unused crypto
rm -r vendor/golang.org/x/crypto/bcrypt
rm -r vendor/golang.org/x/crypto/blowfish
rm -r vendor/golang.org/x/crypto/cast5
rm -r vendor/golang.org/x/crypto/openpgp/elgamal
rm vendor/golang.org/x/crypto/openpgp/packet/ocfb.go
rm -r vendor/golang.org/x/crypto/pkcs12/internal/rc2
# List bundled dependencies
awk '$2 ~ /^v/ && $4 != "indirect" {print "Provides: bundled(golang(" $1 ")) = " substr($2, 2)}' go.mod | \
sed -E 's/=(.*)-(.*)-(.*)/=\1-\2.\3/g' > "../${VENDOR_TAR}.manifest"
# Vendor Node.js dependencies
patch -p1 --fuzz=0 < ../0005-remove-unused-frontend-crypto.patch
export HUSKY=0
yarn install --frozen-lockfile
# Remove files with licensing issues
find .yarn -name 'node-notifier' -prune -exec rm -r {} \;
find .yarn -name 'nodemon' -prune -exec rm -r {} \;
# List bundled dependencies
../list_bundled_nodejs_packages.py . >> "../${VENDOR_TAR}.manifest"
popd
# Create tarball
# shellcheck disable=SC2046
XZ_OPT=-9 tar \
--sort=name \
--mtime="@${SOURCE_DATE_EPOCH}" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-cJf "${VENDOR_TAR}" \
"${SOURCE_DIR}/vendor" \
$(find "${SOURCE_DIR}" -type f -name wire_gen.go | LC_ALL=C sort) \
"${SOURCE_DIR}/.pnp.cjs" \
"${SOURCE_DIR}/.yarn/cache" \
"${SOURCE_DIR}/.yarn/unplugged"
## Create webpack
pushd "${SOURCE_DIR}"
../build_frontend.sh
popd
# Create tarball
tar \
--sort=name \
--mtime="@${SOURCE_DATE_EPOCH}" --clamp-mtime \
--owner=0 --group=0 --numeric-owner \
-czf "${WEBPACK_TAR}" \
"${SOURCE_DIR}/plugins-bundled" \
"${SOURCE_DIR}/public/build" \
"${SOURCE_DIR}/public/img" \
"${SOURCE_DIR}/public/lib" \
"${SOURCE_DIR}/public/locales" \
"${SOURCE_DIR}/public/views"

View File

@ -1,6 +1,6 @@
#!/bin/bash -eu
#
# create vendor and webpack bundles inside a container for reproducibility
# create vendor and webpack bundles inside a container (for reproducibility)
# using a Go cache:
# ./create_bundles_in_container.sh --security-opt label=disable -v $(pwd)/.gocache:/root/go
#
@ -15,9 +15,9 @@ RUN dnf upgrade -y && \
ENV GOPROXY=https://proxy.golang.org,direct
WORKDIR /tmp/grafana-build
COPY Makefile grafana.spec *.patch build_frontend.sh list_bundled_nodejs_packages.py .
COPY grafana.spec create_bundles.sh build_frontend.sh list_bundled_nodejs_packages.py *.patch .
RUN mkdir bundles
CMD make && mv *.tar.* bundles
CMD ./create_bundles.sh && mv *.tar.* bundles
EOF
podman run --name grafana-build --replace "$@" grafana-build

View File

@ -46,8 +46,8 @@ Source2: grafana-webpack-%{version}-1.tar.gz
# Source3 contains the systemd-sysusers configuration
Source3: grafana.sysusers
# Source4 contains the Makefile to create the vendor and webpack bundles
Source4: Makefile
# Source4 contains the script to create the vendor and webpack bundles
Source4: create_bundles.sh
# Source5 contains the script to build the frontend
Source5: build_frontend.sh
@ -66,7 +66,6 @@ Patch4: 0004-remove-unused-backend-dependencies.patch
Patch5: 0005-remove-unused-frontend-crypto.patch
# https://github.com/grafana/grafana/pull/42334
Patch6: 0006-notifications-use-HMAC-SHA256-to-generate-password-r.patch
Patch7: 0007-disable-husky-git-hook.patch
Patch8: 0008-skip-marketplace-plugin-install-test.patch
# https://github.com/grafana/grafana/pull/51508
Patch9: 0009-Prometheus-Fix-integer-overflow-in-rate-interval-cal.patch
@ -704,7 +703,6 @@ rm -r plugins-bundled
%if 0%{?fedora} || 0%{?rhel} > 8
%patch6 -p1
%endif
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
@ -726,7 +724,7 @@ rm -r plugins-bundled
# Build the backend
# see grafana-X.X.X/build.go
# see grafana-X.Y.Z/pkg/build/cmd.go
export LDFLAGS="-X main.version=%{version} -X main.buildstamp=${SOURCE_DATE_EPOCH}"
for cmd in grafana-cli grafana-server; do
%gobuild -o %{_builddir}/bin/${cmd} ./pkg/cmd/${cmd}
@ -833,7 +831,7 @@ yarn run jest
# Test backend
# in setting_test.go there is a unit test which checks if 10 days are 240 hours
# which is usually true except if the dayligt saving time change falls into the last 10 days, then it's either 239 or 241 hours...
# which is usually true except if the daylight saving time change falls into the last 10 days, then it's either 239 or 241 hours...
# let's set the time zone to a time zone without daylight saving time
export TZ=GMT