Skip to content

Commit

Permalink
Added prod docker-compose with wt
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Nov 21, 2024
1 parent 87c4119 commit c877fd0
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=orservice_db
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ build/
mvnw
mvnw.cmd

postgres-data
postgres-data

### env ###
.env
13 changes: 12 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Build stage
FROM maven:3.8.4-openjdk-17-slim AS build
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn clean package -DskipTests

# Runtime stage
FROM openjdk:17-jdk-alpine
COPY target/orservice-0.0.1-SNAPSHOT.jar app-1.0.0.jar
WORKDIR /app
COPY --from=build /app/target/orservice-0.0.1-SNAPSHOT.jar app-1.0.0.jar
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "app-1.0.0.jar", "-Dspring.profiles.active=prod" ]
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,53 @@
Spring Boot REST Service to provide a REST API replacement to current Sarapis OR Service.

## To run the database
Copy the environment variables from the `.env` file.
```bash
cp .env.example .env
```

Start the db container with the following command
```bash
docker-compose up
```
In your terminal you will find the logs of the database. If you see
the following log the database has started gracefully.
```
LOG: database system is ready to accept connections
```

To shut down the container database use
```bash
docker-compose down
```

## To run the service
Build the Java service. This command will generate the application `jar` inside
the `target` directory.
```bash
mvn clean install
```
If the build is successful, then run the service
```bash
java -jar target/orservice-0.0.1-SNAPSHOT.jar
```
You will start seeing logs from the service booting up. If you see the following log
```
Started OrserviceApplication in {} seconds (process running for {})
```
the service has started successfully.

## Troubleshooting
If the db has not started successfully do the following:
1. Check that the container is running
```bash
docker ps
```
You should see all the containers running in your machine.

2. Try rebuilding the database
```bash
docker-compose down --volumes
rm -rf postgres_data
docker-compose up --build
```
46 changes: 46 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
services:
db:
container_name: orservice_db
env_file: ".env"
restart: on-failure
image: postgres:latest
ports:
- "5432:5432"
networks:
orservice:
- ipv4_address: 10.10.2.2
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./initdb:/docker-entrypoint-initdb.d
logging:
options:
max-size: "10m"
max-file: "3"
healthcheck:
test:
["CMD", "pg_isready", "-U", "${POSTGRES_USER}", "-d", "${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
wt:
image: containrrr/watchtower
labels:
- "com.centurylinklabs.watchtower.scope=orservice"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
command: --interval 30 --scope orservice

volumes:
postgres-data:

networks:
orservice:
driver: bridge
ipam:
config:
- subnet: 10.10.2.0/24
gateway: 10.10.2.1
7 changes: 4 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ services:
image: postgres:latest
ports:
- "5432:5432"
env_file: ".env"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=orservice_db
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
volumes:
- ./postgres-data:/var/lib/postgresql/data
- ./initdb:/docker-entrypoint-initdb.d
Expand Down

0 comments on commit c877fd0

Please sign in to comment.