Docker Update Guide for AI Agents

Overview

This guide provides step-by-step instructions for AI agents to update the OASIS API Docker image and deploy it to AWS ECS. Follow these steps whenever code changes are made that require a new Docker build.


Quick Reference: Complete Update Process

# 1. Navigate to project root
cd /Volumes/Storage/OASIS_CLEAN

# 2. Build and push Docker image to AWS ECR
./docker/deploy.sh

# 3. Update ECS service to use new image
./docker/update-ecs.sh

That's it! The scripts handle everything automatically.


Detailed Process

Step 1: Build and Push Docker Image

Script: ./docker/deploy.sh

What it does:

  1. Authenticates with AWS ECR

  2. Checks/creates ECR repository if needed

  3. Builds Docker image from docker/Dockerfile

  4. Tags image with both latest and version tag (e.g., v20251220-003204)

  5. Pushes both tags to AWS ECR

  6. Outputs image digest for reference

Location: Run from project root (/Volumes/Storage/OASIS_CLEAN)

Expected Output:

Common Issues:

  • Docker not running: Start Docker Desktop

  • AWS credentials not configured: Run aws configure

  • Build fails: Check Docker logs, ensure all dependencies are present

  • No space on device: Run docker system prune -a to free space


Step 2: Update ECS Service

Script: ./docker/update-ecs.sh [optional-image-tag]

What it does:

  1. Retrieves current ECS task definition

  2. Updates task definition with new Docker image

  3. Registers new task definition revision

  4. Updates ECS service to use new task definition

  5. Waits for service to stabilize

Location: Run from project root (/Volumes/Storage/OASIS_CLEAN)

Usage:

Expected Output:

Service Details:

  • Cluster: oasis-api-cluster

  • Service: oasis-api-service

  • Task Family: oasis-api-task

  • Region: us-east-1


When to Update Docker

Update Docker whenever:

  1. Code changes are made to:

    • ONODE/NextGenSoftware.OASIS.API.ONODE.WebAPI/ (WebAPI project)

    • ONODE/NextGenSoftware.OASIS.API.ONODE.Core/ (Core project)

    • OASIS Architecture/ (Core OASIS libraries)

    • Providers/ (Provider implementations)

  2. Configuration changes in:

    • appsettings.json or appsettings.Production.json

    • OASIS_DNA.json (if included in image)

    • Dockerfile itself

  3. Dependency updates:

    • NuGet package updates

    • External library changes

    • .NET SDK/runtime updates

  4. New features requiring:

    • New endpoints

    • New services

    • New dependencies


Docker Configuration

Dockerfile Location

  • Path: docker/Dockerfile

  • Build Context: Project root (/Volumes/Storage/OASIS_CLEAN)

Key Configuration

Base Images:

  • Runtime: mcr.microsoft.com/dotnet/aspnet:9.0

  • Build: mcr.microsoft.com/dotnet/sdk:9.0

Ports:

  • Container: 80 (HTTP)

  • Health Check: http://localhost:80/swagger/index.html

Environment Variables:

  • ASPNETCORE_ENVIRONMENT=Production

  • ASPNETCORE_URLS=http://+:80

Build Process:

  1. Copy external libraries (External Libs/, external-libs/, NextGenSoftware-Libraries/)

  2. Copy project files (.csproj files)

  3. Copy source code

  4. Restore NuGet packages

  5. Build solution

  6. Publish WebAPI project

  7. Copy published files to runtime image


AWS Configuration

ECR Repository

  • URI: 881490134703.dkr.ecr.us-east-1.amazonaws.com/oasis-api

  • Region: us-east-1

  • Account ID: 881490134703

ECS Configuration

  • Cluster: oasis-api-cluster

  • Service: oasis-api-service

  • Task Definition: oasis-api-task

  • Load Balancer: oasis-api-alb-2011847064.us-east-1.elb.amazonaws.com

  • Target Group: oasis-api-tg-v5

Domain

  • API Domain: api.oasisweb4.com

  • Points to ALB β†’ ECS service


Testing After Update

1. Check ECS Service Status

Expected: RunningCount should equal DesiredCount (typically 1)

2. Check Running Task

Expected: LastStatus should be RUNNING, Image should match the new image

3. Test API Endpoint


Troubleshooting

Build Fails

Issue: Docker build fails with compilation errors

Solution:

  1. Check build logs for specific errors

  2. Ensure all project references are correct

  3. Verify .csproj files don't reference excluded projects

  4. Check that all required files are in build context

Common Build Errors:

  • Missing project references β†’ Check .csproj files

  • STARNET dependencies β†’ Already excluded, should not appear

  • Missing external libraries β†’ Ensure External Libs/ and external-libs/ are copied

Push Fails

Issue: docker push fails with authentication error

Solution:

ECS Service Won't Update

Issue: Service update fails or doesn't start new tasks

Solution:

  1. Check task definition for errors:

  2. Check service events:

  3. Check task logs:

API Not Responding

Issue: After update, API returns errors or doesn't respond

Solution:

  1. Check if service is running:

  2. Check task logs for errors:

  3. Verify image was built correctly:

  4. Rollback to previous version if needed:


Local Testing Before Deployment

Build Locally

Run Locally

Test Script

Use the provided test script:


Build Optimization

Docker Build Cache

Docker uses layer caching. To force a clean build:

Build Context Size

The build context includes the entire project. To reduce size:

  1. Check .dockerignore excludes unnecessary files

  2. Ensure bin/, obj/, .git/ are excluded

  3. Large directories like holochain-client-csharp/ should be excluded

Build Time

Typical build times:

  • First build: 20-30 minutes (downloads all dependencies)

  • Incremental build: 5-15 minutes (uses cache)

  • Clean build: 20-30 minutes

To speed up:

  • Use Docker BuildKit: DOCKER_BUILDKIT=1 docker build ...

  • Use build cache mount (if supported)


Rollback Procedure

If a deployment causes issues:

1. Identify Previous Working Version

2. Get Previous Task Definition

3. Rollback Service


Important Files

Scripts

  • docker/deploy.sh - Build and push to ECR

  • docker/update-ecs.sh - Update ECS service

  • docker/test-local.sh - Test Docker image locally

  • docker/build.sh - Build locally only

Configuration

  • docker/Dockerfile - Docker build instructions

  • .dockerignore - Files to exclude from build

  • docker/docker-compose.yml - Local development setup

Documentation

  • docker/README.md - General Docker documentation

  • docker/AGENT_DOCKER_UPDATE_GUIDE.md - This file (for AI agents)

  • DOCKER_DEPLOYMENT_GUIDE.md - General deployment guide


Checklist for AI Agents

Before updating Docker:

During update:

After update:


Summary

To update Docker:

  1. ./docker/deploy.sh - Builds and pushes image

  2. ./docker/update-ecs.sh - Updates ECS service

Total time: ~25-35 minutes (build) + ~2-5 minutes (deploy)

Verification: Test http://api.oasisweb4.com/api/avatar/health

The scripts handle all the complexity automatically. Just run them in order from the project root.

Last updated