diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e92c942..c26f37a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,22 +2,38 @@ name: Exporter Release on: push: tags: - - 'v*' + - v[0-9]+.[0-9]+.[0-9]+ jobs: release: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v1 - with: - path: src/github.com/nats-io/prometheus-nats-exporter + - name: Setup Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Setup QEMU + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Setup Docker Hub + uses: docker/login-action@v2 with: - go-version: 1.17 - - name: Release - shell: bash --noprofile --norc -x -eo pipefail {0} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_CLI_TOKEN }} + + - name: Generate goreleaser release + uses: goreleaser/goreleaser-action@v4 env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - run: | - curl --location http://git.io/goreleaser | bash + IMAGE_REGISTRY: "natsio" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + distribution: goreleaser + version: latest + args: release --rm-dist diff --git a/.goreleaser.yml b/.goreleaser.yml index 9d9ed27..21cb408 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,6 +9,9 @@ release: name_template: 'Release {{.Tag}}' +env: + - IMAGE_REPOSITORY={{ if index .Env "IMAGE_REGISTRY" }}{{ .Env.IMAGE_REGISTRY }}/{{ end }}{{ .ProjectName }} + builds: - id: prometheus-nats-exporter main: . @@ -58,9 +61,6 @@ checksum: snapshot: name_template: SNAPSHOT-{{ .Commit }} -github_urls: - download: https://github.com - nfpms: - file_name_template: '{{.ProjectName}}-{{.Tag}}-{{.Arch}}{{if .Arm}}{{.Arm}}{{end}}' homepage: https://nats.io @@ -71,4 +71,70 @@ nfpms: formats: - deb -dist: dist +dockers: + - use: buildx + ids: + - prometheus-nats-exporter + dockerfile: docker/linux/Dockerfile + goos: linux + goarch: amd64 + image_templates: + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-amd64" + build_flag_templates: + - "--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 + ids: + - prometheus-nats-exporter + dockerfile: docker/linux/Dockerfile + goos: linux + goarch: arm64 + image_templates: + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-arm64" + build_flag_templates: + - "--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 }}" + - use: buildx + ids: + - prometheus-nats-exporter + dockerfile: docker/linux/Dockerfile + goos: linux + goarch: arm + goarm: 6 + image_templates: + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-armv6" + build_flag_templates: + - "--platform=linux/arm/v6" + - "--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 + ids: + - prometheus-nats-exporter + dockerfile: docker/linux/Dockerfile + goos: linux + goarch: arm + goarm: 7 + image_templates: + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-armv7" + build_flag_templates: + - "--platform=linux/arm/v7" + - "--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: "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}" + image_templates: + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-amd64" + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-arm64" + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-armv6" + - "{{ .Env.IMAGE_REPOSITORY }}:{{ if .IsSnapshot }}{{ .Version }}{{ else }}{{ .Tag }}{{ end }}-armv7" diff --git a/Makefile b/Makefile index b09d7d8..3914d80 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ export GO111MODULE := on drepo ?= natsio prometheus-nats-exporter.docker: - CGO_ENABLED=0 GOOS=linux go build -o $@ -v -a + CGO_ENABLED=0 GOOS=linux go build -o $@ -v -a \ -tags netgo -tags timetzdata \ -installsuffix netgo -ldflags "-s -w" diff --git a/docker/linux/Dockerfile b/docker/linux/Dockerfile index b295d8c..662b937 100644 --- a/docker/linux/Dockerfile +++ b/docker/linux/Dockerfile @@ -1,15 +1,16 @@ -FROM golang:1.19.3 AS build -COPY . /go/src/prometheus-nats-exporter -WORKDIR /go/src/prometheus-nats-exporter -RUN make prometheus-nats-exporter.docker - FROM alpine:latest as osdeps + RUN apk add --no-cache ca-certificates +ARG BINARY=prometheus-nats-exporter + FROM scratch -COPY --from=build /go/src/prometheus-nats-exporter/prometheus-nats-exporter.docker /prometheus-nats-exporter + +COPY ${BINARY} /${BINARY} + COPY --from=osdeps /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ EXPOSE 7777 + ENTRYPOINT ["/prometheus-nats-exporter"] CMD ["--help"]