From a37d38a864bb211d3dcd07926de03de1beb5c46a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 21 Aug 2022 16:58:22 +0200 Subject: [PATCH 1/5] Set version and revision at linked time Signed-off-by: CrazyMax --- Dockerfile | 17 ++++++++++------- Makefile | 24 ++++++++++++++---------- credentials/credentials.go | 2 +- credentials/version.go | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 78bd902b..ebc1269e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,8 +60,8 @@ RUN --mount=type=bind,target=. \ FROM gobase AS version ARG PKG RUN --mount=target=. \ - VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags); \ - echo "-s -w -X ${PKG}/credentials.Version=${VERSION}" | tee /tmp/.ldflags; \ + VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \ + echo "-s -w -X ${PKG}/credentials.Version=${VERSION} -X ${PKG}/credentials.Revision=${REVISION} -X ${PKG}/credentials.Package=${PKG}" | tee /tmp/.ldflags; \ echo -n "${VERSION}" | tee /tmp/.version; FROM gobase AS base @@ -93,6 +93,7 @@ FROM scratch AS test-coverage COPY --from=test /out / FROM base AS build-linux +ARG PKG ARG TARGETOS ARG TARGETARCH ARG TARGETVARIANT @@ -102,13 +103,14 @@ RUN --mount=type=bind,target=. \ --mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags < Date: Sun, 21 Aug 2022 16:36:45 +0200 Subject: [PATCH 2/5] ci: fetch depth 0 at build time for proper versioning Signed-off-by: CrazyMax --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b8d7dbdf..62cec628 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,6 +128,8 @@ jobs: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up QEMU uses: docker/setup-qemu-action@v2 From e50298d97397e8201ad6a1f7e8591fa685dfccdc Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sat, 27 Aug 2022 00:32:11 +0200 Subject: [PATCH 3/5] Makefile: mutualize local and Dockerfile build opts Signed-off-by: CrazyMax --- .dockerignore | 1 - .gitignore | 1 - Dockerfile | 45 +++++++++++++--------------------- Makefile | 68 +++++++++++++++++++++++++++++++-------------------- 4 files changed, 58 insertions(+), 57 deletions(-) diff --git a/.dockerignore b/.dockerignore index 038672e0..5e56e040 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ /bin -/release diff --git a/.gitignore b/.gitignore index 038672e0..5e56e040 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /bin -/release diff --git a/Dockerfile b/Dockerfile index ebc1269e..8137f385 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ ARG XX_VERSION=1.1.2 ARG OSXCROSS_VERSION=11.3-r7-alpine ARG GOLANGCI_LINT_VERSION=v1.47.3 -ARG PKG=github.com/docker/docker-credential-helpers +ARG PACKAGE=github.com/docker/docker-credential-helpers # xx is a helper for cross-compilation FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx @@ -15,7 +15,7 @@ FROM crazymax/osxcross:${OSXCROSS_VERSION} AS osxcross FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS gobase COPY --from=xx / / -RUN apk add --no-cache clang file git lld llvm pkgconf rsync +RUN apk add --no-cache clang file git lld llvm make pkgconf rsync ENV GOFLAGS="-mod=vendor" ENV CGO_ENABLED="1" WORKDIR /src @@ -57,13 +57,6 @@ RUN --mount=type=bind,target=. \ --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ golangci-lint run ./... -FROM gobase AS version -ARG PKG -RUN --mount=target=. \ - VERSION=$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags) REVISION=$(git rev-parse HEAD)$(if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi); \ - echo "-s -w -X ${PKG}/credentials.Version=${VERSION} -X ${PKG}/credentials.Revision=${REVISION} -X ${PKG}/credentials.Package=${PKG}" | tee /tmp/.ldflags; \ - echo -n "${VERSION}" | tee /tmp/.version; - FROM gobase AS base ARG TARGETPLATFORM RUN xx-apk add musl-dev gcc libsecret-dev pass @@ -93,53 +86,49 @@ FROM scratch AS test-coverage COPY --from=test /out / FROM base AS build-linux -ARG PKG +ARG PACKAGE ARG TARGETOS ARG TARGETARCH ARG TARGETVARIANT RUN --mount=type=bind,target=. \ --mount=type=cache,target=/root/.cache \ - --mount=type=cache,target=/go/pkg/mod \ - --mount=type=bind,from=version,source=/tmp/.ldflags,target=/tmp/.ldflags < Date: Fri, 26 Aug 2022 23:55:23 +0200 Subject: [PATCH 4/5] Fix deb package Signed-off-by: CrazyMax --- Makefile | 4 ++-- deb/Dockerfile | 28 ++++++++++++++++++++++------ deb/build-deb | 8 ++------ deb/debian/rules | 3 ++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 4a44c111..4bad9a89 100644 --- a/Makefile +++ b/Makefile @@ -79,8 +79,8 @@ BUILDIMG:=docker-credential-secretservice-$(VERSION) deb: mkdir -p release docker build -f deb/Dockerfile \ - --build-arg VERSION=$(VERSION) \ - --build-arg DISTRO=xenial \ + --build-arg VERSION=$(patsubst v%,%,$(VERSION)) \ + --build-arg REVISION=$(REVISION) \ --tag $(BUILDIMG) \ . docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf - diff --git a/deb/Dockerfile b/deb/Dockerfile index 1e97b962..c36ae0a3 100644 --- a/deb/Dockerfile +++ b/deb/Dockerfile @@ -1,13 +1,21 @@ -FROM ubuntu:xenial +ARG GO_VERSION=1.18.5 +ARG DISTRO=ubuntu +ARG SUITE=focal -ARG VERSION -ARG DISTRO +FROM golang:${GO_VERSION}-buster AS golang + +FROM ${DISTRO}:${SUITE} -RUN apt-get update && apt-get install -yy debhelper dh-make golang-go libsecret-1-dev +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -yy debhelper dh-make libsecret-1-dev RUN mkdir -p /build WORKDIR /build -ENV GOPATH /build +ENV GOPROXY=https://proxy.golang.org|direct +ENV GO111MODULE=off +ENV GOPATH=/build +ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin +COPY --from=golang /usr/local/go /usr/local/go COPY Makefile . COPY credentials credentials @@ -16,4 +24,12 @@ COPY pass pass COPY deb/debian ./debian COPY deb/build-deb . -RUN /build/build-deb ${VERSION} ${DISTRO} +ARG VERSION +ENV VERSION=${VERSION} +ARG REVISION +ENV REVISION=${REVISION} +ARG DISTRO +ENV DISTRO=${DISTRO} +ARG SUITE +ENV SUITE=${SUITE} +RUN /build/build-deb diff --git a/deb/build-deb b/deb/build-deb index dbb9172d..04d3de1d 100755 --- a/deb/build-deb +++ b/deb/build-deb @@ -1,14 +1,10 @@ #!/usr/bin/env bash -set -x -set -e - -version=$1 -distro=$2 +set -ex maintainer=$(awk -F ': ' '$1 == "Maintainer" { print $2; exit }' debian/control) cat > "debian/changelog" <<-EOF -docker-credential-helpers ($version) $DISTRO; urgency=low +docker-credential-helpers ($VERSION) $DISTRO-$SUITE; urgency=low * New upstream version diff --git a/deb/debian/rules b/deb/debian/rules index e3421e97..4750af38 100755 --- a/deb/debian/rules +++ b/deb/debian/rules @@ -3,7 +3,8 @@ DESTDIR := $(CURDIR)/debian/tmp override_dh_auto_build: - make secretservice pass + make build-secretservice DESTDIR=bin + make build-pass DESTDIR=bin override_dh_auto_install: install -D bin/docker-credential-secretservice $(DESTDIR)/usr/bin/docker-credential-secretservice From a2d8aac9ddc3d32cfa53861c43b0aeb9288269bc Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 26 Aug 2022 23:57:21 +0200 Subject: [PATCH 5/5] ci: add build-deb job Signed-off-by: CrazyMax --- .github/workflows/build.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 62cec628..67a34510 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -155,3 +155,16 @@ jobs: name: docker-credential-helpers path: ${{ env.DESTDIR }}/* if-no-files-found: error + + build-deb: + runs-on: ubuntu-20.04 + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Build + run: | + make deb