Skip to content

Commit

Permalink
Feat #3: env and docker optimization
Browse files Browse the repository at this point in the history
- Better environment variable management
- Healthchecks in docker
- Better documentation
  • Loading branch information
fjlopez committed Jul 15, 2024
1 parent 394c3c2 commit d7bb883
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 156 deletions.
18 changes: 18 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Uncomment the following line to change the default port. 9000 is the default port.
# SERVICE_PORT=9000

# Uncomment the following line to change the default database URL. The default URL points to the persistence service.
# The JDBC URL is composed by the concatenation of DATABASE_URL and DATABASE.
# DATABASE_URL=jdbc:postgresql://persistence:5432/

# Uncomment the following line to change the default database name. The default database name is "sitmun3".
# DATABASE=sitmun3

# Uncomment the following line to change the default database username. The default username is "sitmun3".
# DATABASE_USERNAME=sitmun3

# Uncomment the following line to change the default database password. The default password is "sitmun3".
# DATABASE_PASSWORD=sitmun3

# Uncomment the following line to change the forced use of the proxy. Enabled by default for testing purposes.
# FORCE_USE_OF_PROXY=true
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
*.iml
.idea

# Ignore environment files
.env

# Other files to be ignored
*.properties
*.jar
Expand Down
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ The **SITMUN Application Stack** is an example of how to deploy SITMUN as a mult

Before you begin, ensure you have met the following requirements:

