-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use goreleaser to handle releases (#33)
* Use goreleaser to handle releases
- Loading branch information
Showing
13 changed files
with
259 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Release | ||
|
||
on: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Release Docker | ||
|
||
on: | ||
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Test | ||
|
||
on: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.build | ||
/cgroup_exporter | ||
/coverage.txt | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
# yamllint disable rule:line-length | ||
go: | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.