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

fix: rewrite Dockerfile to resolve architecture mismatch issues #307

Merged
merged 2 commits into from
Apr 25, 2024
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
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ OS ?= $(GOOS)
ARCH ?= $(GOARCH)
PLATFORM ?= $(OS)/$(ARCH)
PLATFORMS ?= linux/amd64 linux/arm64 windows/amd64
OS_VERSION ?= ltsc2019

CONTAINER_BUILDER ?= docker
CONTAINER_RUNTIME ?= docker
Expand Down Expand Up @@ -214,10 +215,11 @@ container-docker: buildx # util target to build container images using docker bu
--platform $(PLATFORM) \
--metadata-file=$$image_metadata_filename \
-f $(DOCKERFILE) \
--build-arg VERSION=$(VERSION) $(EXTRA_BUILD_ARGS) \
--build-arg GOOS=$$os \
--build-arg GOARCH=$$arch \
--build-arg APP_INSIGHTS_ID=$(APP_INSIGHTS_ID) \
--build-arg GOARCH=$$arch \
--build-arg GOOS=$$os \
--build-arg OS_VERSION=$(OS_VERSION) \
--build-arg VERSION=$(VERSION) $(EXTRA_BUILD_ARGS) \
--target=$(TARGET) \
-t $(IMAGE_REGISTRY)/$(IMAGE):$(TAG) \
$(CONTEXT_DIR)
Expand All @@ -233,7 +235,7 @@ retina-image: ## build the retina linux container image.
fi; \
$(MAKE) container-$(CONTAINER_BUILDER) \
PLATFORM=$(PLATFORM) \
DOCKERFILE=controller/Dockerfile.controller \
DOCKERFILE=controller/Dockerfile \
REGISTRY=$(IMAGE_REGISTRY) \
IMAGE=$$image_name \
VERSION=$(TAG) \
Expand All @@ -249,11 +251,13 @@ retina-image-win: ## build the retina Windows container image.
echo "Building $(RETINA_PLATFORM_TAG)"; \
$(MAKE) container-$(CONTAINER_BUILDER) \
PLATFORM=windows/amd64 \
DOCKERFILE=controller/Dockerfile.windows-$$year \
DOCKERFILE=controller/Dockerfile \
REGISTRY=$(IMAGE_REGISTRY) \
IMAGE=$(RETINA_IMAGE) \
OS_VERSION=ltsc$$year \
VERSION=$(TAG) \
TAG=$$tag \
TARGET=agent-win \
CONTEXT_DIR=$(REPO_ROOT); \
done

Expand Down
91 changes: 91 additions & 0 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
ARG OS_VERSION=ltsc2019

# capture binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS capture-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ARG VERSION
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/captureworkload -ldflags "-X main.version="$VERSION" -X main.applicationInsightsID="$APP_INSIGHTS_ID"" captureworkload/main.go


# controller binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS controller-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ARG VERSION
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/controller -ldflags "-X main.version="$VERSION" -X main.applicationInsightsID="$APP_INSIGHTS_ID"" controller/main.go


# init binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS init-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ARG VERSION
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/initretina -ldflags "-X main.version="$VERSION" -X main.applicationInsightsID="$APP_INSIGHTS_ID"" init/retina/main_linux.go


# tools image
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/mirror/docker/library/debian:bookworm@sha256:1aadfee8d292f64b045adb830f8a58bfacc15789ae5f489a0fedcd517a862cb9 AS tools
RUN apt-get update && \
apt-get install -y \
apt-file \
clang \
curl \
gnupg2 \
iproute2 \
iptables \
tcpdump

RUN mkdir -p /tmp/bin
RUN arr="clang tcpdump ip ss iptables-legacy iptables-legacy-save iptables-nft iptables-nft-save cp uname" ;\
for i in $arr; do \
cp $(which $i) /tmp/bin; \
done


# init final image
FROM --platform=$TARGETPLATFORM gcr.io/distroless/cc-debian12:debug as init
COPY --from=init-bin /go/bin/retina/initretina /retina/initretina
COPY --from=tools /lib/ /lib
COPY --from=tools /usr/lib/ /usr/lib
COPY --from=tools /bin/mount /bin/mount
ENTRYPOINT ["./retina/initretina"]


# agent final image
FROM --platform=$TARGETPLATFORM gcr.io/distroless/cc-debian12:debug as agent
COPY --from=tools /lib/ /lib
COPY --from=tools /usr/lib/ /usr/lib
COPY --from=tools /tmp/bin/ /bin
COPY --from=controller-bin /go/bin/retina/controller /retina/controller
COPY --from=controller-bin /go/src/github.com/microsoft/retina/pkg/plugin /go/src/github.com/microsoft/retina/pkg/plugin
COPY --from=capture-bin /go/bin/retina/captureworkload /retina/captureworkload
ENTRYPOINT ["./retina/controller"]


# agent final image for win2019
FROM --platform=$TARGETPLATFORM mcr.microsoft.com/windows/servercore:${OS_VERSION} as agent-win
COPY --from=controller-bin /go/src/github.com/microsoft/retina/windows/kubeconfigtemplate.yaml kubeconfigtemplate.yaml
COPY --from=controller-bin /go/src/github.com/microsoft/retina/windows/setkubeconfigpath.ps1 setkubeconfigpath.ps1
COPY --from=controller-bin /go/bin/retina/controller controller.exe
COPY --from=capture-bin /go/bin/retina/captureworkload captureworkload.exe
ADD https://github.com/microsoft/etl2pcapng/releases/download/v1.10.0/etl2pcapng.exe /etl2pcapng.exe
CMD ["controller.exe", "start", "--kubeconfig=.\\kubeconfig"]
136 changes: 0 additions & 136 deletions controller/Dockerfile.controller

This file was deleted.

25 changes: 0 additions & 25 deletions controller/Dockerfile.windows-2019

This file was deleted.

26 changes: 0 additions & 26 deletions controller/Dockerfile.windows-2022

This file was deleted.

Loading