Skip to content

Commit

Permalink
feat: setup goreleaser (#28)
Browse files Browse the repository at this point in the history
* feat: setup goreleaser

Docker images published to hub and github
Bare binaries published to github
Builds for mac/windows/linux * amd64/arm
  • Loading branch information
jevonearth authored Jul 1, 2021
1 parent 2632438 commit 3ead917
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 55 deletions.
62 changes: 55 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
name: Build
on: push
name: build

on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:

jobs:
build:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.16'
-
name: Cache Go modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
-
name: Login to Docker Hub
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Login to GitHub Container Registry
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
go-version: 1.13
- uses: actions/checkout@v2
- run: go build -v .
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 0 additions & 37 deletions .github/workflows/release.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
tezos_exporter
86 changes: 86 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
- arm64
dockers:
- image_templates:
- 'ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ecadlabs/tezos_exporter:latest-amd64'
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ghcr.io/ecadlabs/tezos_exporter:latest-amd64'
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/amd64"
- image_templates:
- 'ecadlabs/tezos_exporter:{{ .Tag }}-arm64'
- 'ecadlabs/tezos_exporter:latest-arm64'
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-arm64'
- 'ghcr.io/ecadlabs/tezos_exporter:latest-arm64'
dockerfile: Dockerfile
use: buildx
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.name={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source={{.GitURL}}"
- "--platform=linux/arm64"
goarch: arm64
docker_manifests:
- name_template: 'ecadlabs/tezos_exporter:{{ .Tag }}'
image_templates:
- 'ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ecadlabs/tezos_exporter:{{ .Tag }}-arm64'
- name_template: 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}'
image_templates:
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-arm64'
- name_template: 'ecadlabs/tezos_exporter:latest'
image_templates:
- 'ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ecadlabs/tezos_exporter:{{ .Tag }}-arm64'
- name_template: 'ghcr.io/ecadlabs/tezos_exporter:latest'
image_templates:
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-amd64'
- 'ghcr.io/ecadlabs/tezos_exporter:{{ .Tag }}-arm64'


archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
15 changes: 4 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# build stage
FROM golang:1.13-alpine AS build-env
WORKDIR /tezos_exporter
ADD . .
RUN apk --no-cache add git
RUN go get -d ./...
RUN go build

# final stage
FROM alpine
WORKDIR /app
COPY --from=build-env /tezos_exporter/tezos_exporter /usr/bin/tezos_exporter

ENTRYPOINT ["/usr/bin/tezos_exporter"]
CMD ["-tezos-node-url" "http://localhost:8732/"]


COPY tezos_exporter /usr/bin/tezos_exporter

0 comments on commit 3ead917

Please sign in to comment.