Skip to content

Commit cf4457c

Browse files
authored
Merge pull request #23 from Throyer/react-app
React app
2 parents 7fa83bb + decbcbe commit cf4457c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+7643
-534
lines changed

.docker/.env.example

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
11
# docker
2-
COMPOSE_PROJECT_NAME=spring-boot-crud-containers
2+
COMPOSE_PROJECT_NAME=spring-boot-example
33
TIMEZONE=America/Sao_Paulo
44

5+
# api
6+
API_PORT=8080
7+
API_DEBUG_PORT=8000
8+
9+
# web
10+
APP_PORT=3000
11+
APP_API_BASE_URL=http://localhost:8080/api
12+
513
# database
6-
DB_URL=database:5432/example_api
14+
DB_HOST=database
15+
DB_PORT=5432
16+
DB_NAME=example
717
DB_USERNAME=root
8-
DB_PASSWORD=root
18+
DB_PASSWORD=root
19+
DB_SHOW_SQL=true
20+
DB_MAX_CONNECTIONS=5
21+
22+
# security
23+
TOKEN_SECRET=secret
24+
TOKEN_EXPIRATION_IN_HOURS=24
25+
REFRESH_TOKEN_EXPIRATION_IN_DAYS=7
26+
MINUTES_TO_EXPIRE_RECOVERY_CODE=20
27+
MAX_REQUESTS_PER_MINUTE=20
28+
29+
# smtp
30+
SMTP_HOST=smtp.gmail.com
31+
SMTP_PORT=587
32+
SMTP_USERNAME=user@gmail
33+
SMTP_PASSWORD=secret
34+
35+
# swagger
36+
SWAGGER_URL=/docs
37+
SWAGGER_USERNAME=
38+
SWAGGER_PASSWORD=

.docker/docker-compose.dev.yml

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,119 @@ services:
44
database:
55
image: postgres:13
66
restart: unless-stopped
7-
container_name: example-api-database
8-
command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"]
7+
container_name: ${COMPOSE_PROJECT_NAME}-database
8+
command:
9+
[
10+
"postgres",
11+
"-c",
12+
"log_statement=all",
13+
"-c",
14+
"log_destination=stderr"
15+
]
916
ports:
10-
- "5432:5432"
17+
- "${DB_PORT}:5432"
1118
environment:
1219
POSTGRES_USER: ${DB_USERNAME}
1320
POSTGRES_PASSWORD: ${DB_PASSWORD}
14-
POSTGRES_DB: example_api
15-
TZ: America/Sao_Paulo
16-
PGTZ: America/Sao_Paulo
21+
POSTGRES_DB: ${DB_NAME}
22+
TZ: ${TIMEZONE}
23+
PGTZ: ${TIMEZONE}
1724
volumes:
18-
- ./.volumes/database:/var/lib/postgresql/data
25+
- ~/.volumes/database/postgresql:/var/lib/postgresql/data
1926
networks:
20-
- example-api
27+
- spring-boot-example-network
2128
tty: true
2229

