Skip to content

Commit

Permalink
Merge pull request #198 from nats-io/feature/auto-image-build
Browse files Browse the repository at this point in the history
Adding image build to workflow
  • Loading branch information
wallyqs authored Jan 20, 2023
2 parents 1050378 + d728950 commit 998b863
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 998b863

Please sign in to comment.