Skip to content

Commit 78ad31a

Browse files
committed
chore: add docker examples
1 parent ef7d48d commit 78ad31a

File tree

8 files changed

+71
-52
lines changed

8 files changed

+71
-52
lines changed

.github/workflows/deploy-staging.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ target/
55
!**/src/test/**
66

77
### docker ###
8-
.volumes/
8+
docker/.volumes/
9+
docker/.env
910

1011
### STS ###
1112
.apt_generated

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Running a specific test](#tests)
3030
- [Swagger](#swagger)
3131
- [Database Migrations](#database-migrations)
32+
- [Docker](#docker-examples)
3233
- [Environment variables](#environment-variables)
3334

3435
# Features
@@ -114,6 +115,27 @@ Creating database migration files
114115

115116
---
116117

118+
## 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+
```
124+
125+
Building image for production
126+
```bash
127+
cd docker
128+
DOCKER_BUILDKIT=1 docker build -f Dockerfile.prod -t common-api:4.1.1 .
129+
```
130+
131+
docker compose for production
132+
```bash
133+
cd docker
134+
cp .env.example .env
135+
136+
docker-compose -p common-api -f docker-compose.prod.yml up -d
137+
```
138+
117139
## Environment variables
118140

119141
| **Description** | **Parameter** | **Default values** |
@@ -139,7 +161,7 @@ Creating database migration files
139161
> ```shell
140162
> # to change the value of some environment variable at runtime
141163
> # on execution, just pass it as a parameter. (like --SERVER_PORT=80).
142-
> $ java -jar api-4.1.0.RELEASE.jar --SERVER_PORT=80
164+
> $ java -jar api-4.1.1.RELEASE.jar --SERVER_PORT=80
143165
> ```
144166
145167

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:3306/common_app
2+
DB_USERNAME=root
3+
DB_PASSWORD=root
File renamed without changes.

docker-compose.yml renamed to docker/docker-compose.dev.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
version: '3'
22
services:
33

4-
postgresql:
4+
database:
55
image: postgres:13
66
restart: unless-stopped
7-
container_name: postgres-container
7+
container_name: common-database
88
command: ["postgres", "-c", "log_statement=all", "-c", "log_destination=stderr"]
99
ports:
1010
- "5432:5432"
1111
environment:
12-
- POSTGRES_USER=root
13-
- POSTGRES_PASSWORD=root
14-
- POSTGRES_DB=common_app
15-
- TZ=America/Sao_Paulo
16-
- PGTZ=America/Sao_Paulo
12+
POSTGRES_USER: ${DB_USERNAME}
13+
POSTGRES_PASSWORD: ${DB_PASSWORD}
14+
POSTGRES_DB: ${DB_NAME}
15+
TZ: America/Sao_Paulo
16+
PGTZ: America/Sao_Paulo
1717
volumes:
1818
- ./.volumes/database:/var/lib/postgresql/data
19-
19+
2020
api:
2121
image: maven:3.8.3
2222
restart: unless-stopped
23-
container_name: api-container
23+
container_name: common-api
2424
links:
2525
- postgresql
2626
depends_on:
@@ -29,9 +29,9 @@ services:
2929
- "8080:8080"
3030
- "8000:8000"
3131
environment:
32-
DB_URL: "postgresql:5432/common_app"
33-
DB_USERNAME: "root"
34-
DB_PASSWORD: "root"
32+
DB_URL: database:5432/${DB_NAME}
33+
DB_USERNAME: ${DB_USERNAME}
34+
DB_PASSWORD: ${DB_PASSWORD}
3535
volumes:
3636
- ./:/app
3737
- ./.volumes/maven:/root/.m2

docker/docker-compose.prod.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3'
2+
services:
3+
4+
database:
5+
image: postgres:13
6+
restart: unless-stopped
7+
container_name: common-database
8+
ports:
9+
- "5432:5432"
10+
environment:
11+
POSTGRES_USER: ${DB_USERNAME}
12+
POSTGRES_PASSWORD: ${DB_PASSWORD}
13+
POSTGRES_DB: ${DB_NAME}
14+
TZ: America/Sao_Paulo
15+
PGTZ: America/Sao_Paulo
16+
volumes:
17+
- ./.volumes/database:/var/lib/postgresql/data
18+
19+
api:
20+
image: common-api:4.1.1
21+
restart: unless-stopped
22+
container_name: common-api
23+
links:
24+
- database
25+
ports:
26+
- 8080:80
27+
environment:
28+
DB_URL: database:5432/${DB_NAME}
29+
DB_USERNAME: ${DB_USERNAME}
30+
DB_PASSWORD: ${DB_PASSWORD}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<groupId>com.github.throyer.common.spring-boot</groupId>
1111
<artifactId>api</artifactId>
12-
<version>4.1.0</version>
12+
<version>4.1.1</version>
1313
<name>CRUD API</name>
1414

1515
<description>Exemplo de api simples com Spring Boot</description>

0 commit comments

Comments
 (0)