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 runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
- name: Setup go - name: Setup go
uses: actions/setup-go@v2.1.4 uses: actions/setup-go@v2.1.4
with: with:
go-version: '1.16.x' go-version: '1.16.x'
- name: Vet - name: Vet
run: make vet run: go vet
- name: Test - name: Test
run: make coverage run: go test ./...
build: build:
name: Build name: Build
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs:
- test
steps: steps:
- uses: actions/checkout@v2.3.4 - uses: actions/checkout@v2.3.4
- name: Setup go - name: Setup go
uses: actions/setup-go@v2.1.4 uses: actions/setup-go@v2.1.4
with: with:
go-version: '1.16.x' go-version: '1.16.x'
- name: Build
run: make build
docker: - name: Build
name: Docker run: go build ./...
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- name: Docker - name: Docker
run: make docker run: docker build .

View file

@ -10,62 +10,26 @@ jobs:
name: Release name: Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2.3.4 - name: Checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Setup go - name: Setup go
uses: actions/setup-go@v2.1.4 uses: actions/setup-go@v2
with: with:
go-version: '1.16.x' go-version: 1.16.x
- name: Create release artifacts
run: make release - name: Login to Docker Hub
env: uses: docker/login-action@v1.10.0
GOPATH: ${{ github.workspace }}/go with:
- name: Create Github Release username: ${{ secrets.DOCKERHUB_USERNAME }}
id: create_release password: ${{ secrets.DOCKERHUB_TOKEN }}
uses: actions/create-release@v1.1.4
- name: Release
uses: goreleaser/goreleaser-action@v2.6.1
with:
version: latest
args: release --rm-dist
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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 WORKDIR /go/src/github.com/systemli/prometheus-jitsi-meet-exporter
@ -14,20 +14,12 @@ RUN adduser \
--uid "${UID}" \ --uid "${UID}" \
"${USER}" "${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 FROM scratch
COPY --from=builder /etc/passwd /etc/passwd COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group COPY --from=builder /etc/group /etc/group
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY prometheus-jitsi-meet-exporter /prometheus-jitsi-meet-exporter
COPY --from=builder /prometheus-jitsi-meet-exporter /prometheus-jitsi-meet-exporter
USER appuser:appuser 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