Skip to content

Commit

Permalink
Merge pull request #4 from smartSenseSolutions/fix/stable-application
Browse files Browse the repository at this point in the history
Code changes as per upstream PR review
  • Loading branch information
nitin-vavdiya authored May 16, 2024
2 parents 5dae4a2 + 43b1df6 commit b3a7dbc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
4 changes: 0 additions & 4 deletions demand-capacity-mgmt-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
public class DemandCapacityMgmtBackendApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spring:
issuer-uri: ${keycloak.baseUrl}/realms/${keycloak.realm}

datasource:
url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:15432}/${DCM_DATASOURCE_NAME:dcm}
url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dcm}
username: ${DCM_DATASOURCE_USER:dcm}
password: ${DCM_DATASOURCE_PASS:dcm}
driverClassName: org.postgresql.Driver
Expand All @@ -47,7 +47,7 @@ spring:

flyway:
enabled: true
url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:15432}/${DCM_DATASOURCE_NAME:dcm}
url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dcm}
user: ${DCM_DATASOURCE_USER:dcm}
password: ${DCM_DATASOURCE_PASS:dcm}
schemas: migrations
Expand Down
3 changes: 2 additions & 1 deletion dev/create_keycloak_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE auth;
SELECT 'CREATE DATABASE auth'
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'auth')\gexec
EOSQL
48 changes: 16 additions & 32 deletions docs/Local Development Install.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,43 +83,27 @@ Let's begin local development install!

![Docker Desktop](images/dev/3.png "Docker install")
</details>
- ### Running containers

with docker running open a command terminal

docker pull postgres:16.1

this will download the postgres image, then you need to configure postgres

docker run -d --name dcmfPostgres -p 5432:5432 -e POSTGRES_PASSWORD=dcm -e POSTGRES_USER=dcm postgres

choose your own credentials of course, please **do not** use credentails shown on the guide.
now connect to postgres DB either through your IDE or PGADMIN4

![Docker desktop postgres container](images/dev/4.png "Docker postgres")

![Postgres connection](images/dev/5.png "Docker postgres connection")

- ### Running project first time for init configs
execute all flyaway scripts on the postgres dcm schema.
and create a keycloak schema (for later use by keycloak)
. Run the project.
and
when you see "Completed initialization in 1ms" stop the project.

- ### Running Keycloak
open a new cmd file and run

docker run -p 8888:8080 -e KEYCLOAK_ADMIN=YourAdminName -e KEYCLOAK_ADMIN_PASSWORD=YourAdminPassword quay.io/keycloak/keycloak:23.0.6 start-dev
- ### Running containers

Next go to docker and follow the link on the keycloak container.

Login with admin credentials, under realms, click create new realm
import the realm-export.json on the keycloak folder.
This project includes integrated support for Spring Boot Docker Compose, facilitating the setup of Keycloak and PostgreSQL without manual intervention.

You won't need to manually start containers or configure settings. The application will reference the `compose.yaml` file located at the root of the project.

Feel free to adjust configurations (such as ports and credentials) in the `compose.yaml` file to suit your requirements.

When the application starts, it automatically creates a PostgreSQL container with the provided environment credentials. Additionally, a new database for Keycloak is set up.

![Postgres connection](images/dev/5.png "Docker postgres connection")
On startup, the application also creates a Keycloak container based on the configurations in the Compose file. Initial configurations, including the creation of realms, clients, and users, are performed using the `dcm_realm.json` file.

![Docker desktop running containers](images/dev/11.png)

Further you can login with keycloak admin credentials configured in `compose.yaml` and modify users to you heart's content(under the users tabs, credentials for them, assing roles, etc)

Ref: https://spring.io/blog/2023/06/21/docker-compose-support-in-spring-boot-3-1

Modify users to you heart's content(under the users tabs, credentials for them, assing roles, etc).
Further you can login with keycloak admin credentials configured in compose.yaml and modify users to you heart's content(under the users tabs, credentials for them, assing roles, etc)

**Remember you need to have a user role on all users, it can be ADMIN, CUSTOMER, SUPPLIER**
failing to have one of these roles won't let the user login in the app.
Expand Down
Binary file added docs/images/dev/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b3a7dbc

Please sign in to comment.