Skip to content

Commit fd57407

Browse files
authored
Merge pull request #1 from mugarate12/feature/docker-builds
Feature/docker builds
2 parents b0005ac + 00b39c8 commit fd57407

9 files changed

Lines changed: 147 additions & 11 deletions

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
- [Getting Started](#getting-started)
88
- [Usage](#usage)
99
- [Folder Structure](#folder-structure)
10-
- [Scripts in project](#scripts-in-project)
10+
- [Basic Scripts In Project](#basic-scripts-in-project)
11+
- [Docker Scripts In Project](#docker-scripts-in-project)
1112
- [Future Features](#future-features)
1213

1314
## Getting Started
@@ -37,7 +38,11 @@ project
3738
│ CHANGELOG.md
3839
│ README.md
3940
│ docker-compose.yml
41+
│ docker-compose.test.yml
42+
│ docker-compose.dev.yml
4043
│ Dockerfile
44+
│ Dockerfile.test
45+
│ Dockerfile.dev
4146
│ babel.config.js
4247
│ package-lock.json
4348
│ package.json
@@ -70,8 +75,9 @@ project
7075
│ │ index.ts
7176
```
7277

73-
## Scripts in project
74-
- Your package.json have initial commands to build, run and create server to development
78+
## Basic Scripts In Project
79+
80+
- Your package.json have initial commands to build, run, test and create server to development
7581

7682
build your project:
7783
```shell
@@ -92,8 +98,24 @@ run all of tests in project:
9298
```shell
9399
npm run test
94100
```
101+
> Test your application run correctlly to send HTTP GET to localhost:8000
102+
103+
## Docker Scripts In Project
104+
105+
run your project in docker to production:
106+
```shell
107+
npm run docker:prod
108+
```
95109

96-
- Test your application run correctlly to send HTTP GET to localhost:8000
110+
run your project in docker to development:
111+
```shell
112+
npm run docker:dev
113+
```
114+
115+
run your project in docker to test:
116+
```shell
117+
npm run docker:test
118+
```
97119

98120
## Future Features
99121

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "basic-node-ts-config",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "Configuração básica para um ambiente de desenvolvimento com NodeJs + TypeScript",
55
"main": "./lib/copyFile.js",
66
"preferGlobal": true,

project/Dockerfile.dev

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Or whatever Node version/image you want
2+
FROM node:lts
3+
4+
# Create app directory
5+
WORKDIR '/var/www/app'
6+
7+
# Copy all files starts with package and ends wit .json
8+
COPY package*.json ./
9+
10+
# Install app dependencies
11+
RUN npm i
12+
13+
# Copy all files from current directory to app directory
14+
COPY . .
15+
16+
# Listen on port 8000
17+
EXPOSE 8000
18+
19+
# Run the app
20+
CMD [ "npm", "run", "dev" ]

project/Dockerfile.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Or whatever Node version/image you want
2+
FROM node:lts
3+
4+
# Create app directory
5+
WORKDIR '/var/www/app'
6+
7+
# Copy all files starts with package and ends wit .json
8+
COPY package*.json ./
9+
10+
# Install app dependencies
11+
RUN npm i
12+
13+
# Copy all files from current directory to app directory
14+
COPY . .
15+
16+
# Listen on port 8000
17+
EXPOSE 8000
18+
19+
# Run the app
20+
CMD [ "npm", "run", "test:docker" ]

project/README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
- [Getting Started](#getting-started)
88
- [Configuration](#configuration)
9-
- [Scripts](#scripts)
9+
- [Basic Scripts](#basic-scripts)
10+
- [Docker Scripts](#docker-scripts)
1011
- [Folder Structure](#folder-structure)
1112
- [Docker](#docker)
1213

@@ -29,7 +30,7 @@ Set the environment variables in the `.env` file like the `.env.example` file.
2930
- `NODE_ENV`: Set type of environment to run the server mode (development, production, test).
3031
- `REDIS_URL`: URI of the Redis server. By default is `redis://localhost:6379`.
3132

32-
## Scripts
33+
## Basic scripts
3334

3435
- Your package.json have initial commands to build, run, test and create server to development
3536

@@ -52,8 +53,24 @@ run all of tests in project:
5253
```shell
5354
npm run test
5455
```
56+
> Test your application run correctlly to send HTTP GET to localhost:8000
5557
56-
- Test your application run correctlly to send HTTP GET to localhost:8000
58+
## Docker scripts
59+
60+
run your project in docker to production:
61+
```shell
62+
npm run docker:prod
63+
```
64+
65+
run your project in docker to development:
66+
```shell
67+
npm run docker:dev
68+
```
69+
70+
run your project in docker to test:
71+
```shell
72+
npm run docker:test
73+
```
5774

5875
## Folder Structure
5976

@@ -66,7 +83,11 @@ project
6683
│ CHANGELOG.md
6784
│ README.md
6885
│ docker-compose.yml
86+
│ docker-compose.test.yml
87+
│ docker-compose.dev.yml
6988
│ Dockerfile
89+
│ Dockerfile.dev
90+
│ Dockerfile.test
7091
│ babel.config.js
7192
│ package-lock.json
7293
│ package.json

project/docker-compose.dev.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: "3.9"
2+
3+
services:
4+
redis:
5+
image: redis
6+
container_name: cache
7+
expose:
8+
- 6379
9+
10+
app:
11+
build: ./Dockerfile.dev
12+
volumes:
13+
- .:/src
14+
- ./:/var/www/app # docker workdir
15+
depends_on:
16+
- redis
17+
ports:
18+
- "8000:8000"
19+
environment:
20+
- REDIS_URL=redis://cache
21+
- NODE_ENV=development
22+
- PORT=8000
23+
command:
24+
sh -c 'npm run dev'
25+

project/docker-compose.test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3.9"
2+
3+
services:
4+
redis:
5+
image: redis
6+
container_name: cache
7+
expose:
8+
- 6379
9+
10+
app:
11+
build: ./Dockerfile.test
12+
volumes:
13+
- ./:/var/www/app # docker workdir
14+
depends_on:
15+
- redis
16+
ports:
17+
- "8000:8000"
18+
environment:
19+
- REDIS_URL=redis://cache
20+
- NODE_ENV=test
21+
- PORT=8000
22+
command:
23+
sh -c 'npm run test:docker'
24+

project/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
"main": "src/app.js",
66
"scripts": {
77
"build": "tsc",
8-
"dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules src/server.ts",
8+
"dev": "ts-node-dev --poll --respawn --transpile-only --ignore-watch node_modules src/server.ts",
99
"start": "npm run build&&node build/src/server.js",
10-
"test": "SET NODE_ENV=test&&jest"
10+
"test": "SET NODE_ENV=test&&jest",
11+
"test:docker": "jest",
12+
"docker:test": "docker-compose -f ./docker-compose.test.yml up",
13+
"docker:dev": "docker-compose -f ./docker-compose.dev.yml up",
14+
"docker:prod": "docker-compose -f ./docker-compose.yml up"
1115
},
1216
"keywords": [],
1317
"author": "",

0 commit comments

Comments
 (0)