Skip to content

Commit

Permalink
Build ta on the host and copy it into the container image (open-telem…
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm authored Nov 6, 2023
1 parent 6a2047c commit a093269
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/publish-target-allocator.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/otel-allocator/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 target allocator for $arch"
make targetallocator 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/otel-allocator
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
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -o bin/manager_${ARCH} -ldflags ${LD_FLAGS} main.go

# Build target allocator binary
targetallocator:
cd cmd/otel-allocator && CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(ARCH) go build -a -installsuffix cgo -o bin/targetallocator_${ARCH} .

# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt vet manifests
Expand Down Expand Up @@ -254,8 +258,9 @@ container-target-allocator-push:
docker push ${TARGETALLOCATOR_IMG}

.PHONY: container-target-allocator
container-target-allocator:
docker buildx build --load --platform linux/${ARCH} -t ${TARGETALLOCATOR_IMG} cmd/otel-allocator
container-target-allocator: GOOS = linux
container-target-allocator: targetallocator
docker build -t ${TARGETALLOCATOR_IMG} cmd/otel-allocator

.PHONY: container-operator-opamp-bridge
container-operator-opamp-bridge:
Expand Down
28 changes: 9 additions & 19 deletions cmd/otel-allocator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
# Build the otel-allocator 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/targetallocator_${TARGETARCH} ./main

ENTRYPOINT ["./main"]

0 comments on commit a093269

Please sign in to comment.