@studion/infra-code-blocks 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +281 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,290 @@
|
|
|
1
1
|
# `@studion/infra-code-blocks`
|
|
2
2
|
|
|
3
|
-
Studion common infra components.
|
|
3
|
+
Studion Platform common infra components.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [Installation](#installation)
|
|
8
|
+
2. [Usage](#usage)
|
|
9
|
+
3. [API](#api)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
6
12
|
|
|
7
13
|
- Run the command:
|
|
8
14
|
|
|
9
15
|
```bash
|
|
10
16
|
$ npm i @studion/infra-code-blocks
|
|
11
17
|
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
- Import Studion infra components in your project
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import * as studion from '@studion/infra-code-blocks';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- Use Studion components
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import * as studion from '@studion/infra-code-blocks';
|
|
31
|
+
|
|
32
|
+
const project = new studion.Project('demo-project', {
|
|
33
|
+
environment: 'DEVELOPMENT',
|
|
34
|
+
services: [
|
|
35
|
+
{
|
|
36
|
+
type: 'REDIS',
|
|
37
|
+
serviceName: 'redis',
|
|
38
|
+
dbName: 'test-db',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const projectName = project.name;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
1. [Project](#project)
|
|
49
|
+
2. [Database](#database)
|
|
50
|
+
3. [Redis](#redis)
|
|
51
|
+
4. [StaticSite](#static-site)
|
|
52
|
+
5. [WebServer](#web-server)
|
|
53
|
+
|
|
54
|
+
### Project
|
|
55
|
+
|
|
56
|
+
Project component makes it really easy to spin up project infrastructure,
|
|
57
|
+
hiding infrastructure complexity.
|
|
58
|
+
<br>
|
|
59
|
+
The component creates its own VPC which is used for resources within the project.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
new Project(name: string, args: ProjectArgs, opts?: pulumi.CustomResourceOptions);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Argument | Description |
|
|
66
|
+
| :------- | :--------------------------------------------: |
|
|
67
|
+
| name \* | The unique name of the resource. |
|
|
68
|
+
| args \* | The arguments to resource properties. |
|
|
69
|
+
| opts | Bag of options to control resource's behavior. |
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
type ProjectArgs = {
|
|
73
|
+
services: (
|
|
74
|
+
| DatabaseService
|
|
75
|
+
| RedisService
|
|
76
|
+
| StaticSiteService
|
|
77
|
+
| WebServerService
|
|
78
|
+
)[];
|
|
79
|
+
environment: Environment;
|
|
80
|
+
hostedZoneId?: pulumi.Input<string>;
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Argument | Description |
|
|
85
|
+
| :------------- | :---------------------------------------------------------------------: |
|
|
86
|
+
| services \* | Service list. |
|
|
87
|
+
| environment \* | Environment name. |
|
|
88
|
+
| hostedZoneId | Route53 hosted zone ID responsible for managing records for the domain. |
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
type DatabaseService = {
|
|
92
|
+
type: 'DATABASE';
|
|
93
|
+
serviceName: string;
|
|
94
|
+
dbName: pulumi.Input<string>;
|
|
95
|
+
username: pulumi.Input<string>;
|
|
96
|
+
password: pulumi.Input<string>;
|
|
97
|
+
applyImmediately?: pulumi.Input<boolean>;
|
|
98
|
+
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
99
|
+
allocatedStorage?: pulumi.Input<number>;
|
|
100
|
+
maxAllocatedStorage?: pulumi.Input<number>;
|
|
101
|
+
instanceClass?: pulumi.Input<string>;
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
export type RedisService = {
|
|
107
|
+
type: 'REDIS';
|
|
108
|
+
serviceName: string;
|
|
109
|
+
dbName: pulumi.Input<string>;
|
|
110
|
+
region?: pulumi.Input<string>;
|
|
111
|
+
};
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
export type StaticSiteService = {
|
|
116
|
+
type: 'STATIC_SITE';
|
|
117
|
+
serviceName: string;
|
|
118
|
+
domain: pulumi.Input<string>;
|
|
119
|
+
};
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
export type WebServerService = {
|
|
124
|
+
type: 'WEB_SERVER';
|
|
125
|
+
serviceName: string;
|
|
126
|
+
environment?:
|
|
127
|
+
| aws.ecs.KeyValuePair[]
|
|
128
|
+
| ((services: Services) => aws.ecs.KeyValuePair[]);
|
|
129
|
+
image: pulumi.Input<string>;
|
|
130
|
+
port: pulumi.Input<number>;
|
|
131
|
+
domain: pulumi.Input<string>;
|
|
132
|
+
desiredCount?: pulumi.Input<number>;
|
|
133
|
+
minCount?: pulumi.Input<number>;
|
|
134
|
+
maxCount?: pulumi.Input<number>;
|
|
135
|
+
size?: pulumi.Input<Size>;
|
|
136
|
+
healtCheckPath?: pulumi.Input<string>;
|
|
137
|
+
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
138
|
+
pulumi.Input<RoleInlinePolicy>[]
|
|
139
|
+
>;
|
|
140
|
+
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
141
|
+
};
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Often, web server depends on other services such as database, Redis, etc.
|
|
145
|
+
For that purpose, environment factory can be used. The factory function
|
|
146
|
+
recieves services bag as argument.
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
const project = new studion.Project('demo-project', {
|
|
150
|
+
environment: 'DEVELOPMENT',
|
|
151
|
+
services: [
|
|
152
|
+
{
|
|
153
|
+
type: 'REDIS',
|
|
154
|
+
serviceName: 'redis',
|
|
155
|
+
dbName: 'test-db',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
type: 'WEB_SERVER',
|
|
159
|
+
serviceName: 'api',
|
|
160
|
+
image: imageUri,
|
|
161
|
+
port: 3000,
|
|
162
|
+
domain: 'api.my-domain.com',
|
|
163
|
+
environment: (services: Services) => {
|
|
164
|
+
const redisServiceName = 'redis';
|
|
165
|
+
const redis = services[redisServiceName];
|
|
166
|
+
return [
|
|
167
|
+
{ name: 'REDIS_HOST', value: redis.endpoint },
|
|
168
|
+
{ name: 'REDIS_PORT', value: redis.port.apply(port => String(port)) },
|
|
169
|
+
];
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Database
|
|
177
|
+
|
|
178
|
+
RDS Postgres instance.
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
new Database(name: string, args: DatabaseArgs, opts?: pulumi.CustomResourceOptions);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
| Argument | Description |
|
|
185
|
+
| :------- | :--------------------------------------------: |
|
|
186
|
+
| name \* | The unique name of the resource. |
|
|
187
|
+
| args \* | The arguments to resource properties. |
|
|
188
|
+
| opts | Bag of options to control resource's behavior. |
|
|
189
|
+
|
|
190
|
+
```ts
|
|
191
|
+
type DatabaseArgs = {
|
|
192
|
+
dbName: pulumi.Input<string>;
|
|
193
|
+
username: pulumi.Input<string>;
|
|
194
|
+
password: pulumi.Input<string>;
|
|
195
|
+
vpc: awsx.ec2.Vpc;
|
|
196
|
+
applyImmediately?: pulumi.Input<boolean>;
|
|
197
|
+
skipFinalSnapshot?: pulumi.Input<boolean>;
|
|
198
|
+
allocatedStorage?: pulumi.Input<number>;
|
|
199
|
+
maxAllocatedStorage?: pulumi.Input<number>;
|
|
200
|
+
instanceClass?: pulumi.Input<string>;
|
|
201
|
+
};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Redis
|
|
205
|
+
|
|
206
|
+
Upstash Redis instance.
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
new Redis(name: string, args: RedisArgs, opts: RedisOptions);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
| Argument | Description |
|
|
213
|
+
| :------- | :--------------------------------------------: |
|
|
214
|
+
| name \* | The unique name of the resource. |
|
|
215
|
+
| args \* | The arguments to resource properties. |
|
|
216
|
+
| opts | Bag of options to control resource's behavior. |
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
type RedisArgs = {
|
|
220
|
+
dbName: pulumi.Input<string>;
|
|
221
|
+
region?: pulumi.Input<string>;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
interface RedisOptions extends pulumi.ComponentResourceOptions {
|
|
225
|
+
provider: upstash.Provider;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Static Site
|
|
230
|
+
|
|
231
|
+
A static site that will be deployed using S3 + Cloudfront.
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
new StaticSite(name: string, args: StaticSiteArgs, opts?: pulumi.ComponentResourceOptions );
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
| Argument | Description |
|
|
238
|
+
| :------- | :--------------------------------------------: |
|
|
239
|
+
| name \* | The unique name of the resource. |
|
|
240
|
+
| args \* | The arguments to resource properties. |
|
|
241
|
+
| opts | Bag of options to control resource's behavior. |
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
type StaticSiteArgs = {
|
|
245
|
+
domain: pulumi.Input<string>;
|
|
246
|
+
hostedZoneId: pulumi.Input<string>;
|
|
247
|
+
};
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Web Server
|
|
251
|
+
|
|
252
|
+
A web server that will be deployed to ECS Fargate service with autoscaling enabled.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
new WebServer(name: string, args: WebServerArgs, opts?: pulumi.ComponentResourceOptions );
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
| Argument | Description |
|
|
259
|
+
| :------- | :--------------------------------------------: |
|
|
260
|
+
| name \* | The unique name of the resource. |
|
|
261
|
+
| args \* | The arguments to resource properties. |
|
|
262
|
+
| opts | Bag of options to control resource's behavior. |
|
|
263
|
+
|
|
264
|
+
```ts
|
|
265
|
+
export type WebServerArgs = {
|
|
266
|
+
image: pulumi.Input<string>;
|
|
267
|
+
port: pulumi.Input<number>;
|
|
268
|
+
domain: pulumi.Input<string>;
|
|
269
|
+
cluster: aws.ecs.Cluster;
|
|
270
|
+
hostedZoneId: pulumi.Input<string>;
|
|
271
|
+
vpc: awsx.ec2.Vpc;
|
|
272
|
+
desiredCount?: pulumi.Input<number>;
|
|
273
|
+
minCount?: pulumi.Input<number>;
|
|
274
|
+
maxCount?: pulumi.Input<number>;
|
|
275
|
+
size?: pulumi.Input<Size>;
|
|
276
|
+
environment?: aws.ecs.KeyValuePair[];
|
|
277
|
+
healtCheckPath?: pulumi.Input<string>;
|
|
278
|
+
taskExecutionRoleInlinePolicies?: pulumi.Input<
|
|
279
|
+
pulumi.Input<RoleInlinePolicy>[]
|
|
280
|
+
>;
|
|
281
|
+
taskRoleInlinePolicies?: pulumi.Input<pulumi.Input<RoleInlinePolicy>[]>;
|
|
282
|
+
};
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 🚧 TODO
|
|
286
|
+
|
|
287
|
+
- [x] Allow connection with RDS via ec2 instance
|
|
288
|
+
- [x] Execute commands from ecs service
|
|
289
|
+
- [ ] Add worker service for executing tasks
|
|
290
|
+
- [ ] Update docs, describe each service, describe required stack configs...
|