Skip to content

Commit 3f00666

Browse files
committed
re sync 2
1 parent e06260d commit 3f00666

File tree

3 files changed

+73
-46
lines changed

3 files changed

+73
-46
lines changed

Dockerfile

+23-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Use a specific Node.js version for better reproducibility
1+
# Use Node.js 23.3.0 as specified in package.json
22
FROM node:23.3.0-slim AS builder
33

44
# Install pnpm globally and install necessary build tools
@@ -14,19 +14,19 @@ RUN ln -s /usr/bin/python3 /usr/bin/python
1414
# Set the working directory
1515
WORKDIR /app
1616

17-
# Copy package.json and other configuration files
17+
# Copy package files first for better caching
1818
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc turbo.json ./
1919

20+
# Install dependencies and build the project
21+
RUN pnpm install
22+
2023
# Copy the rest of the application code
2124
COPY agent ./agent
2225
COPY packages ./packages
2326
COPY scripts ./scripts
24-
# Don't copy characters folder as we'll get it from GCS
2527

26-
# Install dependencies and build the project
27-
RUN pnpm install --frozen-lockfile \
28-
&& pnpm build-docker \
29-
&& pnpm prune --prod
28+
# Build the project
29+
RUN pnpm build-docker && pnpm prune --prod
3030

3131
# Create a new stage for the final image
3232
FROM node:23.3.0-slim
@@ -57,12 +57,19 @@ COPY --from=builder /app/scripts ./scripts
5757
# Create characters directory
5858
RUN mkdir -p characters
5959

60-
# Set default environment variables
61-
ENV PORT=8080
62-
ENV SERVER_PORT=8080
63-
64-
# Expose the port
65-
EXPOSE 8080
66-
67-
# Modified command to fetch character file from GCS before starting
68-
CMD sh -c "gsutil cp gs://${AGENTS_BUCKET_NAME}/${CHARACTER_FILE} characters/${CHARACTER_FILE} && pnpm start --non-interactive --characters=characters/$CHARACTER_FI${CHARACTER_FILE}"
60+
# Add debugging and error handling to startup command
61+
CMD sh -c '\
62+
echo "Debug: Starting container" && \
63+
echo "Debug: AGENTS_BUCKET_NAME=${AGENTS_BUCKET_NAME}" && \
64+
echo "Debug: CHARACTER_FILE=${CHARACTER_FILE}" && \
65+
echo "Debug: Full GCS path=gs://${AGENTS_BUCKET_NAME}/${CHARACTER_FILE}" && \
66+
if [ -z "${AGENTS_BUCKET_NAME}" ]; then \
67+
echo "Error: AGENTS_BUCKET_NAME is empty" && exit 1; \
68+
fi && \
69+
if [ -z "${CHARACTER_FILE}" ]; then \
70+
echo "Error: CHARACTER_FILE is empty" && exit 1; \
71+
fi && \
72+
echo "Debug: Attempting to copy character file..." && \
73+
gsutil cp gs://${AGENTS_BUCKET_NAME}/${CHARACTER_FILE} characters/${CHARACTER_FILE} && \
74+
echo "Debug: Starting application..." && \
75+
pnpm start --non-interactive --characters=characters/${CHARACTER_FILE}'

cloudbuild.yaml

+16-6
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,29 @@ steps:
2626
ls -la
2727
pwd
2828
29-
# Verify secrets access
29+
# Verify secrets and bucket access
3030
- name: 'gcr.io/cloud-builders/gcloud'
3131
entrypoint: 'bash'
3232
args:
3333
- '-c'
3434
- |
3535
echo "Verifying secrets access..."
36-
echo "Testing secret access..."
37-
if ! gcloud secrets versions access latest --secret="small-google-model"; then
38-
echo "Failed to access secrets"
36+
echo "Testing secrets..."
37+
if ! gcloud secrets versions access latest --secret="small-google-model" > /dev/null; then
38+
echo "Failed to access small-google-model secret"
3939
exit 1
4040
fi
41-
echo "Secret access verified"
41+
if ! gcloud secrets versions access latest --secret="agents-bucket-name" > /dev/null; then
42+
echo "Failed to access agents-bucket-name secret"
43+
exit 1
44+
fi
45+
echo "Verifying bucket access..."
46+
bucket_name=$(gcloud secrets versions access latest --secret="agents-bucket-name")
47+
if ! gsutil ls gs://${bucket_name} > /dev/null; then
48+
echo "Failed to access bucket"
49+
exit 1
50+
fi
51+
echo "Secret and bucket access verified"
4252
4353
# Build the container image
4454
- name: 'gcr.io/cloud-builders/docker'
@@ -104,7 +114,7 @@ substitutions:
104114
_DISK_SIZE: 30GB
105115
_NETWORK: agents-vpc
106116
_SUBNET: agents-subnet
107-
_CHARACTER_FILE: defalt.character.json
117+
_CHARACTER_FILE: default.character.json
108118
_SUFFIX: agent
109119

110120
options:

startup.sh

+34-24
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,59 @@ echo "Verifying directory structure..."
5959
ls -la "$AGENT_DATA_DIR"
6060
ls -la "$AGENT_DATA_DIR/data"
6161

