Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
467 changes: 467 additions & 0 deletions CURL_COMMANDS.md

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions build-and-push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Build and push Docker images to ECR
# Run this script from the project root directory

$ErrorActionPreference = "Stop"

$AWS_REGION = "us-west-2"
$AWS_ACCOUNT_ID = "892825672262"
$ECR_REGISTRY = "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"

Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "Building and Pushing Docker Images to ECR" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan

# Login to ECR
Write-Host ""
Write-Host "Step 1: Logging in to ECR..." -ForegroundColor Yellow
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to login to ECR" -ForegroundColor Red
exit 1
}

# Build and push social-graph-service
Write-Host ""
Write-Host "Step 2: Building social-graph-service..." -ForegroundColor Yellow
Set-Location services/social-graph-services
docker build -t social-graph-service:latest .
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build social-graph-service" -ForegroundColor Red
exit 1
}
docker tag social-graph-service:latest "$ECR_REGISTRY/social-graph-service:latest"
Write-Host "Pushing social-graph-service to ECR..." -ForegroundColor Yellow
docker push "$ECR_REGISTRY/social-graph-service:latest"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to push social-graph-service" -ForegroundColor Red
exit 1
}
Set-Location ../..

# Build and push user-service
Write-Host ""
Write-Host "Step 3: Building user-service..." -ForegroundColor Yellow
Set-Location services/user-service
docker build -t user-service:latest .
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build user-service" -ForegroundColor Red
exit 1
}
docker tag user-service:latest "$ECR_REGISTRY/user-service:latest"
Write-Host "Pushing user-service to ECR..." -ForegroundColor Yellow
docker push "$ECR_REGISTRY/user-service:latest"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to push user-service" -ForegroundColor Red
exit 1
}
Set-Location ../..

# Build and push web-service
Write-Host ""
Write-Host "Step 4: Building web-service..." -ForegroundColor Yellow
Set-Location web-service
docker build -t web-service:latest .
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to build web-service" -ForegroundColor Red
exit 1
}
docker tag web-service:latest "$ECR_REGISTRY/web-service:latest"
Write-Host "Pushing web-service to ECR..." -ForegroundColor Yellow
docker push "$ECR_REGISTRY/web-service:latest"
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to push web-service" -ForegroundColor Red
exit 1
}
Set-Location ..

Write-Host ""
Write-Host "=========================================" -ForegroundColor Green
Write-Host "✅ All images built and pushed successfully!" -ForegroundColor Green
Write-Host "=========================================" -ForegroundColor Green
Write-Host ""
Write-Host "ECR Repository URLs:" -ForegroundColor Cyan
Write-Host " - social-graph-service: $ECR_REGISTRY/social-graph-service:latest" -ForegroundColor White
Write-Host " - user-service: $ECR_REGISTRY/user-service:latest" -ForegroundColor White
Write-Host " - web-service: $ECR_REGISTRY/web-service:latest" -ForegroundColor White
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "1. Update ECS services to use the new images" -ForegroundColor White
Write-Host "2. Run: cd terraform; .\update-ecs-services.ps1" -ForegroundColor White
101 changes: 101 additions & 0 deletions deploy-social-graph.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Build and deploy social-graph-service Docker image to ECR

$ErrorActionPreference = "Stop"

# Configuration
$AWS_REGION = "us-west-2"
$AWS_ACCOUNT_ID = "892825672262"
$ECR_REPOSITORY = "social-graph-service"
$SERVICE_DIR = "services\social-graph-services"
$IMAGE_TAG = "latest"

Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "Building and Deploying Social Graph Service" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""

# Step 1: Login to ECR
Write-Host "1. Logging in to ECR..." -ForegroundColor Yellow
try {
$loginPassword = aws ecr get-login-password --region $AWS_REGION
$loginPassword | docker login --username AWS --password-stdin "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com" 2>&1 | Out-Null
Write-Host " ✓ ECR login successful" -ForegroundColor Green
} catch {
Write-Host " ✗ ECR login failed: $_" -ForegroundColor Red
exit 1
}

Write-Host ""

# Step 2: Build Docker image (from project root, using Dockerfile in service dir)
Write-Host "2. Building Docker image from project root..." -ForegroundColor Yellow

try {
# Build from root directory, but use Dockerfile from service directory
docker build -f "$SERVICE_DIR\Dockerfile" -t "${ECR_REPOSITORY}:${IMAGE_TAG}" .
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Docker image built successfully" -ForegroundColor Green
} else {
throw "Docker build failed with exit code $LASTEXITCODE"
}
} catch {
Write-Host " ✗ Docker build failed: $_" -ForegroundColor Red
exit 1
}

