Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add artifacts to builds, add docker hub automatic releases, add githu… #40

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 18 additions & 27 deletions .github/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project_name: kvrocks-exporter
release:
github:
owner: KvrocksLabs
owner: RocksLabs
name: kvrocks_exporter

builds:
Expand All @@ -13,32 +13,23 @@ builds:
- "-X main.BuildCommitSha={{.Commit}}"
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
dockers:
- id: kvrocks-exporter-docker-amd64
goos: linux
goarch: amd64
ids:
- kvrocks-exporter
image_templates:
- "kvrocks/kvrocks-exporter:v{{ .Version }}-amd64"
build_flag_templates:
- "--platform=linux/amd64"
use: buildx
- id: kvrocks-exporter-docker-arm64
goos: linux
goarch: arm64
ids:
- kvrocks-exporter
image_templates:
- "kvrocks/kvrocks-exporter:v{{ .Version }}-arm64"
build_flag_templates:
- "--platform=linux/arm64"
use: buildx
docker_manifests:
- name_template: kvrocks/kvrocks-exporter:v{{ .Version }}
image_templates:
- kvrocks/kvrocks-exporter:v{{ .Version }}-amd64
- kvrocks/kvrocks-exporter:v{{ .Version }}-arm64
kos:
- repository: docker.io/kvrocks/kvrocks-exporter
tags:
- "{{.Version}}"
- latest
preserve_import_paths: false
base_image: alpine:3.20
bare: true
ldflags:
- "-X main.BuildVersion={{ .Version }}"
- "-X main.BuildDate={{.Date}}"
- "-X main.BuildCommitSha={{.Commit}}"
platforms:
- linux/amd64
- linux/arm64
41 changes: 0 additions & 41 deletions .github/workflows/docker-build-push.yaml

This file was deleted.

75 changes: 75 additions & 0 deletions .github/workflows/release-binaries-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: goreleaser

on:
pull_request:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write
packages: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run GoReleaser for build
uses: goreleaser/goreleaser-action@v6
if: success() && !startsWith(github.ref, 'refs/tags/')
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --snapshot --clean -f ./.github/goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
if: success() && startsWith(github.ref, 'refs/tags/')
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub if publishing tag
if: success() && startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: success() && startsWith(github.ref, 'refs/tags/')
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v2"
args: release --clean -f ./.github/goreleaser.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
if: success() && startsWith(github.ref, 'refs/tags/')
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: RocksLabs/kvrocks-exporter
short-description: ${{ github.event.repository.description }}

- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: kvrocks_exporter_artifacts_${{ github.run_number }}
path: dist/
29 changes: 0 additions & 29 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ contrib/tls/ca.key
contrib/tls/ca.txt
contrib/tls/redis.crt
contrib/tls/redis.key

dist/
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

21 changes: 7 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ upload-coverage:
go install github.com/mattn/[email protected]
/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io

.PHONY: build
build:
go build .

.PHONY: release
release:
go install github.com/goreleaser/goreleaser/v2@latest

BUILD_DT:=$(shell date +%F-%T)
GO_LDFLAGS:="-s -w -extldflags \"-static\" -X main.BuildVersion=${DRONE_TAG} -X main.BuildCommitSha=${DRONE_COMMIT_SHA} -X main.BuildDate=$(BUILD_DT)"
OS ?= linux
ARCH ?= amd64

.PHONE: build-binaries
build-binaries:
go install github.com/oliver006/gox@master

rm -rf .build | true

export CGO_ENABLED=0 ; \
gox -os=$(OS) -arch=$(ARCH) -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/kvrocks_exporter" && \
echo "done"
goreleaser release --clean -f .github/goreleaser.yml
Copy link
Member

@git-hulk git-hulk Sep 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we separate the build and release binary into two targets? That said, we can have make build to build to binary which doesn't depend on goreleaser, and add the target make release for releasing propose. What do you think about this?

Rest are good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, made that change. My opinion I guess would be that this goreleaser step is never used and the release is only done by CI. Good then that the make build only makes a local build with no dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks for checking the PR - I'd suggest that assuming it works, I'd make another PR to update the readme a bit to also point to the docker hub reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thank you!

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ go build .
./kvrocks_exporter --version
```

### Release

All releases are done via Github Actions. To create a new release, create a new Release + Tag from master.
Actions will automatically add the release artifacts and publish new docker images to Docker hub.

### Arguments

These mostly match the redis exporter but with "redis" replaced with "kvrocks". Please note this includes the protocol version.
Expand Down