Skip to content

Commit c4fb600

Browse files
committed
add docker detail
1 parent e5a9a49 commit c4fb600

File tree

6 files changed

+108
-53
lines changed

6 files changed

+108
-53
lines changed

Java/.env.example

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
# Core Credentials
2-
RTO_USER=RTO_USER
3-
RTO_PASSWORD=RTO_PASSWORD
4-
RTO_APP_KEY=RTO_APP_KEY
5-
RTO_SERVICE=ELEKTRON_DD
6-
7-
#WebSocketAPI
8-
RTO_WS_PORT=443
9-
RTO_WS_APP_ID=256
1+
# RTO Credentials
2+
RTO_USER=
3+
RTO_PASSWORD=
4+
RTO_APP_KEY=
5+
# If you do not need to change password, do not input this RTO_WS_NEW_PASSWORD configuration
106
RTO_WS_NEW_PASSWORD=
11-
RTO_WS_AUTH_URL=https://api.refinitiv.com:443/auth/oauth2/v1/token
12-
RTO_WS_DISCOVERY_URL=https://api.refinitiv.com/streaming/pricing/v1/
13-
RTO_WS_POSITION=443
147

15-
#EMA Java
16-
RTO_WS_RDMFIELDDICTIONARY=./etc/RDMFieldDictionary
17-
RTO_WS_ENUMTYPEDEF=./etc/enumtype.def
18-
RTO_PROXY_HOSTNAME=
19-
RTO_PROXY_PORT=
20-
RTO_PROXY_USERNAME=
21-
RTO_PROXY_PASSWORD=
22-
RTO_PROXY_DOMAIN=
23-
RTO_PROXY_KRB5=
8+
# RDP-RTO Core Configurations
9+
RTO_WS_PORT=443
10+
RDP_BASE_URL=https://api.refinitiv.com
11+
RDP_AUTH_URL=/auth/oauth2/v1/token
12+
RDP_DISCOVERY_URL=/streaming/pricing/v1/

Java/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ COPY pom.xml .
66
RUN mvn -e -B dependency:resolve
77
COPY src ./src
88
# Build and compile application
9-
RUN mvn clean -e -B package
9+
#RUN mvn clean -e -B package
10+
RUN mvn clean -e -B compile assembly:single
1011

1112
# Run stage
1213
FROM openjdk:11-jre-slim

Java/pom.xml

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,27 @@
4848
<build>
4949
<plugins>
5050
<plugin>
51-
<groupId>org.apache.maven.plugins</groupId>
5251
<artifactId>maven-assembly-plugin</artifactId>
52+
<configuration>
53+
<archive>
54+
<manifest>
55+
<mainClass>com.refinitiv.ws.cloud.MarketPriceRdpGwServiceDiscovery</mainClass>
56+
</manifest>
57+
</archive>
58+
<descriptorRefs>
59+
<descriptorRef>jar-with-dependencies</descriptorRef>
60+
</descriptorRefs>
61+
</configuration>
5362
<executions>
54-
<execution>
55-
<phase>package</phase>
56-
<goals>
57-
<goal>single</goal>
58-
</goals>
59-
<configuration>
60-
<archive>
61-
<manifest>
62-
<mainClass>
63-
<!--com.refinitiv.ema.test.TestENV-->
64-
com.refinitiv.ws.cloud.MarketPriceRdpGwServiceDiscovery
65-
</mainClass>
66-
</manifest>
67-
</archive>
68-
<descriptorRefs>
69-
<descriptorRef>jar-with-dependencies</descriptorRef>
70-
</descriptorRefs>
71-
</configuration>
72-
</execution>
63+
<execution>
64+
<id>make-assembly</id> <!-- this is used for inheritance merges -->
65+
<phase>package</phase> <!-- bind to the packaging phase -->
66+
<goals>
67+
<goal>single</goal>
68+
</goals>
69+
</execution>
7370
</executions>
74-
</plugin>
71+
</plugin>
7572
</plugins>
7673
</build>
7774

Python/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ RDP_PASSWORD=
44
RDP_APP_KEY=
55

66
# RDP Core Endpoints
7-
RDP_BASE_URL= https://api.refinitiv.com
7+
RDP_BASE_URL=https://api.refinitiv.com
88
RDP_AUTH_URL=/auth/oauth2/v1/token
99
RDP_ESG_URL=/data/environmental-social-governance/v2/views/scores-full

Python/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ RUN pip install --user -r requirements.txt
1111
FROM python:3.8.11-slim
1212
WORKDIR /app
1313

14-
# Set Python buffer to make Docker print every messages instantly.
15-
ENV PYTHONUNBUFFERED=1
14+
# Update PATH environment variable + set Python buffer to make Docker print every messages instantly.
15+
ENV PATH=/root/.local:$PATH \
16+
USERNAME=DOCKER_CONTAINER \
17+
PYTHONUNBUFFERED=1
1618

1719
# copy only the dependencies installation from the 1st stage image
1820
COPY --from=builder /root/.local /root/.local
1921
COPY rdp_apis_console.py .
2022

21-
# update PATH environment variable
22-
ENV PATH=/root/.local:$PATH
23-
ENV USERNAME=DOCKER_CONTAINER
24-
2523
#Run Python
2624
ENTRYPOINT [ "python", "./rdp_apis_console.py" ]

