Skip to content

Commit ba9163c

Browse files
author
nx-plugin-for-aws
committed
fix(ts#strands-agent,py#strands-agent): fix Dockerfile whitespace and A2A port config
- Use <%_ _%> EJS trim tags in Dockerfiles to avoid extra blank lines - Python A2A main.py reads PORT from env var (default 9000) so serve/serve-local targets can set the assigned port - Python serve targets always set PORT env var for consistency
1 parent 4a13fe3 commit ba9163c

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

packages/nx-plugin/src/py/strands-agent/__snapshots__/generator.spec.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ WORKDIR /app
88
# Copy bundled package
99
COPY --from=workspace dist/apps/test-project/bundle-arm /app
1010
11-
1211
EXPOSE 8080
1312
14-
1513
ENV PYTHONPATH=/app
1614
1715
# Auto-instrument with AWS Distro for OpenTelemetry
1816
# https://aws-otel.github.io/docs/getting-started/python-sdk/auto-instr
19-
2017
CMD ["python", "bin/opentelemetry-instrument", "python", "-m", "proj_test_project.snapshot_bedrock_agent.main"]
21-
2218
"
2319
`;
2420

packages/nx-plugin/src/py/strands-agent/files/a2a/main.py.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import logging
2+
import os
23

3-
from .agent import get_agent
44
from strands.multiagent.a2a import A2AServer
55

6+
from .agent import get_agent
7+
68
logging.basicConfig(level=logging.INFO)
79

10+
PORT = int(os.environ.get("PORT", "9000"))
11+
812
# Create A2A server (streaming enabled by default)
913
_agent_ctx = get_agent(session_id="default")
1014
_agent = _agent_ctx.__enter__()
@@ -13,7 +17,7 @@ a2a_server = A2AServer(
1317
agent=_agent,
1418
name="<%= agentNameClassName %>",
1519
description="A Strands Agent exposed via the Agent-to-Agent (A2A) protocol.",
16-
port=9000,
20+
port=PORT,
1721
)
1822

1923
# Expose as a FastAPI app so that `fastapi dev` can serve it with hot reloading

packages/nx-plugin/src/py/strands-agent/files/deploy/Dockerfile.template

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ WORKDIR /app
55
# Copy bundled package
66
COPY --from=workspace <%- bundleOutputDir %> /app
77

8-
<% if (protocol === 'A2A') { %>
8+
<%_ if (protocol === 'A2A') { _%>
99
EXPOSE 9000
10-
<% } else { %>
10+
<%_ } else { _%>
1111
EXPOSE 8080
12-
<% } %>
12+
<%_ } _%>
1313

1414
ENV PYTHONPATH=/app
1515

1616
# Auto-instrument with AWS Distro for OpenTelemetry
1717
# https://aws-otel.github.io/docs/getting-started/python-sdk/auto-instr
18-
<% if (protocol === 'A2A') { %>
18+
<%_ if (protocol === 'A2A') { _%>
1919
CMD ["python", "bin/opentelemetry-instrument", "uvicorn", "<%- moduleName %>.<%- agentNameSnakeCase %>.main:app", "--host", "0.0.0.0", "--port", "9000"]
20-
<% } else { %>
20+
<%_ } else { _%>
2121
CMD ["python", "bin/opentelemetry-instrument", "python", "-m", "<%- moduleName %>.<%- agentNameSnakeCase %>.main"]
22-
<% } %>
22+
<%_ } _%>

packages/nx-plugin/src/py/strands-agent/generator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ export const pyStrandsAgentGenerator = async (
198198
options: {
199199
commands: [serveCommand],
200200
cwd: '{projectRoot}',
201+
env: {
202+
PORT: `${localDevPort}`,
203+
},
201204
},
202205
continuous: true,
203206
},
@@ -207,6 +210,7 @@ export const pyStrandsAgentGenerator = async (
207210
commands: [serveCommand],
208211
cwd: '{projectRoot}',
209212
env: {
213+
PORT: `${localDevPort}`,
210214
SERVE_LOCAL: 'true',
211215
},
212216
},

packages/nx-plugin/src/ts/strands-agent/__snapshots__/generator.spec.ts.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ RUN npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@0.9.0
1212
# Copy bundled agent
1313
COPY --from=workspace dist/apps/test-project/bundle/agent/snapshot-bedrock-agent/index.js /app
1414
15-
1615
EXPOSE 8080
1716
18-
1917
# Auto-instrument with AWS Distro for OpenTelemetry
2018
# https://aws-otel.github.io/docs/getting-started/js-sdk/trace-metric-auto-instr
2119
CMD [ "node", "--require", "@aws/aws-distro-opentelemetry-node-autoinstrumentation/register", "index.js" ]

packages/nx-plugin/src/ts/strands-agent/files/deploy/Dockerfile.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ RUN npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@<%- adotV
99
# Copy bundled agent
1010
COPY --from=workspace <%- distDir %>/bundle/agent/<%- name %>/index.js /app
1111

12-
<% if (protocol === 'A2A') { %>
12+
<%_ if (protocol === 'A2A') { _%>
1313
EXPOSE 9000
14-
<% } else { %>
14+
<%_ } else { _%>
1515
EXPOSE 8080
16-
<% } %>
16+
<%_ } _%>
1717

1818
# Auto-instrument with AWS Distro for OpenTelemetry
1919
# https://aws-otel.github.io/docs/getting-started/js-sdk/trace-metric-auto-instr

0 commit comments

Comments
 (0)