Skip to content

Commit

Permalink
Add gha target to Dockerfile;
Browse files Browse the repository at this point in the history
Update gha: use one binary in docker image and targball;
Rollback Makefile changes;
  • Loading branch information
f100024 committed Dec 3, 2022
1 parent f714285 commit 5256e3c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
45 changes: 38 additions & 7 deletions .github/workflows/make-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@ name: Make release

on:
workflow_dispatch:
inputs:
make_release_draft:
description: Create release draft
default: true
type: boolean
required: true
build_dockerimage:
description: Build docker images and push to docker hub
default: true
type: boolean
required: true
push:
tags:
- 'v*'


jobs:
build_release:
Expand All @@ -24,27 +36,43 @@ jobs:
- name: Make tarballs
run: make tarballs

- name: Upload files to release
- name: Upload files to release and create draft
# if: ${{ inputs.make_release_draft }}
run: make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Cache artifacts
uses: actions/cache@v3
with:
path: .build
key: syncthing_exporter-${{ github.sha }}

build_dockerimage:
# if: ${{ inputs.build_dockerimage }}
needs: build_release
name: Build docker images
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:

- name: Checkout code
uses: actions/[email protected]

- name: Set VERSION as environment variable
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV

- name: Cache artifacts
uses: actions/cache@v3
with:
path: .build
key: syncthing_exporter-${{ github.sha }}

- name: Set up QEMU
uses: docker/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Set VERSION as environment variable
run: echo "VERSION=$(cat VERSION)" >> $GITHUB_ENV

- name: Login to DockerHub
uses: docker/[email protected]
with:
Expand All @@ -57,6 +85,9 @@ jobs:
context: .
platforms: linux/amd64,linux/arm64,linux/386,linux/arm/v6,linux/arm/v7
push: true
target: ghactions
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/syncthing_exporter:latest,
${{ secrets.DOCKERHUB_USERNAME }}/syncthing_exporter:${{ env.VERSION }}
f100024/syncthing_exporter:latest,
f100024/syncthing_exporter:${{ env.VERSION }}
env:
DOCKER_BUILDKIT: 1
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
FROM golang:1.19 as builder

COPY . /builddir
WORKDIR /builddir

RUN make build

FROM alpine:3.17
FROM alpine:3.17 as local
COPY --from=builder /builddir/syncthing_exporter /usr/bin/syncthing_exporter

EXPOSE 9093
ENTRYPOINT ["syncthing_exporter"]

FROM alpine:3.17 as ghactions
ARG TARGETOS TARGETARCH TARGETVARIANT
COPY .build/${TARGETOS}-${TARGETARCH}${TARGETVARIANT}/syncthing_exporter /usr/bin/syncthing_exporter

EXPOSE 9093
ENTRYPOINT ["syncthing_exporter"]
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,10 @@
GO := go
PROMU := $(GOPATH)/bin/promu
PROMU_VERSION := 0.13.0
PKGS = $(shell $(GO) list ./... | grep -v /vendor/)
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
PKGS = $(shell $(GO) list ./... | grep -v /vendor/)
ARCH = $(shell uname -m)
GOOS = $(shell uname -s | tr A-Z a-z)

ifeq ($(ARCH), aarch64)
GOARCH=arm64
endif
ifeq ($(ARCH), x86_64)
GOARCH=amd64
endif
ifeq ($(ARCH), x86)
GOARCH=386
endif
ifeq ($(ARCH), armv7l)
GOARCH=arm
endif


all: test build

Expand Down Expand Up @@ -50,4 +36,6 @@ release: promu
@$(PROMU) release --verbose --timeout=120s --retry=30 $(BIN_DIR)/.tarballs

promu:
$(GO) install github.com/prometheus/promu@v$(PROMU_VERSION)
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) install github.com/prometheus/promu@v$(PROMU_VERSION)

0 comments on commit 5256e3c

Please sign in to comment.