From 03bb194d2c577b333c5ad88e0096a21c65dba5b0 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:05:27 +0100 Subject: [PATCH] Docker: allow setting BUILD_VERSION as a build argument (#2736) * Docker: allow setting BUILD_VERSION as a build argument * CI: don't attempt to publish docker images outside of crowdecurity org * use go 1.21.6 for docker and windows too --- .github/workflows/publish_docker-image_on_master-debian.yml | 1 + .github/workflows/publish_docker-image_on_master.yml | 1 + Dockerfile | 4 +++- Dockerfile.debian | 4 +++- azure-pipelines.yml | 4 ++-- mk/platform/unix_common.mk | 6 +++++- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_docker-image_on_master-debian.yml b/.github/workflows/publish_docker-image_on_master-debian.yml index 88076157c..17332adf0 100644 --- a/.github/workflows/publish_docker-image_on_master-debian.yml +++ b/.github/workflows/publish_docker-image_on_master-debian.yml @@ -19,6 +19,7 @@ jobs: push_to_registry: name: Push Debian Docker image to Docker Hub runs-on: ubuntu-latest + if: ${{ github.repository_owner == 'crowdsecurity' }} steps: - name: Check out the repo diff --git a/.github/workflows/publish_docker-image_on_master.yml b/.github/workflows/publish_docker-image_on_master.yml index 6cab486b0..345290200 100644 --- a/.github/workflows/publish_docker-image_on_master.yml +++ b/.github/workflows/publish_docker-image_on_master.yml @@ -19,6 +19,7 @@ jobs: push_to_registry: name: Push Docker image to Docker Hub runs-on: ubuntu-latest + if: ${{ github.repository_owner == 'crowdsecurity' }} steps: - name: Check out the repo diff --git a/Dockerfile b/Dockerfile index 3b95ca3c4..7470beb57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,6 @@ # vim: set ft=dockerfile: -ARG GOVERSION=1.21.5 +ARG GOVERSION=1.21.6 +ARG BUILD_VERSION FROM golang:${GOVERSION}-alpine3.18 AS build @@ -7,6 +8,7 @@ WORKDIR /go/src/crowdsec # We like to choose the release of re2 to use, and Alpine does not ship a static version anyway. ENV RE2_VERSION=2023-03-01 +ENV BUILD_VERSION=${BUILD_VERSION} # wizard.sh requires GNU coreutils RUN apk add --no-cache git g++ gcc libc-dev make bash gettext binutils-gold coreutils pkgconfig && \ diff --git a/Dockerfile.debian b/Dockerfile.debian index 2f116aa73..bc5b0aa2d 100644 --- a/Dockerfile.debian +++ b/Dockerfile.debian @@ -1,5 +1,6 @@ # vim: set ft=dockerfile: -ARG GOVERSION=1.21.5 +ARG GOVERSION=1.21.6 +ARG BUILD_VERSION FROM golang:${GOVERSION}-bookworm AS build @@ -10,6 +11,7 @@ ENV DEBCONF_NOWARNINGS="yes" # We like to choose the release of re2 to use, the debian version is usually older. ENV RE2_VERSION=2023-03-01 +ENV BUILD_VERSION=${BUILD_VERSION} # wizard.sh requires GNU coreutils RUN apt-get update && \ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1b7cd4960..82caba42b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,9 +25,9 @@ stages: custom: 'tool' arguments: 'install --global SignClient --version 1.3.155' - task: GoTool@0 - displayName: "Install Go 1.20" + displayName: "Install Go" inputs: - version: '1.21.5' + version: '1.21.6' - pwsh: | choco install -y make diff --git a/mk/platform/unix_common.mk b/mk/platform/unix_common.mk index 8f06c9328..5e5b5de3a 100644 --- a/mk/platform/unix_common.mk +++ b/mk/platform/unix_common.mk @@ -8,7 +8,11 @@ MKDIR=mkdir -p GOOS ?= $(shell go env GOOS) # Current versioning information from env -BUILD_VERSION?=$(shell git describe --tags) +# The $(or) is used to ignore an empty BUILD_VERSION when it's an envvar, +# like inside a docker build: docker build --build-arg BUILD_VERSION=1.2.3 +# as opposed to a make parameter: make BUILD_VERSION=1.2.3 +BUILD_VERSION:=$(or $(BUILD_VERSION),$(shell git describe --tags --dirty)) + BUILD_TIMESTAMP=$(shell date +%F"_"%T) DEFAULT_CONFIGDIR?=/etc/crowdsec DEFAULT_DATADIR?=/var/lib/crowdsec/data