Your production application runs on AWS and its resources are defined in the workspace/prd_resources.py file. This guide shows how to:

  1. Build a production image
  2. Update ECS Task Definitions
  3. Update ECS Services

Workspace Settings

The WorkspaceSettings object in the workspace/settings.py file defines common settings used by your workspace apps and resources.

Build your production image

Your application uses the phidata images by default. To use your own image:

  • Open workspace/settings.py file
  • Update the image_repo to your image repository
  • Set build_images=True and push_images=True
workspace/settings.py
ws_settings = WorkspaceSettings(
    ...
    # Subnet IDs in the aws_region
    subnet_ids=["subnet-xyz", "subnet-xyz"],
    # -*- Image Settings
    # Repository for images
    image_repo="your-image-repo",
    # Build images locally
    build_images=True,
    # Push images after building
    push_images=True,
)

Build a new image

Build the production image using:

phi ws up --env prd --infra docker --type image

To force rebuild images, use the --force or -f flag

phi ws up --env prd --infra docker --type image --force

Because the only docker resources in the production env are docker images, you can also use:

phi ws up prd:docker

Use ECR for images

To use ECR, create the image repo and authenticate with ECR before pushing images.

1. Create the image repository in ECR

The repo name should match the ws_name. Meaning if you’re using the default workspace name, the repo name would be ai.

create-ecr-image

2. Authenticate with ECR

Authenticate with ECR
aws ecr get-login-password --region [region] | docker login --username AWS --password-stdin [account].dkr.ecr.[region].amazonaws.com

You can also use a helper script to avoid running the full command

Update the script with your ECR repo before running.

./scripts/auth_ecr.sh

ECS Task Definition

If you updated the Image, CPU, Memory or Environment Variables, update the Task Definition using:

phi ws patch --env prd --infra aws --name td

ECS Service

To redeploy the production application, update the ECS Service using:

phi ws patch --env prd --infra aws --name service

If you ONLY rebuilt the image, you do not need to update the task definition and can just patch the service to pickup the new image.