Skip to content

Commit 6659343

Browse files
committed
feat: add ECS task definition, Dockerfile, and GitHub Actions workflow for deployment
1 parent b3d2950 commit 6659343

6 files changed

Lines changed: 182 additions & 2 deletions

File tree

.aws/task-definition.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"family": "fiesta-api",
3+
"networkMode": "awsvpc",
4+
"requiresCompatibilities": ["FARGATE"],
5+
"cpu": "512",
6+
"memory": "1024",
7+
"executionRoleArn": "arn:aws:iam::752700849402:role/ecsTaskExecutionRole",
8+
"taskRoleArn": "arn:aws:iam::752700849402:role/ecsTaskRole",
9+
"containerDefinitions": [
10+
{
11+
"name": "fiesta-api",
12+
"image": "752700849402.dkr.ecr.us-west-2.amazonaws.com/earthref/fiesta-api:latest",
13+
"essential": true,
14+
"portMappings": [
15+
{
16+
"containerPort": 3000,
17+
"protocol": "tcp"
18+
}
19+
],
20+
"environment": [
21+
{
22+
"name": "NODE_ENV",
23+
"value": "production"
24+
}
25+
],
26+
"secrets": [
27+
{
28+
"name": "OS_NODE",
29+
"valueFrom": "arn:aws:secretsmanager:us-west-2:752700849402:secret:fiesta/OS_NODE"
30+
},
31+
{
32+
"name": "S3_ACCESS_KEY_ID",
33+
"valueFrom": "arn:aws:secretsmanager:us-west-2:752700849402:secret:fiesta/S3_ACCESS_KEY_ID"
34+
},
35+
{
36+
"name": "S3_SECRET_ACCESS_KEY",
37+
"valueFrom": "arn:aws:secretsmanager:us-west-2:752700849402:secret:fiesta/S3_SECRET_ACCESS_KEY"
38+
}
39+
],
40+
"logConfiguration": {
41+
"logDriver": "awslogs",
42+
"options": {
43+
"awslogs-group": "/ecs/fiesta-api",
44+
"awslogs-region": "us-west-2",
45+
"awslogs-stream-prefix": "ecs"
46+
}
47+
},
48+
"healthCheck": {
49+
"command": ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:3000/v1/health-check || exit 1"],
50+
"interval": 30,
51+
"timeout": 5,
52+
"retries": 3,
53+
"startPeriod": 60
54+
}
55+
}
56+
]
57+
}

.dockerignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
npm-debug.log
3+
dist
4+
.git
5+
.gitignore
6+
.env
7+
.env.local
8+
.env.*.local
9+
README.md
10+
.vscode
11+
.DS_Store
12+
downloads
13+
docs
14+
*.log
15+
coverage
16+
.nyc_output

.github/workflows/deploy-ecs.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Deploy to Amazon ECS
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
env:
10+
AWS_REGION: us-west-2 # Set your AWS region
11+
ECR_REPOSITORY: fiesta-api # Set your ECR repository name
12+
ECS_SERVICE: fiesta-api-service # Set your ECS service name
13+
ECS_CLUSTER: fiesta-api-cluster # Set your ECS cluster name
14+
ECS_TASK_DEFINITION: .aws/task-definition.json # Path to task definition
15+
CONTAINER_NAME: fiesta-api # Container name in task definition
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
deploy:
22+
name: Deploy
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v4
31+
with:
32+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
33+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
34+
aws-region: ${{ env.AWS_REGION }}
35+
36+
- name: Login to Amazon ECR
37+
id: login-ecr
38+
uses: aws-actions/amazon-ecr-login@v2
39+
40+
- name: Build, tag, and push image to Amazon ECR
41+
id: build-image
42+
env:
43+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
44+
IMAGE_TAG: ${{ github.sha }}
45+
run: |
46+
# Build a docker container and push it to ECR
47+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
48+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
49+
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest
50+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
51+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
52+
53+
- name: Fill in the new image ID in the Amazon ECS task definition
54+
id: task-def
55+
uses: aws-actions/amazon-ecs-render-task-definition@v1
56+
with:
57+
task-definition: ${{ env.ECS_TASK_DEFINITION }}
58+
container-name: ${{ env.CONTAINER_NAME }}
59+
image: ${{ steps.build-image.outputs.image }}
60+
61+
- name: Deploy Amazon ECS task definition
62+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
63+
with:
64+
task-definition: ${{ steps.task-def.outputs.task-definition }}
65+
service: ${{ env.ECS_SERVICE }}
66+
cluster: ${{ env.ECS_CLUSTER }}
67+
wait-for-service-stability: true

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Build stage
2+
FROM node:14-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Copy package files
7+
COPY package*.json ./
8+
9+
# Install all dependencies (including devDependencies for build)
10+
RUN npm ci
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Build the application
16+
RUN npm run build
17+
18+
# Production stage
19+
FROM node:14-alpine
20+
21+
WORKDIR /app
22+
23+
# Copy package files
24+
COPY package*.json ./
25+
26+
# Install only production dependencies
27+
RUN npm ci --production
28+
29+
# Copy built application from builder stage
30+
COPY --from=builder /app/dist ./dist
31+
COPY --from=builder /app/.platform ./.platform
32+
33+
# Expose the port the app runs on (adjust if different)
34+
EXPOSE 3000
35+
36+
# Set NODE_ENV to production
37+
ENV NODE_ENV=production
38+
39+
# Start the application
40+
CMD ["npm", "start"]

src/v1/libs/es.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const _ = deepdash(lodash);
1111
const indexes = { MagIC: 'magic' };
1212
const usersIndex = 'er_users';
1313
const client = new Client({
14-
node: process.env.ES_NODE,
14+
node: process.env.OS_NODE,
1515
});
1616

1717
function sleep(ms = 0) {

src/vNext/libs/es.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const _ = deepdash(lodash);
77

88
const usersIndex = 'er_users';
99
const client = new Client({
10-
node: process.env.ES_NODE,
10+
node: process.env.OS_NODE,
1111
});
1212

1313
function sleep(ms = 0) {

0 commit comments

Comments
 (0)