Skip to content

Commit 02b04c1

Browse files
committed
2 parents aed9e09 + f7a2fb2 commit 02b04c1

37 files changed

+14963
-0
lines changed

examples/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Infra code blocks examples
2+
3+
## Table of contents
4+
5+
1. [Prerequisites](#prerequisites)
6+
2. [Setup](#setup)
7+
3. [Mongo with web server](#mongo-with-web-server)
8+
4. [Database with web server and redis](#database-with-web-server-and-redis)
9+
5. [Static site](#static-site)
10+
11+
### Prerequisites
12+
13+
- Working [Pulumi](https://www.pulumi.com/docs/clouds/aws/get-started/begin/#pulumi-aws-before-you-begin) project
14+
- AWS account with neccessary permissions for each component used
15+
- aws-cli package
16+
17+
### Setup
18+
19+
- Build infra code blocks library:
20+
21+
```bash
22+
$ npm run build
23+
```
24+
25+
- Navigate to example directory and install dependencies:
26+
27+
```bash
28+
$ npm i
29+
```
30+
31+
### Mongo with web server
32+
33+
- Set ENV variables using provided example
34+
35+
- Deploy pulumi project:
36+
37+
```bash
38+
$ pulumi up
39+
```
40+
41+
### Database with web server and redis
42+
43+
- Set ENV variables using provided example
44+
45+
- Deploy pulumi project:
46+
47+
```bash
48+
$ pulumi up
49+
```
50+
51+
### Static site
52+
53+
- Deploy pulumi project:
54+
55+
```bash
56+
$ pulumi up
57+
```
58+
59+
Deploy command will output bucket and service names. Bucket name can be used
60+
to upload static site files.
61+
62+
```
63+
bucket: [BUCKET_NAME]
64+
default: [SERVICE_NAME]
65+
```
66+
67+
- Files are upload to bucket with following command:
68+
69+
```bash
70+
$ S3_SITE_BUCKET=[BUCKET_NAME] npm run deploy
71+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/bin/
2+
/node_modules/
3+
.env
4+
5+
Pulumi.*.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: database_with_web_server_and_redis
2+
runtime: nodejs
3+
description: Infra Code Blocks database with web server and redis example
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DATABASE_USERNAME=username
2+
DATABASE_PASSWORD=password
3+
DATABASE_HOST=host
4+
DATABASE_DBNAME=dbname
5+
REDIS_PORT=port
6+
REDIS_HOST=redis_host
7+
REDIS_PASSWORD=password
8+
NODE_ENV=development
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node:20.9-bookworm-slim@sha256:c325fe5059c504933948ae6483f3402f136b96492dff640ced5dfa1f72a51716 AS base
2+
RUN apt update && apt install -y --no-install-recommends dumb-init
3+
ENTRYPOINT ["dumb-init", "--"]
4+
5+
FROM node:20.9-bookworm@sha256:3c48678afb1ae5ca5931bd154d8c1a92a4783555331b535bbd7e0822f9ca8603 AS install
6+
WORKDIR /usr/src/app
7+
COPY package*.json .
8+
RUN npm ci
9+
10+
FROM base AS configure
11+
WORKDIR /usr/src/app
12+
COPY --chown=node:node --from=install /usr/src/app/node_modules ./node_modules
13+
COPY --chown=node:node ./package.json ./tsconfig.json ./knexfile.ts ./
14+
COPY --chown=node:node ./src ./src
15+
RUN npm run build
16+
17+
FROM configure AS run
18+
USER node
19+
CMD npm run migrate && npm run prod
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Knex } from 'knex';
2+
3+
require('dotenv').config();
4+
5+
const username = process.env.DATABASE_USERNAME;
6+
const password = process.env.DATABASE_PASSWORD;
7+
const host = process.env.DATABASE_HOST;
8+
const dbName = process.env.DATABASE_DBNAME;
9+
10+
const connectionString = `postgres://${username}:${password}@${host}:5432/${dbName}`;
11+
12+
const knexConfig: { [key: string]: Knex.Config } = {
13+
development: {
14+
client: 'postgresql',
15+
connection: {
16+
connectionString,
17+
},
18+
migrations: {
19+
directory: 'src/migrations',
20+
},
21+
},
22+
production: {
23+
client: 'postgresql',
24+
connection: {
25+
connectionString,
26+
ssl: { rejectUnauthorized: false },
27+
},
28+
migrations: {
29+
directory: 'src/migrations',
30+
},
31+
},
32+
};
33+
34+
export default knexConfig;

0 commit comments

Comments
 (0)