From e7a69763210298fa330fc3f3ea8535423594ad39 Mon Sep 17 00:00:00 2001 From: Tomasz Nowak Date: Tue, 19 Dec 2023 23:26:17 +0100 Subject: [PATCH] feat: Add ci pipelines --- .github/workflows/pr-validation.yaml | 34 +++++++++++++++++ .github/workflows/release.yaml | 44 +++++++++++++++++++++ .goreleaser.yaml | 57 ++++++++++++++++++++++++++++ Dockerfile | 10 +++++ Makefile | 42 ++++++++++---------- 5 files changed, 167 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/pr-validation.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/pr-validation.yaml b/.github/workflows/pr-validation.yaml new file mode 100644 index 0000000..9c53a4d --- /dev/null +++ b/.github/workflows/pr-validation.yaml @@ -0,0 +1,34 @@ +--- +name: PR Validation + +on: + pull_request: + branches: + - main + +jobs: + run-reviewdog: + name: Run ReviewDog + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: ReviewDog - GolangCI Lint + uses: reviewdog/action-golangci-lint@v2 + with: + go_version_file: go.mod + tool_name: GolangCI Lint + golangci_lint_flags: --config=.golangci.yaml --timeout=10m + fail_on_error: true + run-tests: + name: Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Tests + run: make test-ci diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2fdb815 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,44 @@ +--- +name: Release + +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - id: release-please + name: Release Please + uses: google-github-actions/release-please-action@v4 + with: + release-type: go + + - name: Checkout + uses: actions/checkout@v4 + if: steps.release-please.outputs.release_created + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v5 + if: steps.release-please.outputs.release_created + with: + go-version-file: go.mod + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + if: steps.release-please.outputs.release_created + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + if: steps.release-please.outputs.release_created + + - name: Run GoReleaser + if: steps.release-please.outputs.release_created + run: make release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..6d4e251 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,57 @@ +--- +project_name: validator-exporter +before: + hooks: + - go mod tidy +env: + - CGO_ENABLED=0 +builds: + - main: "./cmd/{{ .ProjectName }}/main.go" + binary: "{{ .ProjectName }}" + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + flags: + - -mod=readonly + - -trimpath + ldflags: + - -s -w + tags: + - netgo + +universal_binaries: + - replace: false + +dockers: + - use: buildx + goos: linux + goarch: amd64 + image_templates: + - "ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-amd64" + build_flag_templates: + - "--pull" + - "--platform=linux/amd64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" + - use: buildx + goos: linux + goarch: arm64 + image_templates: + - "ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-arm64v8" + build_flag_templates: + - "--pull" + - "--platform=linux/arm64" + - "--label=org.opencontainers.image.created={{.Date}}" + - "--label=org.opencontainers.image.title={{.ProjectName}}" + - "--label=org.opencontainers.image.revision={{.FullCommit}}" + - "--label=org.opencontainers.image.version={{.Version}}" +docker_manifests: + - name_template: ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }} + image_templates: + - ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/archway-network/{{ .ProjectName }}:{{ .Version }}-arm64v8 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d509fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM gcr.io/distroless/static-debian12:nonroot + +COPY validator-exporter /usr/bin/validator-exporter + +# metrics server +EXPOSE 8008 + +ENTRYPOINT [ "/usr/bin/validator-exporter" ] + +CMD [ "--help" ] diff --git a/Makefile b/Makefile index 0cc1382..ca40375 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BUILD_FOLDER = build DIST_FOLDER = dist -GORELEASER_VERSION = v1.21.0 +GORELEASER_VERSION = v1.22.1 DOCKER := $(shell which docker) PACKAGE_NAME = github.com/archway-network/validator-exporter @@ -56,23 +56,25 @@ update: @go build -o "$(TMPDIR)/validator-exporter" cmd/validator-exporter/main.go @git diff -- go.mod go.sum -# release-dryrun: -# $(DOCKER) run \ -# --rm \ -# -v /var/run/docker.sock:/var/run/docker.sock \ -# -v `pwd`:/go/src/$(PACKAGE_NAME) \ -# -w /go/src/$(PACKAGE_NAME) \ -# goreleaser/goreleaser-cross:$(GORELEASER_VERSION) \ -# --skip-publish \ -# --clean \ -# --skip-validate -# release: -# $(DOCKER) run \ -# --rm \ -# -e GITHUB_TOKEN="$(GITHUB_TOKEN)" \ -# -v /var/run/docker.sock:/var/run/docker.sock \ -# -v `pwd`:/go/src/$(PACKAGE_NAME) \ -# -w /go/src/$(PACKAGE_NAME) \ -# goreleaser/goreleaser-cross:$(GORELEASER_VERSION) \ -# --clean +release-dryrun: + $(DOCKER) run \ + --rm \ + -e GITHUB_TOKEN="$(GITHUB_TOKEN)" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + ghcr.io/goreleaser/goreleaser:$(GORELEASER_VERSION) \ + --clean \ + --skip=publish,validate \ + --snapshot + +release: + $(DOCKER) run \ + --rm \ + -e GITHUB_TOKEN="$(GITHUB_TOKEN)" \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v `pwd`:/go/src/$(PACKAGE_NAME) \ + -w /go/src/$(PACKAGE_NAME) \ + ghcr.io/goreleaser/goreleaser:$(GORELEASER_VERSION) \ + --clean