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: Build docker without open telemetry collector #228

Merged
merged 2 commits into from
Jun 19, 2021
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
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ config-downloader: copy-version-file
$(DARWIN_BUILD)/config-downloader github.com/aws/amazon-cloudwatch-agent/cmd/config-downloader

# A fast build that only builds amd64, we don't need wizard and config downloader
build-for-docker:
build-for-docker: build-for-docker-amd64

build-for-docker-amd64:
$(LINUX_AMD64_BUILD)/amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent
$(LINUX_AMD64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(LINUX_AMD64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator

build-for-docker-arm64:
$(LINUX_ARM64_BUILD)/amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/amazon-cloudwatch-agent
$(LINUX_ARM64_BUILD)/start-amazon-cloudwatch-agent github.com/aws/amazon-cloudwatch-agent/cmd/start-amazon-cloudwatch-agent
$(LINUX_ARM64_BUILD)/config-translator github.com/aws/amazon-cloudwatch-agent/cmd/config-translator

fmt:
go fmt ./...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ docker buildx create --name multi-builder
docker buildx use multi-builder
# Add proper tag and --push if you want to publish it
docker buildx build --platform linux/amd64,linux/arm64 .
# To build multi arch image from soruce code, run the following at project root
docker buildx build --platform linux/amd64,linux/arm64 -f amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile/Dockerfile .
```

### Build multi arch image manifest from single arch images
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@ ARG GO_IMAGE=golang:latest
ARG CERT_IMAGE=ubuntu:latest
FROM $GO_IMAGE as builder

# NOTE: This arg will be populated by docker buildx
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH
RUN mkdir -p /go/src/github.com/aws/amazon-cloudwatch-agent/
WORKDIR /go/src/github.com/aws/amazon-cloudwatch-agent/

ARG GO111MODULE="on"
ENV GO111MODULE=${GO111MODULE}

COPY . /go/src/github.com/aws/amazon-cloudwatch-agent/
RUN make build && make package-deb
RUN make build-for-docker-${TARGETARCH}

# Install cert and binaries
FROM $CERT_IMAGE as cert

# NOTE: This arg will be populated by docker buildx
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
# Need to repeat the ARG after each FROM
ARG TARGETARCH
RUN mkdir -p /opt/aws/amazon-cloudwatch-agent/etc
RUN mkdir -p /opt/aws/amazon-cloudwatch-agent/var
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /go/src/github.com/aws/amazon-cloudwatch-agent/build/bin/linux/ /tmp/deb
RUN dpkg -i -E /tmp/deb/${TARGETARCH:-$(dpkg --print-architecture)}/amazon-cloudwatch-agent.deb
COPY --from=builder /go/src/github.com/aws/amazon-cloudwatch-agent/build/bin/linux_${TARGETARCH}/ /opt/aws/amazon-cloudwatch-agent/bin

FROM scratch

Expand Down