Skip to content

Optimize dockerfile to prevent timeouts #300

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

Merged
merged 3 commits into from
Apr 21, 2025
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
33 changes: 25 additions & 8 deletions .github/workflows/build-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.target-sha }}
ref: ${{ inputs.target-sha }}
repository: ${{inputs.repository}}


Expand Down Expand Up @@ -94,10 +94,27 @@ jobs:
file: ./Dockerfile
context: .
push: true
platforms: linux/amd64, linux/arm64
platforms: linux/amd64,linux/arm64
tags: |
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.target-sha }}
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.target-sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION_PKG=${{ env.VERSION_PKG }}
VERSION=${{ inputs.tag }}
VERSION_DATE=${{ env.VERSION_DATE }}
AGENT_VERSION=${{ env.AGENT_VERSION }}
AUTO_INSTRUMENTATION_JAVA_VERSION=${{ env.AUTO_INSTRUMENTATION_JAVA_VERSION }}
AUTO_INSTRUMENTATION_PYTHON_VERSION=${{ env.AUTO_INSTRUMENTATION_PYTHON_VERSION }}
AUTO_INSTRUMENTATION_DOTNET_VERSION=${{ env.AUTO_INSTRUMENTATION_DOTNET_VERSION }}
AUTO_INSTRUMENTATION_NODEJS_VERSION=${{ env.AUTO_INSTRUMENTATION_NODEJS_VERSION }}
DCMG_EXPORTER_VERSION=${{ env.DCMG_EXPORTER_VERSION }}
NEURON_MONITOR_VERSION=${{ env.NEURON_MONITOR_VERSION }}
TARGET_ALLOCATOR_VERSION=${{ env.TARGET_ALLOCATOR_VERSION }}
outputs: type=image,push=true
provenance: false

MakeTABinary:
name: 'MakeTargetAllocatorImage'
runs-on: ubuntu-latest
Expand Down Expand Up @@ -151,8 +168,8 @@ jobs:
context: ./cmd/amazon-cloudwatch-agent-target-allocator
push: true
tags: |
${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}
${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.target-sha }}
${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}
${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.target-sha }}
platforms: linux/amd64, linux/arm64

bypass-info:
Expand All @@ -179,7 +196,7 @@ jobs:

push-release-ecr:
if: ${{ inputs.release }}
needs: [MakeTABinary, e2e-test]
needs: [ MakeTABinary, e2e-test ]
permissions:
id-token: write
contents: read
Expand All @@ -194,7 +211,7 @@ jobs:
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ env.AWS_ASSUME_ROLE }}
aws-region: ${{inputs.region}}
aws-region: ${{inputs.region}}

- name: Login ECR
id: login-ecr
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/operator-integration-test.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you link the e2e test here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E2E test run that passed on MakeContainerImage step
https://github.com/aws/amazon-cloudwatch-agent/actions/runs/14358637935

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another successful E2E test run

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
kubectl apply -f integration-tests/manifests/cloudwatch-agent-daemonset.yaml -n amazon-cloudwatch
sleep 20
kubectl wait --for=condition=Ready pod --all -n amazon-cloudwatch

pod_name="$(kubectl get pods -n amazon-cloudwatch -l app.kubernetes.io/component=amazon-cloudwatch-agent,app.kubernetes.io/instance=amazon-cloudwatch.cloudwatch-agent -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')"
if [ -z "$pod_name" ]; then
echo "Pod $pod_name is not created. Exiting with ERROR."
Expand All @@ -74,9 +74,9 @@ jobs:
- name: Test for default instrumentation resources for Java
run: |
kubectl apply -f integration-tests/java/sample-deployment-java.yaml
sleep 5
sleep 5
kubectl wait --for=condition=Ready pod --all -n default
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/java/default_instrumentation_java_env_variables.json app_signals

Expand All @@ -86,16 +86,16 @@ jobs:
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals

go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
kubectl delete instrumentation sample-instrumentation

- name: Test for default instrumentation resources for python
run: |
kubectl apply -f integration-tests/python/sample-deployment-python.yaml
sleep 5
kubectl wait --for=condition=Ready pod --all -n default --timeout=120s
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/python/default_instrumentation_python_env_variables.json app_signals

Expand All @@ -114,7 +114,7 @@ jobs:
kubectl apply -f integration-tests/dotnet/sample-deployment-dotnet.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/dotnet/default_instrumentation_dotnet_env_variables.json app_signals