2330
api:
24-
image: maven:3.8.5-openjdk-17
31+
build:
32+
context: ../api
33+
dockerfile: ../api/docker/Dockerfile.dev
34+
image: throyer/springboot/example-api-development:latest
35+
platform: linux/x86_64
2536
restart: unless-stopped
26-
container_name: example-api-development
37+
container_name: ${COMPOSE_PROJECT_NAME}-api
2738
links:
2839
- database
2940
ports:
30-
- "8080:8080"
31-
- "8000:8000"
41+
- "${API_PORT}:${API_PORT}"
42+
- "${API_DEBUG_PORT}:${API_DEBUG_PORT}"
3243
environment:
33-
DB_URL: ${DB_URL}
44+
45+
# database
46+
DB_PORT: ${DB_PORT}
47+
DB_NAME: ${DB_NAME}
48+
DB_HOST: ${DB_HOST}
3449
DB_USERNAME: ${DB_USERNAME}
3550
DB_PASSWORD: ${DB_PASSWORD}
51+
DB_SHOW_SQL: ${DB_SHOW_SQL}
52+
DB_MAX_CONNECTIONS: ${DB_MAX_CONNECTIONS}
53+
54+
# security
55+
TOKEN_SECRET: ${TOKEN_SECRET}
56+
TOKEN_EXPIRATION_IN_HOURS: ${TOKEN_EXPIRATION_IN_HOURS}
57+
REFRESH_TOKEN_EXPIRATION_IN_DAYS: ${REFRESH_TOKEN_EXPIRATION_IN_DAYS}
58+
MINUTES_TO_EXPIRE_RECOVERY_CODE: ${MINUTES_TO_EXPIRE_RECOVERY_CODE}
59+
MAX_REQUESTS_PER_MINUTE: ${MAX_REQUESTS_PER_MINUTE}
60+
61+
# smtp
62+
SMTP_HOST: ${SMTP_HOST}
63+
SMTP_PORT: ${SMTP_PORT}
64+
SMTP_USERNAME: ${SMTP_USERNAME}
65+
SMTP_PASSWORD: ${SMTP_PASSWORD}
66+
67+
# swagger
68+
SWAGGER_URL: ${SWAGGER_URL}
69+
SWAGGER_USERNAME: ${SWAGGER_USERNAME}
70+
SWAGGER_PASSWORD: ${SWAGGER_PASSWORD}
3671
volumes:
3772
- ../api:/app
38-
- ./.volumes/maven:/root/.m2
73+
- ~/.m2:/root/.m2
3974
working_dir: /app
4075
networks:
41-
- example-api
76+
- spring-boot-example-network
4277
tty: true
43-
entrypoint: "mvn spring-boot:run"
44-
45-
# web:
46-
# image: node:16.14.2
47-
# restart: unless-stopped
48-
# container_name: example-api-front-end-development
49-
# ports:
50-
# - "4200:4200"
51-
# volumes:
52-
# - ../web:/app
53-
# working_dir: /app
54-
# networks:
55-
# - vendas
56-
# tty: true
57-
# entrypoint: "npm start"
78+
entrypoint: [
79+
"dockerize",
80+
"-wait",
81+
"tcp://database:${DB_PORT}",
82+
"-timeout",
83+
"20s",
84+
'mvn',
85+
'spring-boot:run',
86+
'-Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,address=*:${API_DEBUG_PORT},suspend=n"'
87+
]
88+
89+
web:
90+
image: throyer/springboot/example-web-development:latest
91+
build:
92+
context: ../web
93+
dockerfile: ../web/docker/Dockerfile.dev
94+
restart: unless-stopped
95+
container_name: ${COMPOSE_PROJECT_NAME}-web
96+
links:
97+
- api
98+
ports:
99+
- "${APP_PORT}:${APP_PORT}"
100+
volumes:
101+
- ../web:/app
102+
working_dir: /app
103+
networks:
104+
- spring-boot-example-network
105+
tty: true
106+
environment:
107+
APP_PORT: ${APP_PORT}
108+
VITE_API_BASE_URL: ${APP_API_BASE_URL}
109+
entrypoint: [
110+
"dockerize",
111+
"-wait",
112+
"http://api:${API_PORT}/api",
113+
"-timeout",
114+
"20s",
115+
"npm",
116+
"run",
117+
"dev"
118+
]
58119

59120
networks:
60-
example-api:
61-
driver: bridge
121+
spring-boot-example-network:
122+
driver: bridge

.docker/docker-compose.prod.yml

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,90 @@ services:
44
database:
55
image: postgres:13
66
restart: unless-stopped
7-
container_name: example-api-database
7+
container_name: ${COMPOSE_PROJECT_NAME}-database
88
ports:
9-
- "5432:5432"
9+
- "${DB_PORT}:5432"
1010
environment:
1111
POSTGRES_USER: ${DB_USERNAME}
1212
POSTGRES_PASSWORD: ${DB_PASSWORD}
13-
POSTGRES_DB: example_api
14-
TZ: America/Sao_Paulo
15-
PGTZ: America/Sao_Paulo
13+
POSTGRES_DB: ${DB_NAME}
14+
TZ: ${TIMEZONE}
15+
PGTZ: ${TIMEZONE}
1616
volumes:
17-
- ./.volumes/database:/var/lib/postgresql/data
17+
- ~/.volumes/database/postgresql:/var/lib/postgresql/data
1818
networks:
19-
- example-api
19+
- spring-boot-example-network
2020
tty: true
2121

