Repository navigation
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·82 lines (70 loc) · 3.48 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·82 lines (70 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# deploy.sh — full stack deploy for Service Mailroom
#
# Deploys:
# 1. Backend — Docker image → ECR → Lambda (arm64)
# 2. Frontend — Vite build → S3 → CloudFront invalidation
#
# Prerequisites: docker, aws CLI, node/npm
# Usage: ./deploy.sh
set -euo pipefail
AWS_PROFILE="nalam"
AWS_REGION="eu-central-1"
ECR_REPO="533220667107.dkr.ecr.eu-central-1.amazonaws.com/mailroom-api"
LAMBDA_FUNCTION="mailroom-api"
S3_BUCKET="mailroom-frontend-533220667107"
CF_DISTRIBUTION="E2QVTU5ZB5FWPT"
# ── 1. ECR login ────────────────────────────────────────────────────────────
echo "==> Logging in to ECR..."
aws ecr get-login-password --region "$AWS_REGION" --profile "$AWS_PROFILE" \
| docker login --username AWS --password-stdin \
"533220667107.dkr.ecr.$AWS_REGION.amazonaws.com"
# ── 2. Build backend image ───────────────────────────────────────────────────
# --platform linux/arm64 : Lambda uses Graviton (arm64)
# --provenance=false : avoids OCI manifest format that Lambda rejects
echo "==> Building backend Docker image..."
docker build \
--platform linux/arm64 \
--provenance=false \
-f Dockerfile.lambda \
-t mailroom-api:latest .
# ── 3. Push to ECR ───────────────────────────────────────────────────────────
echo "==> Pushing image to ECR..."
docker tag mailroom-api:latest "$ECR_REPO:latest"
docker push "$ECR_REPO:latest"
# ── 4. Update Lambda ─────────────────────────────────────────────────────────
echo "==> Updating Lambda function..."
aws lambda update-function-code \
--function-name "$LAMBDA_FUNCTION" \
--image-uri "$ECR_REPO:latest" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE" \
--output text --query "LastUpdateStatus"
echo "==> Waiting for Lambda update to complete..."
aws lambda wait function-updated \
--function-name "$LAMBDA_FUNCTION" \
--region "$AWS_REGION" \
--profile "$AWS_PROFILE"
echo " Backend live."
# ── 5. Build frontend ────────────────────────────────────────────────────────
echo "==> Building frontend..."
cd frontend
npm run build
cd ..
# ── 6. Sync to S3 ────────────────────────────────────────────────────────────
echo "==> Syncing frontend to S3..."
aws s3 sync frontend/dist "s3://$S3_BUCKET" \
--delete \
--exclude "assets/logo.*" \
--profile "$AWS_PROFILE"
# ── 7. Invalidate CloudFront ─────────────────────────────────────────────────
echo "==> Invalidating CloudFront cache..."
aws cloudfront create-invalidation \
--distribution-id "$CF_DISTRIBUTION" \
--paths "/*" \
--profile "$AWS_PROFILE" \
--output text --query "Invalidation.Status"
echo ""
echo "==> Deploy complete."
echo " Backend: https://mailroom-api.nalam.chat"
echo " Frontend: https://d38fvtuswo6t52.cloudfront.net"