From 3ead917321b564d6614d8b8288eaeb82bee9612a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jev=20Bj=C3=B6rsell?= Date: Thu, 1 Jul 2021 08:56:41 -0700 Subject: [PATCH] feat: setup goreleaser (#28) * feat: setup goreleaser Docker images published to hub and github Bare binaries published to github Builds for mac/windows/linux * amd64/arm --- .github/workflows/build.yaml | 62 +++++++++++++++++++++--- .github/workflows/release.yaml | 37 --------------- .gitignore | 2 + .goreleaser.yml | 86 ++++++++++++++++++++++++++++++++++ Dockerfile | 15 ++---- 5 files changed, 147 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/release.yaml create mode 100644 .gitignore create mode 100644 .goreleaser.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7cbd278..30aa8ab 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 0b2d856..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,37 +0,0 @@ -name: Release Docker image -on: - push: - tags: - - v* - -env: - IMAGE_NAME: ecadlabs/tezos_exporter - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/setup-go@v1 - with: - go-version: 1.13 - - uses: actions/checkout@v2 - - run: go build -v . - - push: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME:latest - - - name: Log into registry - run: echo '${{ secrets.DOCKER_PASS }}' | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin - - - name: Push image - run: | - VERSION=$(echo "${{ github.ref }}" | sed -E -e 's/.*\/v?(.*)/\1/') - docker tag $IMAGE_NAME:latest $IMAGE_NAME:$VERSION - docker push $IMAGE_NAME:$VERSION - docker push $IMAGE_NAME:latest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7f5074c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist/ +tezos_exporter diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..61d6224 --- /dev/null +++ b/.goreleaser.yml @@ -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:' diff --git a/Dockerfile b/Dockerfile index e12f2df..d511c0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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