- Java 21
- Apache Maven (3.8.7+)
- Docker
git clone git@github.com:TechAbraao/contacts.git
cd contactsCopy the example file and fill in your values:
cp .env.example .envMinimal .env example:
## POSTGRESQL ##
POSTGRES_CONTAINER_NAME=contacts_postgres
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret
POSTGRES_DB=contacts_db
## PGADMIN ##
PGADMIN_CONTAINER_NAME=contacts_pgadmin
PGADMIN_PORT=8081
PGADMIN_EMAIL=admin@example.com
PGADMIN_PASSWORD=secretUse this flow if you want to run the application directly with Maven, while the database runs in a container.
docker compose --env-file .env -f docker/compose/docker-compose-dev.yml up -dOr with Makefile (Linux/Unix):
make upCheck out more commands by typing
makein the terminal. These commands are solely for development assistance.
Since the application runs on your host machine, it connects to PostgreSQL via localhost:
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://localhost:5432/contacts_db
username: postgres
password: secret
driver-class-name: org.postgresql.Driver
security:
jwt:
secret: secret
user:
email: admin@admin.com
name: admin
password: adminmvn clean install -DskipTests
mvn spring-boot:runTo run with tests:
mvn testAPI:
http://localhost:8080/api/
Swagger UI:
http://localhost:8080/swagger-ui/index.html
Use this flow to run both the application and the database as containers.
mvn package -DskipTestsdocker build -f docker/dockerfiles/Dockerfile -t contacts .Since both services run inside Docker, the application must connect to PostgreSQL using the service name defined in docker-compose-prod.yml (postgres), not localhost:
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://postgres:5432/contacts_db
username: postgres
password: secret
driver-class-name: org.postgresql.Driver
security:
jwt:
secret: secret
user:
email: admin@admin.com
name: admin
password: adminAlternatively, you can keep
localhostinapplication.ymland override the URL via environment variable indocker-compose-prod.yml:environment: SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/contacts_db
docker compose --env-file .env -f docker/compose/docker-compose-prod.yml up -ddocker psdocker logs contacts_appAPI:
http://localhost:8080/api/
Swagger UI:
http://localhost:8080/swagger-ui/index.html