Skip to content

Commit

Permalink
Updating goreleaser, GitHub workflow, and Dockerfile for CI image cre…
Browse files Browse the repository at this point in the history
…ation.

Signed-off-by: Samuel Attwood <sam@synadia.com>
  • Loading branch information
samuelattwood committed Jan 20, 2023
1 parent 8f40861 commit d728950
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 21 deletions.
36 changes: 26 additions & 10 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 70 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: .
Expand Down Expand Up @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
13 changes: 7 additions & 6 deletions docker/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit d728950

Please sign in to comment.