|
| 1 | +# Dockerfile for the Migration agent, configured to use an AWS CodeArtifact |
| 2 | +# mirror of Maven Central instead of hitting repo.maven.apache.org directly. |
| 3 | +# This eliminates the HTTP 429 rate-limit failures seen under high-concurrency |
| 4 | +# RL training. |
| 5 | +# |
| 6 | +# Prerequisites (run once outside this Dockerfile): |
| 7 | +# aws codeartifact create-domain --domain migration-aws-maven-mirror --region us-west-2 |
| 8 | +# aws codeartifact create-repository --domain migration-aws-maven-mirror --repository maven-central-cache --region us-west-2 |
| 9 | +# aws codeartifact associate-external-connection \ |
| 10 | +# --domain migration-aws-maven-mirror --repository maven-central-cache \ |
| 11 | +# --external-connection public:maven-central --region us-west-2 |
| 12 | +# # Grant the AgentCoreRuntime IAM role codeartifact:GetAuthorizationToken |
| 13 | +# # and codeartifact:ReadFromRepository: |
| 14 | +# aws iam put-role-policy \ |
| 15 | +# --role-name AgentCoreRuntime \ |
| 16 | +# --policy-name CodeArtifactReadAccess \ |
| 17 | +# --policy-document '{ |
| 18 | +# "Version": "2012-10-17", |
| 19 | +# "Statement": [ |
| 20 | +# { |
| 21 | +# "Sid": "CodeArtifactRead", |
| 22 | +# "Effect": "Allow", |
| 23 | +# "Action": [ |
| 24 | +# "codeartifact:GetAuthorizationToken", |
| 25 | +# "codeartifact:ReadFromRepository", |
| 26 | +# "codeartifact:GetRepositoryEndpoint" |
| 27 | +# ], |
| 28 | +# "Resource": "*" |
| 29 | +# }, |
| 30 | +# { |
| 31 | +# "Sid": "STSServiceBearerToken", |
| 32 | +# "Effect": "Allow", |
| 33 | +# "Action": "sts:GetServiceBearerToken", |
| 34 | +# "Resource": "*", |
| 35 | +# "Condition": { |
| 36 | +# "StringEquals": { |
| 37 | +# "sts:AWSServiceName": "codeartifact.amazonaws.com" |
| 38 | +# } |
| 39 | +# } |
| 40 | +# } |
| 41 | +# ] |
| 42 | +# }' |
| 43 | + |
| 44 | +FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim |
| 45 | +WORKDIR /app |
| 46 | + |
| 47 | +# All environment variables in one layer |
| 48 | +ENV UV_SYSTEM_PYTHON=1 \ |
| 49 | + UV_COMPILE_BYTECODE=1 \ |
| 50 | + UV_NO_PROGRESS=1 \ |
| 51 | + PYTHONUNBUFFERED=1 \ |
| 52 | + DOCKER_CONTAINER=1 \ |
| 53 | + AWS_REGION=us-west-2 \ |
| 54 | + AWS_DEFAULT_REGION=us-west-2 \ |
| 55 | + CODEARTIFACT_DOMAIN=migration-aws-maven-mirror \ |
| 56 | + CODEARTIFACT_DOMAIN_OWNER={your-aws-account-number} |
| 57 | + |
| 58 | +# ---------- Java code migration specific requirements ---------- |
| 59 | +# 1. Install Java 17 as root user |
| 60 | +RUN apt-get update && \ |
| 61 | + apt-get install -y openjdk-17-jdk && \ |
| 62 | + apt-get clean && \ |
| 63 | + rm -rf /var/lib/apt/lists/* |
| 64 | + |
| 65 | +# Verify Java installation |
| 66 | +RUN echo "=== Java Installation Verification ===" && \ |
| 67 | + java --version && \ |
| 68 | + which java |
| 69 | + |
| 70 | +# 2. Install maven |
| 71 | +# install tools needed for Maven first |
| 72 | +RUN apt-get update && \ |
| 73 | + apt-get install -y curl unzip && \ |
| 74 | + apt-get clean && \ |
| 75 | + rm -rf /var/lib/apt/lists/* |
| 76 | + |
| 77 | +RUN curl -O https://archive.apache.org/dist/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.zip && \ |
| 78 | + unzip apache-maven-3.9.6-bin.zip -d /opt/ && \ |
| 79 | + rm apache-maven-3.9.6-bin.zip && \ |
| 80 | + ln -s /opt/apache-maven-3.9.6 /opt/maven |
| 81 | + |
| 82 | +# Set Maven environment variables |
| 83 | +ENV MAVEN_HOME=/opt/maven |
| 84 | +ENV PATH=$MAVEN_HOME/bin:$PATH |
| 85 | + |
| 86 | +RUN echo "=== Maven Installation Verification ===" && mvn --version |
| 87 | + |
| 88 | +# 3. Install Node.js (prevents some frontend plugins from downloading it |
| 89 | +# at runtime, which incurs latency & introduces spammy logs) |
| 90 | +RUN apt-get update && \ |
| 91 | + apt-get install -y --no-install-recommends nodejs && \ |
| 92 | + apt-get clean && \ |
| 93 | + rm -rf /var/lib/apt/lists/* |
| 94 | + |
| 95 | +# 4. Install git |
| 96 | +RUN apt-get update && \ |
| 97 | + apt-get install -y git && \ |
| 98 | + apt-get clean && \ |
| 99 | + rm -rf /var/lib/apt/lists/* && \ |
| 100 | + git config --system --add safe.directory '*' && \ |
| 101 | + git config --system user.email "no-reply@amazon.com" && \ |
| 102 | + git config --system user.name "NoReply Amazon" |
| 103 | + |
| 104 | +# 5. Install AWS CLI v2 (needed at runtime to fetch CodeArtifact auth tokens). |
| 105 | +# The uv base image doesn't include it. |
| 106 | +RUN ARCH=$(uname -m) && \ |
| 107 | + case "$ARCH" in \ |
| 108 | + x86_64) AWS_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" ;; \ |
| 109 | + aarch64) AWS_URL="https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" ;; \ |
| 110 | + *) echo "Unsupported architecture: $ARCH"; exit 1 ;; \ |
| 111 | + esac && \ |
| 112 | + curl -sSL "$AWS_URL" -o /tmp/awscliv2.zip && \ |
| 113 | + unzip -q /tmp/awscliv2.zip -d /tmp && \ |
| 114 | + /tmp/aws/install && \ |
| 115 | + rm -rf /tmp/awscliv2.zip /tmp/aws && \ |
| 116 | + aws --version |
| 117 | + |
| 118 | +# ---------- |
| 119 | + |
| 120 | +COPY . . |
| 121 | +# Install local toolkit from build context, then install example deps |
| 122 | +RUN --mount=type=bind,from=toolkit,source=.,target=/toolkit \ |
| 123 | + uv pip install /toolkit && uv pip install . |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | +RUN uv pip install aws-opentelemetry-distro==0.12.2 |
| 128 | + |
| 129 | +# 6. Install Maven settings.xml that mirrors all traffic through AWS CodeArtifact. |
| 130 | +# Placed at two locations: |
| 131 | +# - /opt/maven/conf/settings.xml (global, used by any user running mvn) |
| 132 | +# - /home/bedrock_agentcore/.m2/settings.xml (per-user, explicit) |
| 133 | +# Both point to the same file; Maven reads the user location if present, |
| 134 | +# otherwise the global. |
| 135 | +COPY maven-settings.xml /opt/maven/conf/settings.xml |
| 136 | + |
| 137 | +# 7. Install entrypoint script that fetches a CodeArtifact auth token at |
| 138 | +# container startup. No in-container refresh loop is needed because |
| 139 | +# AgentCore spawns a fresh container per session (<= 30min lifetime), |
| 140 | +# always within a single 12h token TTL. Future containers spawned hours |
| 141 | +# or days later will fetch their own fresh tokens at their own startup. |
| 142 | +COPY entrypoint.sh /app/entrypoint.sh |
| 143 | +RUN chmod +x /app/entrypoint.sh |
| 144 | + |
| 145 | +# 8. Create non-root user and set up their Maven config. |
| 146 | +# The symlink points the user-level settings at the global one so there's |
| 147 | +# only one file to maintain. |
| 148 | +RUN useradd -m -u 1000 bedrock_agentcore && \ |
| 149 | + mkdir -p /home/bedrock_agentcore/.m2 && \ |
| 150 | + ln -sf /opt/maven/conf/settings.xml /home/bedrock_agentcore/.m2/settings.xml && \ |
| 151 | + chown -R bedrock_agentcore:bedrock_agentcore /home/bedrock_agentcore |
| 152 | + |
| 153 | +USER bedrock_agentcore |
| 154 | + |
| 155 | +EXPOSE 9000 |
| 156 | +EXPOSE 8000 |
| 157 | +EXPOSE 8080 |
| 158 | + |
| 159 | + |
| 160 | +# Use the full module path |
| 161 | +# Entrypoint obtains the CodeArtifact auth token, starts a background |
| 162 | +# token-refresh loop, then execs the original agent command. |
| 163 | +CMD ["/app/entrypoint.sh"] |
0 commit comments