From 51b5f7fd989f031a5a1420f73c403e62421061f9 Mon Sep 17 00:00:00 2001 From: Gordon Bleux <33967640+UiP9AV6Y@users.noreply.github.com> Date: Sat, 10 Oct 2026 11:58:14 +0200 Subject: [PATCH] use `make` for building in every context instead of building the application in different ways in different places, use `make` as the single point of truth. the application version still needs to be provided by the caller, while the VCS reference is automatically determined by the Makefile --- .dockerignore | 3 +++ .github/workflows/container.yml | 3 +-- Dockerfile | 15 ++++++++------- Makefile | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c95930a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.github +testdata +contrib diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index e99024a..197884f 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -24,8 +24,7 @@ jobs: - uses: actions/checkout@v7 - name: Build image - run: | - docker build --file Dockerfile --tag ghcr.io/netways/alertmanager-icinga-bridge --build-arg "BRIDGE_VERSION=${GITHUB_REF}" --build-arg "BRIDGE_COMMIT=${GITHUB_SHA}" . + run: make build-image CONTAINER_RUNTIME=docker "VERSION=${GITHUB_REF}" - name: Log in to registry run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin diff --git a/Dockerfile b/Dockerfile index cb4957a..f5cbd4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,23 +3,24 @@ # Build Image FROM docker.io/golang:1.27-trixie AS builder -ARG BRIDGE_VERSION=development -ARG BRIDGE_COMMIT=HEAD +WORKDIR /go/src/app -ENV CGO_ENABLED=0 +COPY go.mod go.sum ./ +RUN set -xe; \ + go mod download -WORKDIR /go/src/app -COPY . . +ARG BRIDGE_VERSION=development +COPY . . RUN set -ex; \ - go build -ldflags="-s -w -X main.version=${BRIDGE_VERSION} -X main.commit=${BRIDGE_COMMIT}" -o /go/bin/alertmanager-icinga-bridge + make release "VERSION=${BRIDGE_VERSION}" # Final Image FROM gcr.io/distroless/static-debian13:nonroot WORKDIR / -COPY --from=builder /go/bin/alertmanager-icinga-bridge / +COPY --from=builder /go/src/app/dist/ / EXPOSE 8888 diff --git a/Makefile b/Makefile index d893622..d5d0a72 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ VERSION?=latest build-image: $(CONTAINER_RUNTIME) build --pull \ --build-arg BRIDGE_VERSION=$(VERSION) \ - --build-arg BRIDGE_COMMIT=$(COMMIT) \ -t ghcr.io/netways/alertmanager-icinga-bridge:latest . build: mkdir -p dist; \