Skip to content

Commit d4c0603

Browse files
committed
Add ECS wake/sleep infra with detailed comments
1 parent fcabf5f commit d4c0603

7 files changed

Lines changed: 456 additions & 184 deletions

File tree

.gitignore

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# macOS
2-
.DS_Store
3-
41
# Terraform
5-
**/.terraform/
6-
**/terraform.tfstate
7-
**/terraform.tfstate.*
2+
*.tfstate
3+
*.tfstate.*
4+
.terraform/
5+
.terraform.lock.hcl
6+
7+
# Lambda zips
8+
infra/wake.zip
9+
infra/sleep.zip
810

911
# Node
10-
app/node_modules
11-
app/npm-debug.log*
12-
# Zip
13-
wake.zip
12+
node_modules/
13+
npm-debug.log
14+
15+
# Python
16+
__pycache__/
17+
*.pyc

app/Dockerfile

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
# app/Dockerfile
1+
# Use a small official Node.js 20 image from AWS Public ECR (Alpine-based for minimal size)
22
FROM public.ecr.aws/docker/library/node:20-alpine
33

4+
# Set working directory inside the container
45
WORKDIR /app
56

6-
# Copy only manifests first to leverage layer cache
7+
# Copy only dependency manifests first (package.json, package-lock.json)
8+
# This allows Docker to cache dependency installation layers
9+
# unless package files have changed (faster builds).
710
COPY package*.json ./
811

9-
# Install production dependencies
12+
# Install production dependencies only
13+
# "npm ci" ensures clean, reproducible installs
14+
# "--omit=dev" excludes devDependencies → smaller image, faster runtime
1015
RUN npm ci --omit=dev
1116

12-
# Copy source
17+
# Copy the application source code
18+
# Here we assume all source is inside "src/" directory
1319
COPY src ./src
1420

21+
# Set environment variables for production
1522
ENV NODE_ENV=production
1623
ENV PORT=80
1724

18-
# Lightweight healthcheck (no curl/wget needed)
19-
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
25+
# Define container health check
26+
# - Interval: every 30s
27+
# - Timeout: fail after 3s
28+
# - Start period: allow 10s before first check
29+
# - Command: Run a Node one-liner that makes HTTP request to /health endpoint
30+
# → exits 0 if OK, exits 1 if failure
31+
# Using Node's fetch avoids installing curl or wget, keeping the image slim.
32+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
33+
CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
2034

35+
# Expose application port (for ECS, Kubernetes, etc.)
2136
EXPOSE 80
22-
CMD ["npm", "start"]
37+
38+
# Default container startup command → "npm start" defined in package.json
39+
CMD ["npm", "start"]

0 commit comments

Comments
 (0)