- A `Windows/Linux/Mac` machine.
- Installed the latest version of [Docker CE](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/), or [Docker Desktop](https://www.docker.com/products/docker-desktop/).
Docker CE is fully open-source, while Docker Desktop is a commercial product.
- Installed [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) on your machine.
- Basic understanding of Docker, Docker Compose, and Git.
- A `Windows/Mac/Linux` machine.
- Installed the latest version of `Docker`. Installation scenarios:
- Scenario one: Install [Docker Engine](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/install/).
- Scenario two: Install [Docker Desktop](https://docs.docker.com/desktop/) (one-click-install commercial product), which includes `Docker Engine` and `Docker Compose.
- Installed Git. See [Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
- Internet access to pull Docker images and Git repositories.

## Installing SITMUN Application Stack
Expand Down Expand Up @@ -46,26 +46,40 @@ To install the SITMUN Application Stack, follow these steps:
docker compose up -d
```

## Docker Compose Configuration
## Available services

| Application | URL |
|----------------------------|------------------------------------------------------------------|
| Viewer application | <http://localhost:9000/viewer> |
| Administrative application | <http://localhost:9000/admin> |
| Backend API | <http://localhost:9000/backend/> and <http://localhost:9001/> |
| Proxy Middleware API | <http://localhost:9000/middleware/> and <http://localhost:9002/> |
|

## Configuration Notes

The SITMUN Application Stack uses Docker Compose to define the services, specified in the `docker-compose.yml` file.

### Available services
Data is stored in the `pgdata` volume, which is used by the `postgres` service.

- `front`: SITMUN front-end services
- `viewer`: SITMUN viewer application at <http://localhost:9000/viewer>
- `admin`: SITMUN administrative application at <http://localhost:9000/admin>
- Also, it acts as reverse proxy for `backend` and `proxy` services at <http://localhost:9000/backend/> and <http://localhost:9000/middleware/> endpoints respectively.
- `backend`: SITMUN API at [http://localhost:9001/](http://localhost:9001/)
- `proxy`: SITMUN proxy at [http://localhost:9002/](http://localhost:9002/)
Environment variables are defined in the `.env` file. The following variables can be modified.

### Configuration Notes
| Variable | Description | Default value |
|----------------------|------------------------------------------|---------------------------------------|
| `SERVICE_PORT` | The port where the services are exposed. | `9000` |
| `DATABASE` | The name of the database. | `sitmun3` |
| `DATABASE_URL` | The JDBC URL of the database. | `jdbc:postgresql://persistence:5432/` |
| `DATABASE_USERNAME` | The username to access the database. | `sitmun3` |
| `DATABASE_PASSWORD` | The password to access the database. | `sitmun3` |
| `FORCE_USE_OF_PROXY` | Forces the use of the proxy middleware. | `true` |

For testing purposes, the use of the `proxy` is controlled by the `SITMUN_PROXY_FORCE` environment variable in `backend`, which by default is `true`.
Notes:

Data is stored in the `pgdata` volume, which is used by the `postgres` service.
- The default value of `DATABASE_URL` points to `persistence`, which is one of the services defined in the `docker-compose.yml` file. It is a PostgreSQL database.
- The effective JDBC URL is composed by the concatenation of `DATABASE_URL` and `DATABASE`.
- `FORCE_USE_OF_PROXY` is enabled by default for testing purposes.

## Working with submodules
## Developing SITMUN

SITMUN Application Stack uses Git submodules to include the source code of the SITMUN viewer and administrative applications, the SITMUN Backend and the SITMUN Proxy middleware.

Expand All @@ -76,14 +90,12 @@ SITMUN Application Stack uses Git submodules to include the source code of the S
| `sitmun-backend-core` | [SITMUN Backend](https://github.com/sitmun/sitmun-backend-core.git) | `backend` |
| `sitmun-proxy-middleware` | [SITMUN Proxy middleware](https://github.com/sitmun/sitmun-proxy-middleware.git) | `proxy` |

### Changing Submodule Branches

To change the branch of a submodule, use the following command:

```bash
git submodule set-branch -b branch_name submodule_name
git submodule sync
git submodule update --init submodule_name
git submodule update --init
```

The update command updates the registered submodule to match the expected configuration by cloning it if missing, fetching missing commits and updating the working tree to the specified branch.
Expand All @@ -95,13 +107,6 @@ docker compose build --no-cache service_name
docker compose up service_name -d
```

## Uninstalling SITMUN Application Stack

To stop and remove all services, volumes, and networks defined in the `docker-compose.yml` file, use:
```bash
docker compose down -v
```

## Contributing to SITMUN Application Stack

To contribute to SITMUN Application Stack, follow these steps:
Expand Down
2 changes: 2 additions & 0 deletions back/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ RUN --mount=type=cache,target=/root/.gradle ./gradlew --no-daemon -i stage

# Stage 1, based on OpenJDK, to have only the compiled app, ready for production with Nginx
FROM openjdk:11-jre-slim-buster
RUN apt-get update && apt-get install -y curl
COPY --from=build-backend-core /usr/src/sitmun-backend-core/deploy/heroku-dev-full/build/libs/*.jar /usr/src/sitmun.jar
WORKDIR /usr/src
ENTRYPOINT ["java", "-jar", "sitmun.jar"]
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl --fail http://localhost:8080/api/dashboard/health || exit 1
80 changes: 0 additions & 80 deletions back/backend/config/application-dev.yml

This file was deleted.

134 changes: 100 additions & 34 deletions back/backend/config/application.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,64 @@
# =====================================================================================================================
# Spring Boot configuration.
#
# This configuration will be overridden by the Spring profile you use,
# for example application-dev.yml if you use the "dev" profile.
#
# Full reference is available at:
# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# =====================================================================================================================
# ===================================================================
# SITMUN specific properties
# ===================================================================

sitmun:
module: SITMUN Core
version: 3.0-SNAPSHOT
proxy:
config-response-validity-in-seconds: 3600
dashboard:
fetchMetrics: 60000
initialDelay: 60000
cartographies-by-created-date.size: 30 #last days
users-by-created-date.size: 30 # last days
users-per-application.size: 30 # last days

# ===================================================================
# Logging
# ===================================================================

logging:
level:
ROOT: INFO
org.sitmun.plugin.core: INFO
liquibase: TRACE
java:
util:
logging:
manager: org.apache.logging.log4j.jul.LogManager
log4j2:
disable:
jmx: true
liquibase:
sql:
logLevel: DEBUG

# ===================================================================
# Management
# ===================================================================

management:
metrics:
enable:
all: false
sitmun: true
endpoints:
web:
base-path: /api/dashboard
exposure:
include: "health"
health:
ldap:
enabled: false

# ===================================================================
# Spring Boot
# ===================================================================

spring:
application:
name: SITMUN
profiles:
# The commented value for `active` can be replaced with valid Spring profiles to load.
# Otherwise, it will be filled in by gradle when building the JAR file
# Either way, it can be overridden by `--spring.profiles.active` value passed in the commandline or
#`-Dspring.profiles.active` set in `JAVA_OPTS`
active: dev
jmx:
enabled: false
data:
Expand All @@ -28,32 +70,45 @@ spring:
max-page-size: 100000
jackson:
serialization:
indent-output: true
fail_on_empty_beans: false
datasource:
type: com.zaxxer.hikari.HikariDataSource
hikari:
poolName: Hikari
auto-commit: false
h2:
console:
enabled: false
jpa:
show-sql: false
hibernate:
use-new-id-generator-mappings: true
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
properties:
hibernate.dialect: org.sitmun.infrastructure.persistence.dialect.PostgresSQL93DialectFixed
hibernate.jdbc.time_zone: UTC
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
# modify batch size as necessary
hibernate.jdbc.batch_size: 25
hibernate.order_inserts: true
hibernate.order_updates: true
# modify fetch size as necessary
hibernate.jdbc.fetch_size: 150
hibernate.criteria.literal_handling_mode: BIND
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
# Disable Hibernate validation to avoid double validation
javax.persistence.validation.mode: none
hibernate:
use-new-id-generator-mappings: true
ddl-auto: none
naming:
physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
liquibase:
change-log: file:/usr/src/config/liquibase/master.xml
contexts: dev
run-async: true
sync-legacy: true
main:
allow-bean-definition-overriding: true
task:
Expand All @@ -68,19 +123,30 @@ spring:
pool:
size: 2

# ===================================================================
# Security
# ===================================================================

security:
authentication:
jwt:
secret: 9ef80c644166846897f6a87d3cf6ab204d144229
token-validity-in-miliseconds: 36000000
ldap:
host: ldap://localhost:1389
base_dn: dc=example,dc=com
user_dn_pattern: uid={0}
user_ldap: cn=admin
password_ldap: admin

# ===================================================================
# Server
# ===================================================================

server:
port: 8080
forward-headers-strategy: framework
servlet:
session:
cookie:
http-only: true

# ===================================================================
# SITMUN specific properties
# ===================================================================

sitmun:
module: SITMUN Core
version: 3.0-SNAPSHOT
proxy:
config-response-validity-in-seconds: 3600
Loading

0 comments on commit d7bb883

Please sign in to comment.