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