Skip to content

Commit

Permalink
Use goreleaser to handle releases (#33)
Browse files Browse the repository at this point in the history
* Use goreleaser to handle releases
  • Loading branch information
treydock authored May 18, 2024
1 parent 28e9388 commit d0cbfaa
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 126 deletions.
80 changes: 0 additions & 80 deletions .circleci/config.yml

This file was deleted.

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

Check warning on line 1 in .github/workflows/release.yaml

View workflow job for this annotation

GitHub Actions / Test

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/release.yaml

View workflow job for this annotation

GitHub Actions / Test

3:1 [truthy] truthy value should be one of [false, true]
push:
tags:
- '*'

jobs:
release:
runs-on: ubuntu-latest
name: Create Release
steps:
- name: Set version
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: creekorful/[email protected]
- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
- name: Run GoReleaser
run: make release
51 changes: 51 additions & 0 deletions .github/workflows/release_docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release Docker

Check warning on line 1 in .github/workflows/release_docker.yaml

View workflow job for this annotation

GitHub Actions / Test

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/release_docker.yaml

View workflow job for this annotation

GitHub Actions / Test

3:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- master
tags:
- '*'

jobs:
release-docker:
runs-on: ubuntu-latest
name: Release Docker
steps:
- name: Set version
run: |
ref=${GITHUB_REF#refs/*/}
if [ $ref = "master" ]; then
version="latest"
else
version=$ref
fi
echo "REF=${ref}" >> $GITHUB_ENV
echo "VERSION=${version}" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: treydock
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: treydock
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: ./
platforms: linux/amd64,linux/arm64
file: ./Dockerfile
push: true
tags: |
treydock/cgroup_exporter:${{ env.VERSION }}
quay.io/treydock/cgroup_exporter:${{ env.VERSION }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
47 changes: 47 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test

Check warning on line 1 in .github/workflows/test.yaml

View workflow job for this annotation

GitHub Actions / Test

1:1 [document-start] missing document start "---"

on:

Check warning on line 3 in .github/workflows/test.yaml

View workflow job for this annotation

GitHub Actions / Test

3:1 [truthy] truthy value should be one of [false, true]
push:
branches:
- master
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 3
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: make
- name: Run coverage
run: make coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
build:
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run GoReleaser build
run: make release-test
- name: Docker Build
run: make docker
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.build
/cgroup_exporter
/coverage.txt
/dist
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
before:
hooks:
# You may remove this if you don't use go modules.
- go mod download
env:
- CGO_ENABLED=1
builds:
- id: amd64
main: cgroup_exporter.go
env:
- CC=x86_64-linux-gnu-gcc
goos:
- linux
goarch:
- amd64
ldflags:
- -extldflags "-static"
- -X github.com/prometheus/common/version.Version={{.Version}}
- -X github.com/prometheus/common/version.Revision={{.FullCommit}}
- -X github.com/prometheus/common/version.Branch={{.Branch}}
- -X github.com/prometheus/common/version.BuildUser=goreleaser
- -X github.com/prometheus/common/version.BuildDate={{.Date}}
- id: arm64
main: cgroup_exporter.go
env:
- CC=aarch64-linux-gnu-gcc
goos:
- linux
goarch:
- arm64
ldflags:
- -extldflags "-static"
- -X github.com/prometheus/common/version.Version={{.Version}}
- -X github.com/prometheus/common/version.Revision={{.FullCommit}}
- -X github.com/prometheus/common/version.Branch={{.Branch}}
- -X github.com/prometheus/common/version.BuildUser=goreleaser
- -X github.com/prometheus/common/version.BuildDate={{.Date}}
archives:
- id: archive
builds:
- amd64
- arm64
files:
- LICENSE
- CHANGELOG.md
name_template: "cgroup_exporter-{{ .Version }}_{{ .Os }}_{{ .Arch }}"
wrap_in_directory: true
checksum:
name_template: 'checksums.txt'
release:
prerelease: auto
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
49 changes: 25 additions & 24 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
# yamllint disable rule:line-length
go:

Check warning on line 2 in .promu.yml

View workflow job for this annotation

GitHub Actions / Test

2:1 [document-start] missing document start "---"
version: 1.20
cgo: true
repository:
path: github.com/treydock/cgroup_exporter
path: github.com/treydock/cgroup_exporter
build:
binaries:
- name: cgroup_exporter
path: .
flags: -a -tags netgo
ldflags: |
-extldflags "-static"
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
binaries:
- name: cgroup_exporter
path: .
flags: -a -tags netgo
ldflags: |
-extldflags "-static"
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.Revision}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- CHANGELOG.md
files:
- LICENSE
- CHANGELOG.md
crossbuild:
platforms:
- linux/amd64
- linux/386
- linux/arm64
- linux/mips
- linux/mipsle
- linux/mips64
- linux/mips64le
- linux/ppc64le
platforms:
- linux/amd64
- linux/386
- linux/arm64
- linux/mips
- linux/mipsle
- linux/mips64
- linux/mips64le
- linux/ppc64le
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
ARG ARCH="amd64"
ARG OS="linux"
FROM quay.io/prometheus/busybox-${OS}-${ARCH}:glibc
ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/cgroup_exporter /cgroup_exporter
EXPOSE 9306
FROM golang:1.20.7-alpine3.17 AS builder
RUN apk update && apk add git make gcompat curl build-base
WORKDIR /go/src/app
COPY . ./
RUN make build

FROM alpine:3.17
RUN apk --no-cache add ca-certificates gcompat
WORKDIR /
COPY --from=builder /go/src/app/cgroup_exporter .
ENTRYPOINT ["/cgroup_exporter"]
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
DOCKER_ARCHS ?= amd64 arm64 ppc64le
DOCKER_REPO ?= treydock
export GOPATH ?= $(firstword $(subst :, ,$(shell go env GOPATH)))
GOLANG_CROSS_VERSION ?= v1.20.7

include Makefile.common

Expand All @@ -10,6 +11,18 @@ DOCKER_IMAGE_NAME ?= cgroup_exporter
coverage:
go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./...

release-test:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/work -w /work \
ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION) \
build --snapshot --clean

release:
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
--env-file .release-env -v `pwd`:/work -w /work \
ghcr.io/goreleaser/goreleaser-cross:$(GOLANG_CROSS_VERSION) \
release --clean

%/.unpacked: %.ttar
@echo ">> extracting fixtures"
./ttar -C $(dir $*) -x -f $*.ttar
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

Loading

0 comments on commit d0cbfaa

Please sign in to comment.