Skip to content

Commit 6f460e3

Browse files
Ecs code mounting (#7)
* initial setup * get it working * remove useless files * Fix remote debugger configuration and instructions * Review README file --------- Co-authored-by: HarshCasper <[email protected]> Co-authored-by: Bart Szydlowski <[email protected]>
1 parent 4bef755 commit 6f460e3

File tree

12 files changed

+990
-2779
lines changed

12 files changed

+990
-2779
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ start-localstack:
4646
cd devops-tooling && docker compose -p $(APP_NAME) up
4747

4848
stop-localstack:
49-
cd devops-tooling && docker compose down
49+
cd devops-tooling && docker compose -p $(APP_NAME) down
5050

5151

5252
PKG_SUB_DIRS := $(dir $(shell find . -type d -name node_modules -prune -o -type d -name "venv*" -prune -o -type f -name package.json -print))

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ make install
6565
Start the LocalStack server using the following command:
6666

6767
```bash
68-
export LOCALSTACK_API_KEY=<YOUR_API_KEY>
68+
export LOCALSTACK_AUTH_TOKEN=<YOUR_AUTH_TOKEN>
6969
make start-localstack
7070
```
7171

@@ -166,12 +166,8 @@ Node.js applications. 🛠️🔍
166166

167167
1️⃣ **Configure LocalStack for remote Node.js debugging** 🛠️
168168

169-
First, we need to configure LocalStack to enable remote debugging of Node.js applications. To do so, we need to set
170-
the `ECS_DOCKER_FLAGS` to enable the debugger using `NODE_OPTIONS`:
169+
First, we need to configure LocalStack to enable remote debugging of Node.js applications. In devops-tooling/docker-compose.yml file, uncomment **ECS_DOCKER_FLAGS** line to enable required configuration for remote debugging.
171170

172-
```bash
173-
export ECS_DOCKER_FLAGS="-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229"
174-
```
175171

176172
2️⃣ **Adding a Task to Wait for Remote Debugger Server** 🕰️
177173

@@ -205,7 +201,7 @@ existing one from the *Run and Debug* tab, then add the following configuration.
205201
"localRoot": "${workspaceFolder}",
206202
"name": "Attach to Remote Node.js",
207203
"port": 9229,
208-
"remoteRoot": "/var/task/",
204+
"remoteRoot": "/app",
209205
"request": "attach",
210206
"type": "node",
211207
"preLaunchTask": "Wait Remote Debugger Server"
@@ -214,7 +210,16 @@ existing one from the *Run and Debug* tab, then add the following configuration.
214210
}
215211
```
216212

217-
4️⃣ **Running the Debugger** 🏃
213+
4️⃣ **Start LocalStack**
214+
215+
Start the LocalStack server using the following command:
216+
217+
```bash
218+
export LOCALSTACK_AUTH_TOKEN=<YOUR_AUTH_TOKEN>
219+
make start-localstack
220+
```
221+
222+
5️⃣ **Running the Debugger** 🏃
218223

219224
Finally, run the debugger by selecting the *Attach to Remote Node.js* configuration from the *Run and Debug* tab. You
220225
can now set breakpoints and debug your Node.js application running in a Docker container. 🐳

devops-tooling/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
- ENFORCE_IAM=${ENFORCE_IAM-0} # Enable IAM policy evaluation and enforcement
1515
- LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT=90
1616
- PERSIST_ALL=${PERSIST_ALL-false}
17-
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-}
1817
- LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN-}
18+
# - ECS_DOCKER_FLAGS=-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229 # Optional flag required for remote debugging
1919
volumes:
2020
- /var/run/docker.sock:/var/run/docker.sock # Mount the Docker socket into the container

iac/awscdk/lib/repo-stack.ts

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,72 @@
1-
import * as cdk from 'aws-cdk-lib'
2-
import {DockerImageAsset, Platform} from 'aws-cdk-lib/aws-ecr-assets'
3-
import {Construct} from 'constructs'
4-
// import * as sqs from 'aws-cdk-lib/aws-sqs';
5-
import * as ec2 from "aws-cdk-lib/aws-ec2"
6-
import * as ecs from "aws-cdk-lib/aws-ecs"
7-
import * as ecs_patterns from "aws-cdk-lib/aws-ecs-patterns"
1+
import * as cdk from 'aws-cdk-lib';
2+
import { DockerImageAsset, Platform } from 'aws-cdk-lib/aws-ecr-assets';
3+
import { Construct } from 'constructs';
4+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
5+
import * as ecs from 'aws-cdk-lib/aws-ecs';
6+
import * as ecs_patterns from 'aws-cdk-lib/aws-ecs-patterns';
87

9-
const path = require('path')
8+
const path = require('path');
109

1110
export class RepoStack extends cdk.Stack {
12-
/**
13-
*
14-
* @param {Construct} scope
15-
* @param {string} id
16-
* @param {StackProps=} props
17-
*/
1811
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
19-
super(scope, id, props)
12+
super(scope, id, props);
2013

21-
// base infrastructure
22-
const vpc = new ec2.Vpc(this, 'VPC', {maxAzs: 2})
14+
const vpc = new ec2.Vpc(this, 'VPC', {maxAzs: 2});
2315
const cluster = new ecs.Cluster(this, 'Cluster', {
2416
clusterName: 'Services',
2517
vpc: vpc
26-
})
18+
});
2719

2820
const asset = new DockerImageAsset(this, 'service1', {
2921
directory: path.join(__dirname, '../../../src'),
3022
platform: Platform.LINUX_AMD64,
31-
})
23+
});
24+
25+
const taskDefinition = new ecs.FargateTaskDefinition(this, "MyFargateTask", {
26+
cpu: 512,
27+
memoryLimitMiB: 2048,
28+
});
29+
30+
taskDefinition.addVolume({
31+
name: 'local-src',
32+
host: {
33+
sourcePath: path.join(__dirname, '../../../src/app')
34+
}
35+
});
36+
37+
const container = taskDefinition.addContainer("MyFargateContainer", {
38+
image: ecs.ContainerImage.fromDockerImageAsset(asset),
39+
logging: new ecs.AwsLogDriver({streamPrefix: "MyApp"}),
40+
memoryLimitMiB: 2048,
41+
cpu: 512
42+
});
43+
44+
container.addPortMappings({
45+
containerPort: 3000
46+
});
47+
48+
// Match the container path with the Dockerfile WORKDIR
49+
container.addMountPoints({
50+
containerPath: '/app',
51+
sourceVolume: 'local-src',
52+
readOnly: false
53+
});
3254

33-
// task definition
34-
// Create a load-balanced Fargate service and make it public
3555
const albfs = new ecs_patterns.ApplicationLoadBalancedFargateService(this, "MyFargateService", {
36-
cluster: cluster, // Required
37-
cpu: 512, // Default is 256
38-
desiredCount: 2, // Default is 1
39-
taskImageOptions: {
40-
image: ecs.ContainerImage.fromDockerImageAsset(asset),
41-
containerPort: 3000,
42-
},
43-
memoryLimitMiB: 2048, // Default is 512
56+
cluster: cluster,
57+
desiredCount: 1,
58+
taskDefinition: taskDefinition,
4459
listenerPort: 80,
45-
publicLoadBalancer: true // Default is true
46-
})
60+
publicLoadBalancer: true
61+
});
4762

4863
new cdk.CfnOutput(this, 'serviceslb', {
4964
value: albfs.loadBalancer.loadBalancerDnsName,
50-
})
65+
});
5166
new cdk.CfnOutput(this, 'localstackserviceslb', {
5267
value: `${albfs.loadBalancer.loadBalancerDnsName}:4566`,
53-
})
68+
});
5469
}
5570
}
5671

57-
module.exports = {RepoStack}
72+
module.exports = {RepoStack};

0 commit comments

Comments
 (0)