Skip to content

Commit

Permalink
feat: fetch precompiled xk6 extension from grafana/xk6-sm (#966)
Browse files Browse the repository at this point in the history
* Dockerfiles: ADD sm-k6 from grafana/xk6-sm releases

* renovate: upgrade grafana/xk6-sm releases URLs

* make: add target to pull sm-k6 from grafana/xk6-sm repo

* renovate: update xk6-sm version in makefile

* scripts/package: source sm-k6 binary from current path

* xk6: remove source tree and make targets

* ci: call `make sm-k6` for workflows that need a k6 binary

* prober/multihttp: use k6 binary from dest repo for `make sm-k6`
  • Loading branch information
nadiamoe authored Jan 23, 2025
1 parent 24e2a41 commit 0a57fad
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 1,555 deletions.
12 changes: 8 additions & 4 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
],
"customManagers": [
{
// Update k6 version in Dockerfiles.
// Update xk6-sm
"customType": "regex",
"depNameTemplate": "grafana/xk6-sm",
"datasourceTemplate": "github-releases",
"depNameTemplate": "grafana/k6",
"fileMatch": [".*\\.mk"],
"versioningTemplate": "semver",
"fileMatch": [
"Dockerfile",
"scripts/make/sm-k6.mk"
],
"matchStrings": [
"(?:^|\\n)[ \\t]*K6_VERSION\\s*:=\\s*(?<currentValue>\\S+)[ \\t]*(?:$|\\n)"
"https://github.com/grafana/xk6-sm/releases/download/(?<currentValue>[^/]+)/"
]
}
]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build_and_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ jobs:
- name: build
run: make build-native

- name: Download sm-k6
run: make sm-k6-native

- name: lint
run: make lint

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/validate_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
- name: build
run: make build-native

- name: Download sm-k6
run: make sm-k6-native

- name: lint
run: make lint

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ARG TARGETOS
ARG TARGETARCH
ARG HOST_DIST=$TARGETOS-$TARGETARCH

ADD --chmod=0555 https://github.com/grafana/xk6-sm/releases/download/v0.0.3-pre/sm-k6-${TARGETOS}-${TARGETARCH} /usr/local/bin/sm-k6
COPY dist/${HOST_DIST}/synthetic-monitoring-agent /usr/local/bin/synthetic-monitoring-agent
COPY dist/${HOST_DIST}/k6 /usr/local/bin/sm-k6
COPY scripts/pre-stop.sh /usr/local/lib/synthetic-monitoring-agent/pre-stop.sh
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ARG TARGETOS
ARG TARGETARCH
ARG HOST_DIST=$TARGETOS-$TARGETARCH

ADD --chmod=0555 https://github.com/grafana/xk6-sm/releases/download/v0.0.3-pre/sm-k6-${TARGETOS}-${TARGETARCH} /usr/local/bin/sm-k6
COPY dist/${HOST_DIST}/synthetic-monitoring-agent /usr/local/bin/synthetic-monitoring-agent
COPY dist/${HOST_DIST}/k6 /usr/local/bin/sm-k6
COPY scripts/pre-stop.sh /usr/local/lib/synthetic-monitoring-agent/pre-stop.sh
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ include $(ROOTDIR)/scripts/make/build.mk
include $(ROOTDIR)/scripts/make/testing.mk
include $(ROOTDIR)/scripts/make/linters.mk
include $(ROOTDIR)/scripts/make/release.mk
include $(ROOTDIR)/scripts/make/sm-k6.mk
include $(ROOTDIR)/scripts/make/helpers.mk
include $(ROOTDIR)/scripts/make/xk6.mk
4 changes: 3 additions & 1 deletion internal/prober/multihttp/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -852,7 +853,8 @@ func TestSettingsToScript(t *testing.T) {
t.Cleanup(cancel)
// logger := zerolog.New(zerolog.NewTestWriter(t))
logger := zerolog.Nop()
k6path := filepath.Join(testhelper.ModuleDir(t), "dist", "k6")
k6path := filepath.Join(testhelper.ModuleDir(t), "dist", runtime.GOOS+"-"+runtime.GOARCH, "sm-k6")
t.Log(k6path)
runner := k6runner.New(k6runner.RunnerOpts{Uri: k6path})

prober, err := NewProber(ctx, check, logger, runner, http.Header{})
Expand Down
21 changes: 21 additions & 0 deletions scripts/make/sm-k6.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
XK6_PLATFORMS := $(filter-out linux/arm,$(PLATFORMS)) darwin/arm64 darwin/amd64

.PHONY: sm-k6
sm-k6:
@true

define sm-k6
$(DISTDIR)/$(1)-$(2)/sm-k6:
mkdir -p "$(DISTDIR)/$(1)-$(2)"
# Renovate updates the following line. Keep its syntax as it is.
curl -sSL https://github.com/grafana/xk6-sm/releases/download/v0.0.3/sm-k6-$(1)-$(2) -o "$$@"
chmod +x "$$@"

sm-k6: $(DISTDIR)/$(1)-$(2)/sm-k6
endef

$(foreach BUILD_PLATFORM,$(XK6_PLATFORMS), \
$(eval $(call sm-k6,$(word 1,$(subst /, ,$(BUILD_PLATFORM))),$(word 2,$(subst /, ,$(BUILD_PLATFORM))))))

.PHONY: sm-k6-native
sm-k6-native: $(DISTDIR)/$(HOST_OS)-$(HOST_ARCH)/sm-k6
1 change: 0 additions & 1 deletion scripts/make/vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ ifeq ($(USE_LOCAL_TOOLS),true)
GOLANGCI_LINT := golangci-lint
GOTESTSUM := gotestsum
SHELLCHECK := shellcheck
XK6 := xk6
endif
88 changes: 0 additions & 88 deletions scripts/make/xk6.mk

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/package/nfpm.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contents:
dst: /etc/systemd/system/synthetic-monitoring-agent.service

# Copy k6 as sm-k6 to prevent clashing with k6 if it's installed.
- src: {{.DISTDIR}}/{{.Os}}-{{.Arch}}/k6
- src: {{.DISTDIR}}/{{.Os}}-{{.Arch}}/sm-k6
dst: /usr/bin/sm-k6
rpm:
deb:
Loading

0 comments on commit 0a57fad

Please sign in to comment.