README.md

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Please note that you *do not* need the ```""``` or ```''``` characters for a str
6060

6161
### Caution
6262

63-
You *should not* share this ```.env``` file to your peers or commit/push it to the version control. You should add the file to the ```.gitignore``` file to avoid adding it to a version control or public repo accidentally.
63+
You *should not* share this ```.env``` file to your peers or commit/push it to the version control. You should add the file to the ```.gitignore``` file to avoid adding it to a version control or public repository accidentally.
6464

6565
You can create a ```.env.example``` file as a template for environment variables and ```.env``` file sharing. The file has the same parameters' keys as a ```.env``` file but without sensitive values as the following example:
6666

@@ -115,7 +115,7 @@ RDP_PASSWORD=<Your RDP password>
115115
RDP_APP_KEY=<Your RDP appkey>
116116
117117
# RDP Core Endpoints
118-
RDP_BASE_URL = https://api.refinitiv.com
118+
RDP_BASE_URL=https://api.refinitiv.com
119119
RDP_AUTH_URL=/auth/oauth2/v1/token
120120
RDP_ESG_URL=/data/environmental-social-governance/v2/views/scores-full
121121
```
@@ -249,7 +249,7 @@ RTO_PASSWORD=<Your RTO password>
249249
RTO_APP_KEY=<Your RTO appkey>
250250
251251
# RDP-RTO Core Endpoints
252-
RDP_BASE_URL = https://api.refinitiv.com
252+
RDP_BASE_URL=https://api.refinitiv.com
253253
RDP_AUTH_URL=/auth/oauth2/v1/token
254254
RDP_DISCOVERY_URL=/streaming/pricing/v1/
255255
RTO_WS_PORT=443
@@ -287,6 +287,76 @@ discoveryUrl = baseUrl + dotenv.get("RDP_DISCOVERY_URL");
287287
```
288288
Next, the application uses those configurations to authenticate with RDP Auth Service, get the RTO WebSocket endpoint dynamically from the Service Discovery mechanism and further connects and consume the real-time streaming data from the WebSocket server.
289289

290+
## dotenv with Docker
291+
292+
[Docker](https://www.docker.com/) supports the environment variables usage in the [Dockerfile](https://docs.docker.com/engine/reference/builder/#env), [docker run command](https://docs.docker.com/engine/reference/commandline/run/) and [Docker compose](https://docs.docker.com/compose/environment-variables/).
293+
294+
### dotenv with Dockerfile
295+
296+
#### Dockerfile ENV instruction
297+
298+
Let's demonstrate with the Dockerfile first. You can use the ```ENV``` instruction to set the environment variable in the image.
299+
300+
```
301+
ENV <key>=<value> ...
302+
```
303+
You can set multiple environment variables in a single ```ENV``` instruction as well.
304+
305+
```
306+
ENV <key>=<value> \
307+
<key>=<value> \
308+
<key>=<value>
309+
```
310+
311+
The Dockerfile below set both application and System's configurations in the Dockerfile.
312+
313+
```
314+
# Update PATH environment variable + set Python buffer to make Docker print every messages instantly.
315+
ENV PATH=/root/.local:$PATH \
316+
USERNAME=DOCKER_CONTAINER \
317+
PYTHONUNBUFFERED=1
318+
```
319+
All containers from the result image can access the environment variables set using Dockerfile ```ENV``` instruction, unless it is replaced by the Docker run command options.
320+
321+
When you run the Docker containers from the above Docker image setting, the ```System.out.println(dotenv.get("USERNAME"));``` (Java) and ``` print('User: ', os.getenv('USERNAME'))``` (Python) will print the USERNAME information as *DOCKER_CONTAINER*.
322+
323+
#### Docker Run command
324+
325+
You can use the ```--env``` (```-e``` for shorter syntax) options with the Docker run command to set the environment variable of the container.
326+
327+
```
328+
$> docker run --env <key>=<value> IMAGE
329+
```
330+
331+
Please note that if you want to set multiple environment variables, you need to set ```--env```` multiple times
332+
333+
```
334+
$> docker run --env USERNAME=DOCKER_CONTAINER_RUN --env RDP_USER=USER1 --env RDP_PASSWORD=PASSWORD --env RDP_APP_KEY=APP_KEY IMAGE
335+
```
336+
Alternatively, you can use the ```--env-file``` option to parse a file of environment variables (```.env``` file) to Docker container.
337+
338+
```
339+
$> docker run --env-file .env IMAGE
340+
```
341+
342+
Example for the Python RDP application:
343+
344+
```
345+
$>Python> docker build . -t python_rdp
346+
...
347+
$>Python> docker run --env-file .env --name python_console python_rdp
348+
```
349+
350+
Example for the Java RTO WebSocket application:
351+
352+
```
353+
$>Java> docker build . -t java_rto
354+
...
355+
$>Java> docker run --env-file .env --name java_websocket java_rto
356+
```
357+
#### Caution
358+
359+
You *should add* ```.env``` (and ```.env.example````) file to the ```.dockerignore``` file to avoid adding it to a public Docker Hub repository.
290360

291361

292362
## <a id="references"></a>References

0 commit comments

Comments
 (0)