Expand All @@ -123,7 +123,7 @@ jobs:
kubectl apply -f integration-tests/manifests/sample-instrumentation.yaml
kubectl delete pods --all -n default
sleep 5
kubectl wait --for=condition=Ready pod --all -n default
kubectl wait --for=condition=Ready pod --all -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/manifests/cmd/ns_instrumentation_env_variables.json app_signals
kubectl delete instrumentation sample-instrumentation

Expand All @@ -135,7 +135,7 @@ jobs:
kubectl apply -f integration-tests/nodejs/sample-deployment-nodejs.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/nodejs/default_instrumentation_nodejs_env_variables.json app_signals

Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
kubectl apply -f integration-tests/jmx/sample-deployment-jmx.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/jmx/default_instrumentation_jmx_env_variables.json app_signals

Expand All @@ -196,7 +196,7 @@ jobs:
kubectl apply -f integration-tests/manifests/cloudwatch-agent-daemonset-no-app-signals.yaml -n amazon-cloudwatch
sleep 20
kubectl wait --for=condition=Ready pod --all -n amazon-cloudwatch

pod_name="$(kubectl get pods -n amazon-cloudwatch -l app.kubernetes.io/component=amazon-cloudwatch-agent,app.kubernetes.io/instance=amazon-cloudwatch.cloudwatch-agent -o=jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')"
if [ -z "$pod_name" ]; then
echo "Pod $pod_name is not created. Exiting with ERROR."
Expand All @@ -214,7 +214,7 @@ jobs:
kubectl apply -f integration-tests/jmx/sample-deployment-jmx.yaml
sleep 5
kubectl wait --for=condition=Available deployment/nginx -n default
kubectl get pods -A
kubectl get pods -A
kubectl describe pods -n default
go run integration-tests/manifests/cmd/validate_instrumentation_vars.go default integration-tests/jmx/default_instrumentation_jmx_env_variables_no_app_signals.json no_app_signals

Expand Down Expand Up @@ -429,7 +429,7 @@ jobs:
sleep 5
go test -v -run TestJavaOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
go test -v -run TestPythonOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
go test -v -run TestPythonOnlyNamespace ./integration-tests/manifests/annotations -timeout 45m
sleep 5
go test -v -run TestDotNetOnlyNamespace ./integration-tests/manifests/annotations -timeout 30m
sleep 5
Expand Down
66 changes: 40 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
# Build the manager binary
FROM golang:1.23 as builder

# set goproxy=direct
ENV GOPROXY direct

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY apis/ apis/
COPY controllers/ controllers/
COPY internal/ internal/
COPY pkg/ pkg/
COPY versions.txt versions.txt
# syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder

# Set build arguments early
ARG TARGETARCH
ARG VERSION_PKG
ARG VERSION
ARG VERSION_DATE
Expand All @@ -32,14 +15,45 @@ ARG DCMG_EXPORTER_VERSION
ARG NEURON_MONITOR_VERSION
ARG TARGET_ALLOCATOR_VERSION

# Build
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.agent=${AGENT_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} -X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGET_ALLOCATOR_VERSION}" -a -o manager main.go
# Set environment variables
ENV GOPROXY="https://proxy.golang.org,direct" \
GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=$TARGETARCH \
GOPRIVATE="" \
GOSUMDB=on

WORKDIR /workspace

# Download dependencies with cache mount
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download

# Copy only necessary files
COPY . .

# Build with cache mount
RUN --mount=type=cache,target=/root/.cache/go-build \
go build \
-trimpath \
-ldflags="\
-X ${VERSION_PKG}.version=${VERSION} \
-X ${VERSION_PKG}.buildDate=${VERSION_DATE} \
-X ${VERSION_PKG}.agent=${AGENT_VERSION} \
-X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} \
-X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION} \
-X ${VERSION_PKG}.autoInstrumentationDotNet=${AUTO_INSTRUMENTATION_DOTNET_VERSION} \
-X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} \
-X ${VERSION_PKG}.dcgmExporter=${DCMG_EXPORTER_VERSION} \
-X ${VERSION_PKG}.neuronMonitor=${NEURON_MONITOR_VERSION} \
-X ${VERSION_PKG}.targetAllocator=${TARGET_ALLOCATOR_VERSION}" \
-o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
4 changes: 2 additions & 2 deletions integration-tests/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"k8s.io/client-go/kubernetes"
)

const TimoutDuration = 2 * time.Minute
const TimeBetweenRetries = 2 * time.Second
const TimoutDuration = 3 * time.Minute
const TimeBetweenRetries = 5 * time.Second

// WaitForNewPodCreation takes in a resource either Deployment, DaemonSet, or StatefulSet wait until it is in running stage
func WaitForNewPodCreation(clientSet *kubernetes.Clientset, resource interface{}, startTime time.Time) error {
Expand Down
Loading