2222
api:
2323
build:
2424
context: ../api
2525
dockerfile: ../api/docker/Dockerfile.prod
26-
image: throyer/example-api:latest
26+
image: throyer/springboot/spring-boot-example-network:latest
2727
platform: linux/x86_64
2828
restart: unless-stopped
29-
container_name: example-api
29+
container_name: ${COMPOSE_PROJECT_NAME}-api
3030
links:
3131
- database
3232
ports:
3333
- 8080:80
34-
depends_on:
35-
- database
3634
environment:
37-
DB_URL: ${DB_URL}
35+
36+
# database
37+
DB_PORT: ${DB_PORT}
38+
DB_NAME: ${DB_NAME}
39+
DB_HOST: ${DB_HOST}
3840
DB_USERNAME: ${DB_USERNAME}
3941
DB_PASSWORD: ${DB_PASSWORD}
42+
DB_SHOW_SQL: ${DB_SHOW_SQL}
43+
DB_MAX_CONNECTIONS: ${DB_MAX_CONNECTIONS}
44+
45+
# security
46+
TOKEN_SECRET: ${TOKEN_SECRET}
47+
TOKEN_EXPIRATION_IN_HOURS: ${TOKEN_EXPIRATION_IN_HOURS}
48+
REFRESH_TOKEN_EXPIRATION_IN_DAYS: ${REFRESH_TOKEN_EXPIRATION_IN_DAYS}
49+
MINUTES_TO_EXPIRE_RECOVERY_CODE: ${MINUTES_TO_EXPIRE_RECOVERY_CODE}
50+
MAX_REQUESTS_PER_MINUTE: ${MAX_REQUESTS_PER_MINUTE}
51+
52+
# smtp
53+
SMTP_HOST: ${SMTP_HOST}
54+
SMTP_PORT: ${SMTP_PORT}
55+
SMTP_USERNAME: ${SMTP_USERNAME}
56+
SMTP_PASSWORD: ${SMTP_PASSWORD}
57+
58+
# swagger
59+
SWAGGER_URL: ${SWAGGER_URL}
60+
SWAGGER_USERNAME: ${SWAGGER_USERNAME}
61+
SWAGGER_PASSWORD: ${SWAGGER_PASSWORD}
62+
networks:
63+
- spring-boot-example-network
64+
tty: true
65+
entrypoint: [
66+
"dockerize",
67+
"-wait",
68+
"tcp://database:${DB_PORT}",
69+
"-timeout",
70+
"20s",
71+
"java",
72+
"-jar",
73+
"api.jar"
74+
]
75+
76+
web:
77+
image: throyer/springboot/example-web:latest
78+
build:
79+
context: ../web
80+
dockerfile: ../web/docker/Dockerfile.prod
81+
args:
82+
- APP_API_BASE_URL=${APP_API_BASE_URL}
83+
restart: unless-stopped
84+
container_name: ${COMPOSE_PROJECT_NAME}-web
85+
ports:
86+
- "8082:80"
4087
networks:
41-
- example-api
88+
- spring-boot-example-network
4289
tty: true
43-
entrypoint: "dockerize -wait tcp://database:5432 -timeout 20s java -jar api.jar"
44-
45-
# web:
46-
# build:
47-
# context: ../web
48-
# dockerfile: ../web/docker/Dockerfile.prod
49-
# image: throyer/example-api-front-end:latest
50-
# restart: unless-stopped
51-
# container_name: example-api-front-end
52-
# ports:
53-
# - "8082:8080"
54-
# networks:
55-
# - example-api
56-
# tty: true
5790

5891
networks:
59-
example-api:
92+
spring-boot-example-network:
6093
driver: bridge

.docker/scripts/develop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
docker-compose -f .docker/docker-compose.dev.yml --env-file .docker/.env $@
2+
docker compose -f .docker/docker-compose.dev.yml --env-file .docker/.env $@

.docker/scripts/mvn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
docker-compose -f .docker/docker-compose.dev.yml --env-file .docker/.env exec -it api mvn $@
2+
docker compose -f .docker/docker-compose.dev.yml --env-file .docker/.env exec -it api mvn $@

.docker/scripts/production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
docker-compose -f .docker/docker-compose.prod.yml --env-file .docker/.env $@
2+
docker compose -f .docker/docker-compose.prod.yml --env-file .docker/.env $@

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
Vendas.iml
44
.idea
55
*.DS_Store
6+
web/.npm/

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
java openjdk-17.0.1
22
maven 3.8.4
3+
nodejs 16.17.0

.vscode/launch.json

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
{
2-
// Use o IntelliSense para saber mais sobre os atributos possíveis.
3-
// Focalizar para exibir as descrições dos atributos existentes.
4-
// Para obter mais informações, acesse: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "java",
9-
"name": "Debug (local)",
10-
"request": "launch",
11-
"mainClass": "com.github.throyer.common.springboot.Application",
12-
"cwd": "${workspaceFolder}/api"
13-
},
14-
{
15-
"type": "java",
16-
"name": "Debug (Attach Docker)",
17-
"projectName": "Vendas",
18-
"request": "attach",
19-
"hostName": "127.0.0.1",
20-
"port": 8000
21-
}
22-
]
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "java",
6+
"name": "Debug (Attach Docker)",
7+
"projectName": "Vendas",
8+
"request": "attach",
9+
"hostName": "127.0.0.1",
10+
"port": 8000
11+
},
12+
{
13+
"type": "java",
14+
"name": "Debug (local)",
15+
"request": "launch",
16+
"mainClass": "com.github.throyer.common.springboot.Application",
17+
"cwd": "${workspaceFolder}/api"
18+
}
19+
]
2320
}

0 commit comments

Comments
 (0)