Skip to content

Commit 8d2d3cc

Browse files
committed
optimize docker commands and enviroment
1 parent f490746 commit 8d2d3cc

File tree

7 files changed

+150
-21
lines changed

7 files changed

+150
-21
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker/.env
2+
docker/.volumes
3+
Vendas.iml
4+
.idea

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> [🐬 MySQL/MariaDB implementation](https://github.com/Throyer/springboot-api-crud/tree/mariadb#readme)
44
55
<p align="center">
6-
<a href="https://github.com/Throyer" target="blank"><img src="./assets/tecnologias.png" width="560" alt="Tecnologias" /></a>
6+
<a href="https://github.com/Throyer" target="blank"><img src="./assets/images/tecnologias.png" width="560" alt="Tecnologias" /></a>
77
</p>
88

99
<h1 align="center">Spring Boot API RESTful</h1>
@@ -17,7 +17,7 @@
1717
[**Live demo on heroku**](https://throyer-crud-api.herokuapp.com)
1818

1919
<p align="center">
20-
<a href="https://throyer-crud-api.herokuapp.com" target="blank"><img src="./assets/demo.gif" alt="Demonstration" /></a>
20+
<a href="https://throyer-crud-api.herokuapp.com" target="blank"><img src="./assets/images/demo.gif" alt="Demonstration" /></a>
2121
</p>
2222

2323
## Table of Contents
@@ -35,7 +35,7 @@
3535
# Features
3636

3737
<p align="center">
38-
<a href="https://throyer-crud-api.herokuapp.com" target="blank"><img src="./assets/features.png" alt="Tecnologias" /></a>
38+
<a href="https://throyer-crud-api.herokuapp.com" target="blank"><img src="./assets/images/features.png" alt="Tecnologias" /></a>
3939
</p>
4040

4141

@@ -51,10 +51,10 @@ This project was started with [Spring Initializr](https://start.spring.io/#!type
5151
## Entities
5252

5353
<p>
54-
<img src="./database_diagram/spring_boot_crud_database_diagram.png" alt="database diagram" />
54+
<img src="./assets/database/diagram.png" alt="database diagram" />
5555
</p>
5656

57-
>[🚨 draw.io file here](./der/spring_boot_crud_database_diagram.drawio)
57+
>[🚨 draw.io file here](./assets/database/diagram.drawio)
5858
5959
## Installation
6060

@@ -103,6 +103,10 @@ Once the application is up, it is available at: [localhost:8080/documentation](l
103103
## Database Migrations
104104
Creating database migration files
105105

106+
> 🚨 make sure you have maven in your environment
107+
and that you are in the correct directory __./api__
108+
109+
106110
- Java based migrations
107111
```bash
108112
mvn migration:generate -Dname=my-migration-name
@@ -116,25 +120,23 @@ Creating database migration files
116120
---
117121

118122
## Docker examples
119-
docker compose for development
120-
```bash
121-
cd docker
122-
docker-compose -p common-api-development -f docker-compose.dev.yml up -d
123-
```
124123

125-
Building image for production
126-
```bash
127-
cd docker
128-
DOCKER_BUILDKIT=1 docker build -f Dockerfile.prod -t common-api:4.1.2 ../
129-
```
124+
> 🚨 create `environment` file
125+
>
126+
> ```bash
127+
> cp docker/.env.example docker/.env
128+
> ```
130129
131-
docker compose for production
132-
```bash
133-
cd docker
134-
cp .env.example .env
130+
- docker compose development
131+
```bash
132+
docker-compose -p example-api-development -f ./docker/docker-compose.dev.yml --env-file ./docker/.env up -d --force-recreate
133+
```
134+
135+
- docker compose production
136+
```bash
137+
docker-compose -p example-api -f ./docker/docker-compose.prod.yml --env-file ./docker/.env up -d --build
138+
```
135139
136-
docker-compose -p common-api -f docker-compose.prod.yml up -d
137-
```
138140
139141
## Environment variables
140142

api/database_diagram/spring_boot_crud_database_diagram.drawio renamed to assets/database/diagram.drawio

File renamed without changes.

api/database_diagram/spring_boot_crud_database_diagram.png renamed to assets/database/diagram.png

File renamed without changes.

docker/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DB_URL=database:5432/example_api
2+
DB_USERNAME=root
3+
DB_PASSWORD=root

docker/docker-compose.dev.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
version: '3'
2+
services:
3+
4+
database:
5+
image: postgres:13
6+
restart: unless-stopped
7+
container_name: example-api-database
8+
command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"]
9+
ports:
10+
- "5432:5432"
11+
environment:
12+
POSTGRES_USER: ${DB_USERNAME}
13+
POSTGRES_PASSWORD: ${DB_PASSWORD}
14+
POSTGRES_DB: example_api
15+
TZ: America/Sao_Paulo
16+
PGTZ: America/Sao_Paulo
17+
volumes:
18+
- ./.volumes/database:/var/lib/postgresql/data
19+
networks:
20+
- example-api
21+
tty: true
22+
23+
api:
24+
image: maven:3.8.5-openjdk-17
25+
restart: unless-stopped
26+
container_name: example-api-development
27+
links:
28+
- database
29+
ports:
30+
- "8080:8080"
31+
- "8000:8000"
32+
environment:
33+
DB_URL: ${DB_URL}
34+
DB_USERNAME: ${DB_USERNAME}
35+
DB_PASSWORD: ${DB_PASSWORD}
36+
volumes:
37+
- ../api:/app
38+
- ./.volumes/maven:/root/.m2
39+
working_dir: /app
40+
networks:
41+
- example-api
42+
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"
58+
59+
networks:
60+
example-api:
61+
driver: bridge

docker/docker-compose.prod.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: '3'
2+
services:
3+
4+
database:
5+
image: postgres:13
6+
restart: unless-stopped
7+
container_name: example-api-database
8+
ports:
9+
- "5432:5432"
10+
environment:
11+
POSTGRES_USER: ${DB_USERNAME}
12+
POSTGRES_PASSWORD: ${DB_PASSWORD}
13+
POSTGRES_DB: example_api
14+
TZ: America/Sao_Paulo
15+
PGTZ: America/Sao_Paulo
16+
volumes:
17+
- ./.volumes/database:/var/lib/postgresql/data
18+
networks:
19+
- example-api
20+
tty: true
21+
22+
api:
23+
build:
24+
context: ../api
25+
dockerfile: ../api/docker/Dockerfile.prod
26+
image: throyer/example-api:latest
27+
restart: unless-stopped
28+
container_name: example-api
29+
links:
30+
- database
31+
ports:
32+
- 8080:80
33+
depends_on:
34+
- database
35+
environment:
36+
DB_URL: ${DB_URL}
37+
DB_USERNAME: ${DB_USERNAME}
38+
DB_PASSWORD: ${DB_PASSWORD}
39+
networks:
40+
- example-api
41+
tty: true
42+
entrypoint: "dockerize -wait tcp://database:5432 -timeout 20s java -jar api.jar"
43+
44+
# web:
45+
# build:
46+
# context: ../web
47+
# dockerfile: ../web/docker/Dockerfile.prod
48+
# image: throyer/example-api-front-end:latest
49+
# restart: unless-stopped
50+
# container_name: example-api-front-end
51+
# ports:
52+
# - "8082:8080"
53+
# networks:
54+
# - example-api
55+
# tty: true
56+
57+
networks:
58+
example-api:
59+
driver: bridge

0 commit comments

Comments
 (0)