diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56b2fd2..5bff7f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,26 @@ jobs: exit 1 fi - run-tests: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - name: Build + run: | + go install github.com/goreleaser/goreleaser/v2@latest + make build + - name: Archive artifacts + uses: actions/upload-artifact@v4 + with: + name: dist + path: | + dist/ + + tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.go-version b/.go-version index 89144db..2a0ba77 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.22.3 +1.22.4 diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..79d5d77 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,59 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + - go mod tidy + - go generate ./... + +builds: + - id: apmsoak + main: ./cmd/apmsoak + binary: apmsoak-{{.Os}}-{{.Arch}} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -X github.com/elastic/apm-perf/internal/version.commitSha={{.FullCommit}} + - -X github.com/elastic/apm-perf/internal/version.buildTime={{.Date}} + no_unique_dist_dir: true + - id: apmbench + main: ./cmd/apmbench + binary: apmbench-{{.Os}}-{{.Arch}} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -X github.com/elastic/apm-perf/internal/version.commitSha={{.FullCommit}} + - -X github.com/elastic/apm-perf/internal/version.buildTime={{.Date}} + no_unique_dist_dir: true + - id: apmtelemetrygen + main: ./cmd/apmtelemetrygen + binary: apmtelemetrygen-{{.Os}}-{{.Arch}} + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -X github.com/elastic/apm-perf/internal/version.commitSha={{.FullCommit}} + - -X github.com/elastic/apm-perf/internal/version.buildTime={{.Date}} + no_unique_dist_dir: true diff --git a/Containerfile b/Containerfile index 037e782..c3b6d1b 100644 --- a/Containerfile +++ b/Containerfile @@ -10,16 +10,11 @@ WORKDIR /opt/apm-perf # Use dedicated layer for Go dependency, cached until they changes COPY go.mod go.sum ./ RUN go mod download +RUN go install github.com/goreleaser/goreleaser/v2@latest # Copy files COPY . . -# Build -ARG TARGETOS TARGETARCH -ENV GOOS=$TARGETOS -ENV GOARCH=$TARGETARCH -ENV CGO_ENABLED=0 - # Leverage mounts to cache relevant Go paths RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ @@ -49,16 +44,19 @@ LABEL \ # Switch workdir WORKDIR /opt/apm-perf +# OS Details +ARG TARGETOS TARGETARCH + # Copy files for apmsoak -COPY --from=builder /opt/apm-perf/dist/apmsoak /usr/bin/apmsoak +COPY --from=builder /opt/apm-perf/dist/apmsoak-${TARGETOS}-${TARGETARCH} /usr/bin/apmsoak COPY ./internal/loadgen/events ./events COPY ./cmd/apmsoak/scenarios.yml /opt/apm-perf/scenarios.yml # Copy files for apmbench -COPY --from=builder /opt/apm-perf/dist/apmbench /usr/bin/apmbench +COPY --from=builder /opt/apm-perf/dist/apmbench-${TARGETOS}-${TARGETARCH} /usr/bin/apmbench # Copy files for apmtelemetrygen -COPY --from=builder /opt/apm-perf/dist/apmtelemetrygen /usr/bin/apmtelemetrygen +COPY --from=builder /opt/apm-perf/dist/apmtelemetrygen-${TARGETOS}-${TARGETARCH} /usr/bin/apmtelemetrygen # Default to apmsoak, override to use apmbench CMD [ "/usr/bin/apmsoak" ] diff --git a/Makefile b/Makefile index df026fc..3d36e7a 100644 --- a/Makefile +++ b/Makefile @@ -23,15 +23,8 @@ clean: rm -fr bin .PHONY: build -build: COMMIT_SHA=$$(git rev-parse HEAD) -build: CURRENT_TIME_ISO=$$(date -u +"%Y-%m-%dT%H:%M:%SZ") -build: LDFLAGS=-X 'github.com/elastic/apm-perf/internal/version.commitSha=$(COMMIT_SHA)' -build: LDFLAGS+=-X 'github.com/elastic/apm-perf/internal/version.buildTime=$(CURRENT_TIME_ISO)' build: - mkdir -p $(DIST_DIR) - go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmsoak cmd/apmsoak/*.go - go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmbench cmd/apmbench/*.go - go build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/apmtelemetrygen cmd/apmtelemetrygen/*.go + goreleaser build --snapshot --clean .PHONY: test test: go.mod