Write-Host ""

# Step 3: Tag image for ECR
Write-Host "3. Tagging image for ECR..." -ForegroundColor Yellow
docker tag "${ECR_REPOSITORY}:${IMAGE_TAG}" "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}"
Write-Host " ✓ Image tagged" -ForegroundColor Green
Write-Host ""

# Step 4: Push to ECR
Write-Host "4. Pushing image to ECR..." -ForegroundColor Yellow
try {
docker push "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}"
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Image pushed successfully" -ForegroundColor Green
} else {
throw "Docker push failed with exit code $LASTEXITCODE"
}
} catch {
Write-Host " ✗ Image push failed: $_" -ForegroundColor Red
exit 1
}
Write-Host ""

# Step 5: Force new deployment
Write-Host "5. Forcing ECS service update..." -ForegroundColor Yellow
try {
aws ecs update-service `
--cluster social-graph-service `
--service social-graph-service `
--force-new-deployment `
--region $AWS_REGION `
--query 'service.{ServiceName:serviceName,Status:status,DesiredCount:desiredCount}' `
--output table

Write-Host " ✓ Service update triggered" -ForegroundColor Green
} catch {
Write-Host " ✗ Service update failed: $_" -ForegroundColor Red
exit 1
}

Write-Host ""
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host "Deployment Complete!" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Next steps:" -ForegroundColor White
Write-Host "1. Wait 2-3 minutes for tasks to start" -ForegroundColor Gray
Write-Host "2. Check service status:" -ForegroundColor Gray
Write-Host " aws ecs describe-services --cluster social-graph-service --services social-graph-service --region us-west-2" -ForegroundColor DarkGray
Write-Host ""
Write-Host "3. View logs:" -ForegroundColor Gray
Write-Host " aws logs tail /ecs/social-graph-service --follow --region us-west-2" -ForegroundColor DarkGray
Write-Host ""
Write-Host "4. Test the service:" -ForegroundColor Gray
Write-Host " Invoke-WebRequest -Uri 'http://cs6650-project-dev-alb-2003105151.us-west-2.elb.amazonaws.com/api/health'" -ForegroundColor DarkGray
Write-Host ""
99 changes: 99 additions & 0 deletions deploy-social-graph.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
# Build and deploy social-graph-service Docker image to ECR

set -e

# Configuration
AWS_REGION="us-west-2"
AWS_ACCOUNT_ID="892825672262"
ECR_REPOSITORY="social-graph-service"
SERVICE_DIR="services/social-graph-services"
IMAGE_TAG="latest"

echo "========================================="
echo "Building and Deploying Social Graph Service"
echo "========================================="
echo ""

# Step 1: Login to ECR
echo "1. Logging in to ECR..."
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com

if [ $? -eq 0 ]; then
echo "✓ ECR login successful"
else
echo "✗ ECR login failed"
exit 1
fi

echo ""

# Step 2: Build Docker image
echo "2. Building Docker image..."
cd $SERVICE_DIR

docker build -t ${ECR_REPOSITORY}:${IMAGE_TAG} .

if [ $? -eq 0 ]; then
echo "✓ Docker image built successfully"
else
echo "✗ Docker build failed"
exit 1
fi

echo ""

# Step 3: Tag image for ECR
echo "3. Tagging image for ECR..."
docker tag ${ECR_REPOSITORY}:${IMAGE_TAG} ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}

echo "✓ Image tagged"
echo ""

# Step 4: Push to ECR
echo "4. Pushing image to ECR..."
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}

if [ $? -eq 0 ]; then
echo "✓ Image pushed successfully"
else
echo "✗ Image push failed"
exit 1
fi

echo ""

# Step 5: Force new deployment
echo "5. Forcing ECS service update..."
cd ../..
aws ecs update-service \
--cluster social-graph-service \
--service social-graph-service \
--force-new-deployment \
--region $AWS_REGION \
--query 'service.{ServiceName:serviceName,Status:status,DesiredCount:desiredCount}' \
--output table

if [ $? -eq 0 ]; then
echo "✓ Service update triggered"
else
echo "✗ Service update failed"
exit 1
fi

echo ""
echo "========================================="
echo "Deployment Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo "1. Wait 2-3 minutes for tasks to start"
echo "2. Check service status:"
echo " aws ecs describe-services --cluster social-graph-service --services social-graph-service --region us-west-2"
echo ""
echo "3. View logs:"
echo " aws logs tail /ecs/social-graph-service --follow --region us-west-2"
echo ""
echo "4. Test the service:"
echo " curl http://cs6650-project-dev-alb-1139764678.us-west-2.elb.amazonaws.com/api/health"
echo ""
Loading