Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding image build to workflow #198

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opinions on using gcr.io/distroless/static-debian11 here? That's essentially what we are making with scratch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me since that includes the certs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's benefit to using same distro - for example @philpennock tracks alpine security updates etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only things coming from debian in this image are CA Certificates and TZData. It has some other niceties, such as a /tmp directory and an /etc/passwd entry though.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly this particular image has been working fine without those things though, so fine to just leave it the way it is too

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"]