Skip to content

Commit 2d1521c

Browse files
committed
cap08-05-conhecendo-a-aplicacao-escopo-do-ci
1 parent 0d21f6f commit 2d1521c

19 files changed

Lines changed: 11954 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Include any files or directories that you don't want to be copied to your
2+
# container here (e.g., local build artifacts, temporary files, etc.).
3+
#
4+
# For more help, visit the .dockerignore file reference guide at
5+
# https://docs.docker.com/go/build-context-dockerignore/
6+
7+
**/.classpath
8+
**/.dockerignore
9+
**/.env
10+
**/.git
11+
**/.github
12+
**/.gitignore
13+
**/.project
14+
**/.settings
15+
**/.toolstarget
16+
**/.vs
17+
**/.vscode
18+
**/.next
19+
**/.cache
20+
**/*.*proj.user
21+
**/*.dbmdl
22+
**/*.jfm
23+
**/charts
24+
**/docker-compose*
25+
**/compose.y*ml
26+
**/Dockerfile*
27+
**/node_modules
28+
**/npm-debug.log
29+
**/obj
30+
**/secrets.dev.yaml
31+
**/values.dev.yaml
32+
**/build
33+
**/dist
34+
**/*.log
35+
!logs/app.log
36+
LICENSE
37+
README.md

src/ci/nestjs-project/.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

src/ci/nestjs-project/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
FROM node:23.0.0-slim AS ci
2+
3+
ARG REPO_PATH=github.com/argentinaluiz/private-repo.git
4+
5+
RUN apt update && apt install -y \
6+
git \
7+
curl && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
USER node
11+
12+
RUN mkdir /home/node/app
13+
14+
WORKDIR /home/node/app
15+
16+
RUN --mount=type=bind,source=package.json,target=package.json \
17+
--mount=type=bind,source=package-lock.json,target=package-lock.json \
18+
--mount=type=cache,target=/home/node/.npm,uid=1000,gid=1000,id=npm-cache \
19+
npm ci
20+
21+
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN \
22+
git clone https://github_user:$GITHUB_TOKEN@${REPO_PATH} /home/node/app/private-repo
23+
24+
RUN chmod +x /home/node/app/private-repo/script.sh
25+
26+
COPY --chown=node:node . .
27+
28+
CMD [ "tail", "-f", "/dev/null" ]
29+
30+
FROM node:23.0.0-slim AS builder
31+
32+
ENV NODE_ENV=production
33+
34+
USER node
35+
36+
RUN mkdir /home/node/app
37+
38+
WORKDIR /home/node/app
39+
40+
COPY --from=ci --chown=node:node /home/node/app .
41+
RUN npm run build
42+
43+
RUN --mount=type=cache,target=/home/node/.npm,uid=1000,gid=1000,id=npm-cache \
44+
npm ci --only=production
45+
46+
FROM node:23.0.0-slim AS production
47+
48+
ENV NODE_ENV=production
49+
50+
USER node
51+
52+
RUN mkdir /home/node/app
53+
54+
WORKDIR /home/node/app
55+
56+
COPY --chown=node:node --from=builder /home/node/app/dist ./dist
57+
COPY --chown=node:node --from=builder /home/node/app/node_modules ./node_modules
58+
COPY --chown=node:node --from=builder /home/node/app/package.json ./
59+
60+
EXPOSE 3000
61+
62+
CMD [ "node", "dist/main.js" ]

src/ci/nestjs-project/README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<p align="center">
2+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3+
</p>
4+
5+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6+
[circleci-url]: https://circleci.com/gh/nestjs/nest
7+
8+
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9+
<p align="center">
10+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
15+
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
16+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
17+
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
18+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
19+
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
20+
</p>
21+
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
22+
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
23+
24+
## Description
25+
26+
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
27+
28+
## Project setup
29+
30+
```bash
31+
$ npm install
32+
```
33+
34+
## Compile and run the project
35+
36+
```bash
37+
# development
38+
$ npm run start
39+
40+
# watch mode
41+
$ npm run start:dev
42+
43+
# production mode
44+
$ npm run start:prod
45+
```
46+
47+
## Run tests
48+
49+
```bash
50+
# unit tests
51+
$ npm run test
52+
53+
# e2e tests
54+
$ npm run test:e2e
55+
56+
# test coverage
57+
$ npm run test:cov
58+
```
59+
60+
## Deployment
61+
62+
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
63+
64+
If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
65+
66+
```bash
67+
$ npm install -g @nestjs/mau
68+
$ mau deploy
69+
```
70+
71+
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
72+
73+
## Resources
74+
75+
Check out a few resources that may come in handy when working with NestJS:
76+
77+
- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
78+
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
79+
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
80+
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
81+
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
82+
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
83+
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
84+
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
85+
86+
## Support
87+
88+
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
89+
90+
## Stay in touch
91+
92+
- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
93+
- Website - [https://nestjs.com](https://nestjs.com/)
94+
- Twitter - [@nestframework](https://twitter.com/nestframework)
95+
96+
## License
97+
98+
Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
services:
2+
nestjs:
3+
image: argentinaluiz/docker-prod-test:ci
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.prod
7+
target: ci
8+
ports:
9+
- 3000:3000
10+
deploy:
11+
resources:
12+
limits:
13+
cpus: '0.5' # Máximo 50% de 1 CPU
14+
memory: 512M # Máximo 512MB de RAM
15+
reservations:
16+
cpus: '0.25' # Reserva mínima 25% de 1 CPU
17+
memory: 256M # Reserva mínima 256MB de RAM
18+
cap_drop:
19+
- ALL
20+
security_opt:
21+
- no-new-privileges:true
22+
# Um healthcheck pode ser adicionado quando tenhamos um comando já que iniciará a aplicação
23+
# nesta aplicação temos o comando "tail -f /dev/null" apenas para manter o container rodando
24+
# permitindo rodar o que quisermos para testes
25+
# healthcheck:
26+
# test: ["CMD-SHELL", "curl -f http://localhost:3000/health || exit 1"]
27+
# interval: 1m30s
28+
# timeout: 30s
29+
# retries: 5
30+
# start_period: 30s
31+
depends_on:
32+
postgres:
33+
condition: service_healthy
34+
35+
postgres:
36+
image: postgres:15
37+
environment:
38+
POSTGRES_PASSWORD: example
39+
POSTGRES_DB: db
40+
ports:
41+
- 5432:5432
42+
deploy:
43+
resources:
44+
limits:
45+
cpus: '1.0' # Máximo 1 CPU completa
46+
memory: 1G # Máximo 1GB de RAM
47+
reservations:
48+
cpus: '0.5' # Reserva mínima 50% de 1 CPU
49+
memory: 512M # Reserva mínima 512MB de RAM
50+
healthcheck:
51+
test: ["CMD-SHELL", "pg_isready -U postgres"]
52+
interval: 1m30s
53+
timeout: 30s
54+
retries: 5
55+
start_period: 30s
56+
57+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @ts-check
2+
import eslint from '@eslint/js';
3+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
4+
import globals from 'globals';
5+
import tseslint from 'typescript-eslint';
6+
7+
export default tseslint.config(
8+
{
9+
ignores: ['eslint.config.mjs'],
10+
},
11+
eslint.configs.recommended,
12+
...tseslint.configs.recommendedTypeChecked,
13+
eslintPluginPrettierRecommended,
14+
{
15+
languageOptions: {
16+
globals: {
17+
...globals.node,
18+
...globals.jest,
19+
},
20+
sourceType: 'commonjs',
21+
parserOptions: {
22+
projectService: true,
23+
tsconfigRootDir: import.meta.dirname,
24+
},
25+
},
26+
},
27+
{
28+
rules: {
29+
'@typescript-eslint/no-explicit-any': 'off',
30+
'@typescript-eslint/no-floating-promises': 'warn',
31+
'@typescript-eslint/no-unsafe-argument': 'warn'
32+
},
33+
},
34+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/nest-cli",
3+
"collection": "@nestjs/schematics",
4+
"sourceRoot": "src",
5+
"compilerOptions": {
6+
"deleteOutDir": true
7+
}
8+
}

0 commit comments

Comments
 (0)