Move CD to Goreleaser (#57)

* move to goreleaser

* Apply suggestions from code review
This commit is contained in:
Dwight Donovan Benvenuto 2021-09-14 11:37:38 +02:00 committed by GitHub
parent f8d9d009c1
commit c2167be572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 119 deletions

View file

@ -10,31 +10,33 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Setup go
uses: actions/setup-go@v2.1.4
with:
go-version: '1.16.x'
- name: Vet
run: make vet
run: go vet
- name: Test
run: make coverage
run: go test ./...
build:
name: Build
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v2.3.4
- name: Setup go
uses: actions/setup-go@v2.1.4
with:
go-version: '1.16.x'
- name: Build
run: make build
docker:
name: Docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Build
run: go build ./...
- name: Docker
run: make docker
run: docker build .

View file

@ -10,62 +10,26 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v2.1.4
uses: actions/setup-go@v2
with:
go-version: '1.16.x'
- name: Create release artifacts
run: make release
env:
GOPATH: ${{ github.workspace }}/go
- name: Create Github Release
id: create_release
uses: actions/create-release@v1.1.4
go-version: 1.16.x
- name: Login to Docker Hub
uses: docker/login-action@v1.10.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Release
uses: goreleaser/goreleaser-action@v2.6.1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: Upload release artifacts (Mac OS amd64)
id: upload-release-asset-mac
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/prometheus-jitsi-meet-exporter-darwin-amd64
asset_name: prometheus-jitsi-meet-exporter-darwin-amd64
asset_content_type: application/octet-stream
- name: Upload release artifacts (FreeBSD amd64)
id: upload-release-asset-freebsd
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/prometheus-jitsi-meet-exporter-freebsd-amd64
asset_name: prometheus-jitsi-meet-exporter-freebsd-amd64
asset_content_type: application/octet-stream
- name: Upload release artifacts (Linux amd64)
id: upload-release-asset-linux
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/prometheus-jitsi-meet-exporter-linux-amd64
asset_name: prometheus-jitsi-meet-exporter-linux-amd64
asset_content_type: application/octet-stream
- name: Upload release artifacts (shasums)
id: upload-release-asset-sha512sums
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/sha512sums.txt
asset_name: sha512sums.txt
asset_content_type: application/octet-stream

34
.goreleaser.yml Normal file
View file

@ -0,0 +1,34 @@
before:
hooks:
- go mod tidy
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarm:
- 6
- 7
ldflags:
- -s -w
dockers:
-
goos: linux
goarch: amd64
image_templates:
- "systemli/prometheus-jitsi-meet-exporter:{{ .Tag }}"
- "systemli/prometheus-jitsi-meet-exporter:{{ .Major }}"
- "systemli/prometheus-jitsi-meet-exporter:{{ .Major }}.{{ .Minor }}"
- "systemli/prometheus-jitsi-meet-exporter:latest"
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

View file

@ -1,4 +1,4 @@
FROM golang:1.17.0-alpine as builder
FROM alpine:3.14.0 as builder
WORKDIR /go/src/github.com/systemli/prometheus-jitsi-meet-exporter
@ -14,20 +14,12 @@ RUN adduser \
--uid "${UID}" \
"${USER}"
ADD . /go/src/github.com/systemli/prometheus-jitsi-meet-exporter
RUN apk --update add ca-certificates && \
go get -d -v && \
go mod download && \
go mod verify && \
CGO_ENABLED=0 go build -ldflags="-w -s" -o /prometheus-jitsi-meet-exporter
FROM scratch
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /prometheus-jitsi-meet-exporter /prometheus-jitsi-meet-exporter
COPY prometheus-jitsi-meet-exporter /prometheus-jitsi-meet-exporter
USER appuser:appuser

View file

@ -1,44 +0,0 @@
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOVET = $(GOCMD) vet
GOGET = $(GOCMD) get
GOX = $(GOPATH)/bin/gox
GOGET = $(GOCMD) get
GOX_ARGS = -output="$(BUILD_DIR)/{{.Dir}}-{{.OS}}-{{.Arch}}" -osarch="linux/amd64 darwin/amd64 freebsd/amd64"
BUILD_DIR = build
BINARY_NAME = prometheus-jitsi-meet-exporter
all: clean vet test build
build:
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) -v
vet:
${GOVET} ./...
test:
${GOTEST} ./...
coverage:
${GOTEST} -coverprofile=coverage.txt -covermode=atomic ./...
clean:
$(GOCLEAN)
rm -f $(BUILD_DIR)/*
run: build
./$(BUILD_DIR)/$(BINARY_NAME)
release:
${GOGET} -u github.com/mitchellh/gox
${GOX} -ldflags "${LD_FLAGS}" ${GOX_ARGS}
shasum -a 512 build/* > build/sha512sums.txt
docker:
docker build --rm --force-rm --no-cache -t systemli/prometheus-jitsi-meet-exporter .
.PHONY: all vet test coverage clean build run release docker