62-
# Pull latest image with verification
63-
echo "Pulling latest image..."
64-
docker pull us-central1-docker.pkg.dev/${PROJECT_ID}/${FULL_NAME}:${version} 2>&1 | tee /tmp/docker-pull.log || {
65-
echo "Failed to pull image, logs:"
66-
cat /tmp/docker-pull.log
62+
# Get secrets from Secret Manager with error checking
63+
echo "Fetching secrets..."
64+
AGENTS_BUCKET_NAME=$(gcloud secrets versions access latest --secret="agents-bucket-name") || {
65+
echo "Failed to fetch agents-bucket-name secret"
66+
exit 1
67+
}
68+
SMALL_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="small-google-model") || {
69+
echo "Failed to fetch small-google-model secret"
70+
exit 1
71+
}
72+
MEDIUM_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="medium-google-model") || {
73+
echo "Failed to fetch medium-google-model secret"
74+
exit 1
75+
}
76+
GOOGLE_GENERATIVE_AI_API_KEY=$(gcloud secrets versions access latest --secret="google-generative-ai-key") || {
77+
echo "Failed to fetch google-generative-ai-key secret"
6778
exit 1
6879
}
6980

70-
# Get secrets from Secret Manager
71-
echo "Fetching secrets..."
72-
AGENTS_BUCKET_NAME=$(gcloud secrets versions access latest --secret="agents-bucket-name")
73-
SMALL_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="small-google-model")
74-
MEDIUM_GOOGLE_MODEL=$(gcloud secrets versions access latest --secret="medium-google-model")
75-
GOOGLE_GENERATIVE_AI_API_KEY=$(gcloud secrets versions access latest --secret="google-generative-ai-key")
81+
# Debug environment variables
82+
echo "Debug: Environment variables:"
83+
echo "AGENTS_BUCKET_NAME: ${AGENTS_BUCKET_NAME:-not set}"
84+
echo "CHARACTER_FILE: ${CHARACTER_FILE:-not set}"
85+
echo "SMALL_GOOGLE_MODEL: ${SMALL_GOOGLE_MODEL:0:5}... (truncated)"
86+
echo "MEDIUM_GOOGLE_MODEL: ${MEDIUM_GOOGLE_MODEL:0:5}... (truncated)"
87+
echo "GOOGLE_GENERATIVE_AI_API_KEY: ${GOOGLE_GENERATIVE_AI_API_KEY:0:5}... (truncated)"
7688

7789
# Run container with persistent storage and restart policy
7890
echo "Starting container..."
7991
docker run -d \
8092
--name ${FULL_NAME} \
8193
--restart=always \
8294
-v "$AGENT_DATA_DIR/data":/app/agent/data \
83-
-e AGENTS_BUCKET_NAME="${AGENTS_BUCKET_NAME}" \
84-
-e CHARACTER_FILE="${CHARACTER_FILE}" \
85-
-e SMALL_GOOGLE_MODEL="${SMALL_GOOGLE_MODEL}" \
86-
-e MEDIUM_GOOGLE_MODEL="${MEDIUM_GOOGLE_MODEL}" \
87-
-e GOOGLE_GENERATIVE_AI_API_KEY="${GOOGLE_GENERATIVE_AI_API_KEY}" \
95+
-e AGENTS_BUCKET_NAME="${AGENTS_BUCKET_NAME:?'AGENTS_BUCKET_NAME not set'}" \
96+
-e CHARACTER_FILE="${CHARACTER_FILE:?'CHARACTER_FILE not set'}" \
97+
-e SMALL_GOOGLE_MODEL="${SMALL_GOOGLE_MODEL:?'SMALL_GOOGLE_MODEL not set'}" \
98+
-e MEDIUM_GOOGLE_MODEL="${MEDIUM_GOOGLE_MODEL:?'MEDIUM_GOOGLE_MODEL not set'}" \
99+
-e GOOGLE_GENERATIVE_AI_API_KEY="${GOOGLE_GENERATIVE_AI_API_KEY:?'GOOGLE_GENERATIVE_AI_API_KEY not set'}" \
88100
-e PORT="8080" \
89101
-e SERVER_PORT="8080" \
90102
us-central1-docker.pkg.dev/${PROJECT_ID}/${FULL_NAME}:${version}
91103

92-
# Verify container is running
93-
echo "Container started. Checking status..."
104+
# Verify container is running and check logs
105+
echo "Checking container status and logs..."
106+
sleep 5 # Give container a moment to start
94107
if ! docker ps | grep ${FULL_NAME}; then
95108
echo "Container failed to start. Checking logs:"
96109
docker logs ${FULL_NAME}
97110
exit 1
98111
fi
99112

100-
# Final verification
101-
echo "Verifying final state..."
102-
df -h
103-
mount
104-
docker ps
105-
ls -la "$AGENT_DATA_DIR"
113+
# Show container logs
114+
echo "Initial container logs:"
115+
docker logs ${FULL_NAME}
106116

107117
echo "Startup script completed successfully"

0 commit comments

Comments
 (0)