diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 89c6df7..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,80 +0,0 @@ ---- -version: 2.1 - -orbs: - prometheus: prometheus/prometheus@0.17.1 - codecov: codecov/codecov@3.2.2 - -executors: - # Whenever the Go version is updated here, .promu.yml should - # also be updated. - golang: - docker: - - image: cimg/go:1.20.3 - -jobs: - test: - executor: golang - steps: - - prometheus/setup_environment - - run: make - - run: make coverage - - codecov/upload: - file: coverage.txt - - prometheus/store_artifact: - file: cgroup_exporter - build: - machine: - image: ubuntu-2004:202201-02 - steps: - - checkout - - run: make promu - - run: promu crossbuild -v - - persist_to_workspace: - root: . - paths: - - .build - - store_artifacts: - path: .build - destination: /build - - run: - command: | - if [ -n "$CIRCLE_TAG" ]; then - make docker DOCKER_IMAGE_TAG=$CIRCLE_TAG - else - make docker - fi -workflows: - version: 2 - cgroup_exporter: - jobs: - - test: - filters: - tags: - only: /.*/ - - build: - filters: - tags: - only: /.*/ - - prometheus/publish_master: - context: org-context - docker_hub_organization: treydock - quay_io_organization: treydock - requires: - - test - - build - filters: - branches: - only: master - - prometheus/publish_release: - context: org-context - docker_hub_organization: treydock - quay_io_organization: treydock - requires: - - test - - build - filters: - tags: - only: /^v([0-9]).*/ - branches: - ignore: /.*/ diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b030862 --- /dev/null +++ b/.github/workflows/release.yaml @@ -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/goreportcard-action@v1.0 + - name: setup release environment + run: |- + echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env + - name: Run GoReleaser + run: make release diff --git a/.github/workflows/release_docker.yaml b/.github/workflows/release_docker.yaml new file mode 100644 index 0000000..756dbca --- /dev/null +++ b/.github/workflows/release_docker.yaml @@ -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 }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..4b2afc6 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 diff --git a/.gitignore b/.gitignore index ab2e663..35b354f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.build /cgroup_exporter /coverage.txt +/dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..a47488d --- /dev/null +++ b/.goreleaser.yml @@ -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:' diff --git a/.promu.yml b/.promu.yml index 2a7d977..da52351 100644 --- a/.promu.yml +++ b/.promu.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index aaef86e..2a973db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index 0f744d4..10c7802 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/VERSION b/VERSION deleted file mode 100644 index 9c21819..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -1.0.0-rc.1