Merge "CI: Add test rtdv3 GHA workflow"
[cps.git] / docker-compose / README.md
1 <!--
2   ============LICENSE_START=======================================================
3    Copyright (C) 2020 Pantheon.tech
4    Modifications Copyright (C) 2020-2021 Nordix Foundation.
5    Modifications Copyright (C) 2021 Bell Canada.
6    Modifications Copyright (C) 2022 TechMahindra Ltd.
7   ================================================================================
8   Licensed under the Apache License, Version 2.0 (the "License");
9   you may not use this file except in compliance with the License.
10   You may obtain a copy of the License at
11
12        http://www.apache.org/licenses/LICENSE-2.0
13
14   Unless required by applicable law or agreed to in writing, software
15   distributed under the License is distributed on an "AS IS" BASIS,
16   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   See the License for the specific language governing permissions and
18   limitations under the License.
19
20   SPDX-License-Identifier: Apache-2.0
21   ============LICENSE_END=========================================================
22 -->
23
24 # Building and running CPS locally
25
26 ## Building Java Archive only
27
28 Following command builds all Java components to `cps-application/target/cps-application-x.y.z-SNAPSHOT.jar` JAR file
29 without generating any docker images:
30
31 ```bash
32 mvn clean install -Pcps-docker -Pncmp-docker -Pcps-ncmp-docker -Djib.skip
33 ```
34
35 ## Building Java Archive and Docker images
36
37 * Following command builds the JAR file and also generates the Docker image for all CPS components:
38
39 ```bash
40 mvn clean install -Pcps-docker -Pncmp-docker -Pcps-ncmp-docker
41 ```
42
43 * Following command builds the JAR file and generates the Docker image for specified CPS component:
44   (with `<docker-profile>` being one of `cps-docker`, `ncmp-docker` or `cps-ncmp-docker`):
45
46 ```bash
47 mvn clean install -P<docker-profile>
48 ```
49
50 ## Running Docker containers
51
52 `docker-compose/docker-compose.yml` file is provided to be run with `docker-compose` tool and images previously built.
53 It starts both Postgres database and CPS services.
54
55 1. Edit `docker-compose.yml`
56    1. uncomment desired service to be deployed, by default `cps-and-ncmp` is enabled. You can comment it and uncomment `cps-standalone` or `ncmp-standalone`.
57    2. To send data-updated events to kafka,
58       * uncomment the `zookeeper` and `kafka` services.
59       * uncomment environment variables
60         * `notification.data-updated.enabled: 'true'`
61         * `KAFKA_BOOTSTRAP_SERVER: kafka:9092`
62         * `NOTIFICATION_DATASPACE_FILTER_PATTERNS: '.*'`
63 2. Execute following command from `docker-compose` folder:
64
65 Use one of the below version type that has been generated in the local system's docker image list after the build.
66 ```bash
67 VERSION=latest DB_USERNAME=cps DB_PASSWORD=cps docker-compose up -d
68 or
69 VERSION=<version> DB_USERNAME=cps DB_PASSWORD=cps docker-compose up -d
70 ```
71
72 ## Running or debugging Java built code
73
74 Before running CPS, a Postgres database instance needs to be started. This can be done with following
75 command:
76
77 ```bash
78 docker run --name postgres -p 5432:5432 -d \
79   -e POSTGRES_DB=cpsdb -e POSTGRES_USER=cps -e POSTGRES_PASSWORD=cps \
80   postgres:12.4-alpine
81 ```
82
83 Then CPS can be started either using a Java Archive previously built or directly from Intellij IDE.
84
85 ### Running from Jar Archive
86
87 Following command starts the application using JAR file:
88
89 ```bash
90 DB_HOST=localhost DB_USERNAME=cps DB_PASSWORD=cps CPS_USERNAME=cpsuser CPS_PASSWORD=cpsr0cks! \
91   DMI_USERNAME=cpsuser DMI_PASSWORD=cpsr0cks! \
92   java -jar cps-application/target/cps-application-x.y.z-SNAPSHOT.jar
93 ```
94
95 ### Running from IntelliJ IDE
96
97 Here are the steps to run or debug the application from Intellij:
98
99 1. Enable the desired maven profile form Maven Tool Window
100 2. Run a configuration from `Run -> Edit configurations` with following settings:
101    * `Environment variables`: `DB_HOST=localhost;DB_USERNAME=cps;DB_PASSWORD=cps
102                                 CPS_USERNAME=cpsuser CPS_PASSWORD=cpsr0cks!
103                                 DMI_USERNAME=cpsuser DMI_PASSWORD=cpsr0cks!`
104
105 ## Accessing services
106
107 Swagger UI and Open API specifications are available to discover service endpoints and send requests.
108
109 * `http://localhost:<port-number>/swagger-ui.html`
110 * `http://localhost:<port-number>/api-docs/cps-core/openapi.yaml`
111 * `http://localhost:<port-number>/api-docs/cps-ncmp/openapi.yaml`
112 * `http://localhost:<port-number>/api-docs/cps-ncmp/openapi-inventory.yaml`
113
114 with <port-number> being either `8080` if running the plain Java build or retrieved using following command
115 if running from `docker-compose`:
116
117 ```bash
118 docker inspect \
119   --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' \
120   <cps-docker-container>
121 ```
122
123 Enjoy CPS !