Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build opamp-bridge on the host #2296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/publish-operator-opamp-bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 9 additions & 19 deletions cmd/operator-opamp-bridge/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Loading