-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use GitHub Actions for releases and Docker image (#75)
- Loading branch information
1 parent
9c6e59c
commit 916576b
Showing
8 changed files
with
184 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: CI | ||
on: push | ||
jobs: | ||
test: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.x | ||
- run: make lint | ||
- run: make test | ||
|
||
release: | ||
runs-on: ubuntu-latest | ||
if: contains(github.ref, 'refs/tags/') | ||
needs: test | ||
outputs: | ||
upload_url: ${{ steps.release.outputs.upload_url }} | ||
steps: | ||
- name: Create GitHub release | ||
uses: actions/create-release@v1 | ||
id: release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: ${{ github.ref }} | ||
body: TODO | ||
draft: true | ||
|
||
assets: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
needs: release | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.x | ||
- run: echo "APP_VERSION=$(git describe --tags --abbrev=0 | sed -e 's/^v//')" >> $GITHUB_ENV | ||
shell: bash | ||
- run: echo "ASSET_NAME=fastly-exporter-${{ env.APP_VERSION }}.$(go env GOOS)-$(go env GOARCH).tar.gz" >> $GITHUB_ENV | ||
shell: bash | ||
- run: echo "ASSET_PATH=dist/v${{ env.APP_VERSION }}/${{ env.ASSET_NAME }}" >> $GITHUB_ENV | ||
shell: bash | ||
- run: make dist | ||
- uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.release.outputs.upload_url }} | ||
asset_path: ${{ env.ASSET_PATH }} | ||
asset_name: ${{ env.ASSET_NAME }} | ||
asset_content_type: application/gzip | ||
|
||
docker: | ||
runs-on: ubuntu-latest | ||
needs: release | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: docker/metadata-action@v3 | ||
id: meta | ||
with: | ||
images: ghcr.io/peterbourgon/fastly-exporter | ||
- uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,4 @@ | ||
/dist/ | ||
/fastly-exporter | ||
|
||
# Binaries for programs and plugins | ||
*.exe | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.tar.gz | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 | ||
.glide/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:latest AS builder | ||
RUN groupadd -r fastly-exporter | ||
RUN useradd -r -g fastly-exporter fastly-exporter | ||
WORKDIR /app | ||
COPY go.mod . | ||
COPY go.sum . | ||
RUN go mod download | ||
ADD .git .git | ||
ADD cmd cmd | ||
ADD pkg pkg | ||
RUN env CGO_ENABLED=0 go build \ | ||
-a \ | ||
-ldflags="-X main.programVersion=$(git describe --tags --abbrev=0 | sed -e 's/^v//')" \ | ||
-o /fastly-exporter \ | ||
./cmd/fastly-exporter | ||
|
||
FROM scratch | ||
COPY --from=builder /etc/passwd /etc/passwd | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY --from=builder /fastly-exporter /fastly-exporter | ||
USER fastly-exporter | ||
EXPOSE 8080 | ||
ENTRYPOINT ["/fastly-exporter", "-listen=0.0.0.0:8080"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
GO ?= go | ||
GOOS ?= $(shell ${GO} env GOOS) | ||
GOARCH ?= $(shell ${GO} env GOARCH) | ||
VERSION ?= $(shell git describe --tags --abbrev=0 | sed -e 's/^v//') | ||
STATICCHECK ?= $(shell $(GO) env GOPATH)/bin/staticcheck | ||
REVIVE ?= $(shell $(GO) env GOPATH)/bin/revive | ||
GOFUMPT ?= $(shell $(GO) env GOPATH)/bin/gofumpt | ||
DOCKER ?= docker | ||
BINARY = fastly-exporter | ||
BINPKG = ./cmd/fastly-exporter | ||
SOURCE = $(shell find . -name *.go) | ||
DIST_DIR = dist/v${VERSION} | ||
DIST_BIN_FILE = ${BINARY}-${VERSION}.${GOOS}-${GOARCH} | ||
DIST_ZIP_FILE = ${DIST_BIN_FILE}.tar.gz | ||
DIST_BIN = ${DIST_DIR}/${DIST_BIN_FILE} | ||
DIST_ZIP = ${DIST_DIR}/${DIST_ZIP_FILE} | ||
DOCKER_TAG = fastly-exporter:${VERSION} | ||
DOCKER_ZIP = ${DIST_DIR}/${BINARY}-${VERSION}.docker.tar.gz | ||
|
||
${BINARY}: ${SOURCE} Makefile | ||
env CGO_ENABLED=0 ${GO} build -o ${BINARY} -ldflags="-X main.programVersion=${VERSION}" ${BINPKG} | ||
|
||
${DIST_BIN}: ${DIST_DIR} ${SOURCE} Makefile | ||
env CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} ${GO} build -o $@ -ldflags="-X main.programVersion=${VERSION}" ${BINPKG} | ||
|
||
${DIST_DIR}: | ||
mkdir -p $@ | ||
|
||
${DIST_ZIP}: ${DIST_BIN} | ||
tar -C ${DIST_DIR} -c -z -f ${DIST_ZIP} ${DIST_BIN_FILE} | ||
|
||
${DOCKER_ZIP}: ${SOURCE} Dockerfile | ||
${DOCKER} build --tag=${DOCKER_TAG} . | ||
${DOCKER} save --output=$@ ${DOCKER_TAG} | ||
|
||
${STATICCHECK}: | ||
${GO} install honnef.co/go/tools/cmd/staticcheck@latest | ||
|
||
${REVIVE}: | ||
${GO} install github.com/mgechev/revive@latest | ||
|
||
${GOFUMPT}: | ||
${GO} install mvdan.cc/gofumpt@latest | ||
|
||
.PHONY: lint | ||
lint: ${STATICCHECK} ${REVIVE} ${GOFUMPT} ${SOURCE} | ||
${GO} vet ./... | ||
${STATICCHECK} ./... | ||
${REVIVE} ./... | ||
${GOFUMPT} -s -l -d -e . | ||
|
||
.PHONY: test | ||
test: ${SOURCE} | ||
${GO} test -race ./... | ||
|
||
.PHONY: dist | ||
dist: ${DIST_ZIP} | ||
|
||
.PHONY: docker | ||
docker: ${DOCKER_ZIP} | ||
|
||
.PHONY: release | ||
release: dist docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.