From c064339732aebef6bd98f7dc11b51f824b326cb2 Mon Sep 17 00:00:00 2001 From: Joel Takvorian Date: Thu, 10 Oct 2024 16:59:56 +0200 Subject: [PATCH] Distinguish "clean builds" and dev builds It will save time during rebuilds for the developers, since the current time isn't passed to the go build anymore, which was previously forcing to refresh the docker layers --- .github/workflows/push_image.yml | 8 ++++---- .github/workflows/push_image_pr.yml | 2 +- .github/workflows/release.yml | 2 +- Dockerfile | 5 ++--- Makefile | 23 +++++++---------------- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index a8845b6c9..cfa909515 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -35,14 +35,14 @@ jobs: run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: build and push manifest with images run: | - MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} make images - MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.short_sha }} OCI_BUILD_OPTS="--label quay.expires-after=2w" make images + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} CLEAN_BUILD=1 make images + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.short_sha }} CLEAN_BUILD=1 OCI_BUILD_OPTS="--label quay.expires-after=2w" make images if [[ "main" == "$WF_VERSION" ]]; then - MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=latest make images + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=latest CLEAN_BUILD=1 make images fi - name: build and push manifest with images for standalone build run: | - MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} STANDALONE=true make images + MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.WF_VERSION }} CLEAN_BUILD=1 STANDALONE=true make images codecov-back: name: Codecov backend upload diff --git a/.github/workflows/push_image_pr.yml b/.github/workflows/push_image_pr.yml index 588ad3c26..6b1cf3bfb 100644 --- a/.github/workflows/push_image_pr.yml +++ b/.github/workflows/push_image_pr.yml @@ -37,7 +37,7 @@ jobs: - name: get short sha run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - name: build and push manifest with images - run: OCI_BUILD_OPTS="--label quay.expires-after=2w" IMAGE_ORG=${{ env.WF_ORG }} IMAGE=${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }} make images + run: OCI_BUILD_OPTS="--label quay.expires-after=2w" IMAGE_ORG=${{ env.WF_ORG }} IMAGE=${{ env.WF_REGISTRY }}/${{ env.WF_IMAGE }}:${{ env.short_sha }} CLEAN_BUILD=1 make images - uses: actions/github-script@v6 with: github-token: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 94d256491..f2482e37d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,4 +42,4 @@ jobs: password: ${{ secrets.QUAY_SECRET }} registry: quay.io - name: build and push manifest with images - run: MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.tag }} make images + run: MULTIARCH_TARGETS="${{ env.WF_MULTIARCH_TARGETS }}" IMAGE_ORG=${{ env.WF_ORG }} VERSION=${{ env.tag }} CLEAN_BUILD=1 make images diff --git a/Dockerfile b/Dockerfile index 8c8bb5168..3258f99b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,21 +24,20 @@ RUN npm run build$BUILDSCRIPT FROM docker.io/library/golang:1.22 as go-builder -ARG TARGETPLATFORM ARG TARGETARCH=amd64 ARG LDFLAGS + WORKDIR /opt/app-root COPY go.mod go.mod COPY go.sum go.sum COPY vendor/ vendor/ -COPY .mk/ .mk/ COPY cmd/ cmd/ COPY pkg/ pkg/ RUN CGO_ENABLED=0 GOARCH=$TARGETARCH go build -ldflags "$LDFLAGS" -mod vendor -o plugin-backend cmd/plugin-backend.go -FROM --platform=linux/$TARGETARCH registry.access.redhat.com/ubi9/ubi-minimal:9.4 +FROM --platform=linux/$TARGETARCH registry.access.redhat.com/ubi9/ubi-minimal:9.4 COPY --from=web-builder /opt/app-root/web/dist ./web/dist COPY --from=go-builder /opt/app-root/plugin-backend ./ diff --git a/Makefile b/Makefile index 84706ab25..3cbb5ffc5 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,6 @@ # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) VERSION ?= main -BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M) -TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1) -TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true) -BUILD_SHA := $(shell git rev-parse --short HEAD) -BUILD_VERSION := $(TAG:v%=%) -ifneq ($(COMMIT), $(TAG_COMMIT)) - BUILD_VERSION := $(BUILD_VERSION)-$(BUILD_SHA) -endif -ifneq ($(shell git status --porcelain),) - BUILD_VERSION := $(BUILD_VERSION)-dirty -endif # Go architecture and targets images to build GOARCH ?= amd64 @@ -41,18 +30,20 @@ endif # Image URL to use all building/pushing image targets IMAGE ?= ${IMAGE_TAG_BASE}:${VERSION} -OCI_BUILD_OPTS ?= - # Image building tool (docker / podman) - docker is preferred in CI OCI_BIN_PATH = $(shell which docker 2>/dev/null || which podman) OCI_BIN ?= $(shell basename ${OCI_BIN_PATH}) +OCI_BUILD_OPTS ?= + +ifneq ($(CLEAN_BUILD),) + BUILD_DATE := $(shell date +%Y-%m-%d\ %H:%M) + BUILD_SHA := $(shell git rev-parse --short HEAD) + LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}' +endif GOLANGCI_LINT_VERSION = v1.53.3 NPM_INSTALL ?= install CMDLINE_ARGS ?= --loglevel trace --config config/config.yaml -LDFLAGS := -X 'main.buildVersion=${BUILD_VERSION}' -X 'main.buildDate=${BUILD_DATE}' -# You can add GO Build flags like -gcflags=all="-N -l" here to remove optimizations for debugging -BUILD_FLAGS ?= -ldflags "${LDFLAGS}" .DEFAULT_GOAL := help