From f97df1c0a84e4326fa60a0af005da2ee57d55237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Tue, 31 Oct 2023 11:59:48 +0100 Subject: [PATCH] Build opamp-bridge on the host --- .../publish-operator-opamp-bridge.yaml | 22 ++++++++++++--- Makefile | 9 ++++-- cmd/operator-opamp-bridge/Dockerfile | 28 ++++++------------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.github/workflows/publish-operator-opamp-bridge.yaml b/.github/workflows/publish-operator-opamp-bridge.yaml index 8493d37472..c5833b554d 100644 --- a/.github/workflows/publish-operator-opamp-bridge.yaml +++ b/.github/workflows/publish-operator-opamp-bridge.yaml @@ -11,18 +11,35 @@ on: - 'v*' workflow_dispatch: +env: + PLATFORMS: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le + jobs: publish: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 + + - uses: actions/setup-go@v4 + with: + go-version: '~1.21.3' + cache-dependency-path: 'cmd/operator-opamp-bridge/go.sum' + # TODO: We're currently not using this. Should we? - name: Read version run: | echo "VERSION=$(git describe --tags | sed 's/^v//')" >> $GITHUB_ENV echo "VERSION_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + - name: Build the binary for each supported architecture + run: | + for platform in $(echo $PLATFORMS | tr "," "\n"); do + arch=${platform#*/} + echo "Building operator-opamp-bridge for $arch" + make operator-opamp-bridge ARCH=$arch + done + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -69,11 +86,8 @@ jobs: uses: docker/build-push-action@v5 with: context: cmd/operator-opamp-bridge - platforms: linux/amd64,linux/arm64,linux/s390x,linux/ppc64le + platforms: ${{ env.PLATFORMS }} push: true - build-args: | - VERSION=${{ env.VERSION }} - VERSION_DATE=${{ env.VERSION_DATE }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=local,src=/tmp/.buildx-cache diff --git a/Makefile b/Makefile index 863009f04c..5c04861dd8 100644 --- a/Makefile +++ b/Makefile @@ -108,6 +108,10 @@ test: generate fmt vet ensure-generate-is-noop envtest manager: generate fmt vet go build -o bin/manager main.go +# Build opamp bridge binary +operator-opamp-bridge: + cd cmd/operator-opamp-bridge && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -a -installsuffix cgo -o bin/opampbridge_${ARCH} . + # Run against the configured Kubernetes cluster in ~/.kube/config .PHONY: run run: generate fmt vet manifests @@ -257,8 +261,9 @@ container-target-allocator: docker buildx build --load --platform linux/${ARCH} -t ${TARGETALLOCATOR_IMG} cmd/otel-allocator .PHONY: container-operator-opamp-bridge -container-operator-opamp-bridge: - docker buildx build --platform linux/${ARCH} -t ${OPERATOROPAMPBRIDGE_IMG} cmd/operator-opamp-bridge +container-operator-opamp-bridge: GOOS = linux +container-operator-opamp-bridge: operator-opamp-bridge + docker build -t ${OPERATOROPAMPBRIDGE_IMG} cmd/operator-opamp-bridge .PHONY: start-kind start-kind: diff --git a/cmd/operator-opamp-bridge/Dockerfile b/cmd/operator-opamp-bridge/Dockerfile index 0ec1b6581d..ae8a861b89 100644 --- a/cmd/operator-opamp-bridge/Dockerfile +++ b/cmd/operator-opamp-bridge/Dockerfile @@ -1,29 +1,19 @@ -# Build the operator-opamp-bridge binary -FROM golang:1.21-alpine as builder - -WORKDIR /app +# Get CA certificates from the Alpine package repo +FROM alpine:3.18 as certificates RUN apk --no-cache add ca-certificates -# Copy go mod and sum files -COPY go.mod go.sum ./ - -RUN go mod download - -COPY . . - -# Build the Go app -RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . - -######## Start a new stage from scratch ####### +# Start a new stage from scratch FROM scratch +ARG TARGETARCH + WORKDIR /root/ -# Copy the certs from the builder -COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +# Copy the certs +COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt -# Copy the pre-built binary file from the previous stage -COPY --from=builder /app/main . +# Copy binary built on the host +COPY bin/opampbridge_${TARGETARCH} ./main ENTRYPOINT ["./main"]