0a38283535a9d203acad5795bdfb53120d7c855f
[cps.git] / docker-compose / README.md
1 # Building and running CPS locally
2
3 ## Building Java Archive only
4
5 Following command builds all Java components to `cps-application/target/cps-application-x.y.z-SNAPSHOT.jar` JAR file
6 without generating any docker images:  
7
8 ```bash
9 mvn clean install -Pcps-docker -Pxnf-docker -Pcps-xnf-docker -Djib.skip
10 ```
11
12 ## Building Java Archive and Docker images
13
14 * Following command builds the JAR file and also generates the Docker image for all CPS components:
15
16 ```bash
17 mvn clean install -Pcps-docker -Pxnf-docker -Pcps-xnf-docker -Dnexus.repository=
18 ```
19
20 * Following command builds the JAR file and generates the Docker image for specified CPS component:
21   (with `<docker-profile>` being one of `cps-docker`, `xnf-docker` or `cps-xnf-docker`):
22
23 ```bash
24 mvn clean install -P<docker-profile> -Dnexus.repository=
25 ```
26
27 ## Running Docker containers
28
29 `docker-compose/docker-compose.yml` file is provided to be run with `docker-compose` tool and images previously built.
30 It starts both Postgres database and CPS services.
31
32 1. Edit `docker-compose.yml` and uncomment desired service to be deployed, by default `cps-and-nf-proxy`
33    is enabled. You can comment it and uncomment `cps-standalone` or `nf-proxy-standalone`.
34 2. Execute following command from `docker-compose` folder:
35
36 ```bash
37 VERSION=x.y.z-SNAPSHOT DB_HOST=dbpostgresql DB_USERNAME=cps DB_PASSWORD=cps docker-compose up -d
38 ```
39
40 ## Running or debugging Java built code
41
42 Before running CPS, a Postgres database instance needs to be started. This can be done with following
43 command:
44
45 ```bash
46 docker run --name postgres -p 5432:5432 -d \
47   -e POSTGRES_DB=cpsdb -e POSTGRES_USER=cps -e POSTGRES_PASSWORD=cps \
48   postgres:12.4-alpine
49 ```
50
51 Then CPS can be started either using a Java Archive previously built or directly from Intellij IDE.
52
53 ### Running from Jar Archive
54
55 Following command starts the application using JAR file:
56
57 ```bash
58 DB_HOST=localhost DB_USERNAME=cps DB_PASSWORD=cps \
59   java -classpath cps-application/target/cps-application-x.y.z-SNAPSHOT.jar:docker-compose \
60   org.springframework.boot.loader.JarLauncher
61 ```
62
63 ### Running from IntelliJ IDE
64
65 Here are the steps to run or debug the application from Intellij:
66
67 1. Enable the desired maven profile form Maven Tool Window
68 2. Run a configuration from `Run -> Edit configurations` with following settings:
69    * `Working directory`: docker-compose folder, e.g. `$ProjectFileDir$/docker-compose`
70    * `Environment variables`: `DB_HOST=localhost;DB_USERNAME=cps;DB_PASSWORD=cps`
71
72 ## Accessing services
73
74 Swagger UI and Open API specifications are available to discover service endpoints and send requests.
75
76 * `http://localhost:<port-number>/swagger-ui/index.html`
77 * `http://localhost:<port-number>/v3/api-docs?group=cps-docket`
78
79 with <port-number> being either `8080` if running the plain Java build or retrieved using following command
80 if running from `docker-compose`:
81
82 ```bash
83 docker inspect \
84   --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' \
85   <cps-docker-container>
86 ```
87
88 Enjoy CPS !