Skip to content

Commit 5b524c0

Browse files
Re-organize the two docker examples into a monorepo
Also: - update them to use the "previous latest" Theia community release, v1.49.1 - move docker example using the Trace Viewer for VS Code - rename docker examples sub-folders - rename example-package.json to package.json Signed-off-by: Marc Dumais <[email protected]>
1 parent 514449d commit 5b524c0

File tree

18 files changed

+9633
-151
lines changed

18 files changed

+9633
-151
lines changed

.github/workflows/docker-example.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
matrix:
1818
os: [ubuntu-latest]
1919
node-version: [18]
20+
params:
21+
- name: "tate"
22+
resources-folder: "theia-app-theia-ext"
23+
- name: "tave"
24+
resources-folder: "theia-app-vscode-ext"
2025

2126
steps:
2227
- uses: actions/checkout@v4
@@ -26,23 +31,25 @@ jobs:
2631
with:
2732
node-version: ${{ matrix.node-version }}
2833

29-
- name: Build example-docker
34+
- name: Build example app
3035
uses: nick-invision/retry@v3
3136
with:
3237
timeout_minutes: 10
3338
retry_wait_seconds: 15
34-
max_attempts: 3
39+
max_attempts: 1
3540
retry_on: error
3641
command: |
37-
cd examples/docker
38-
docker build -t tte .
42+
cd docker
43+
docker build . --build-arg RESOURCES=${{ matrix.params.resources-folder }} -t tv-${{ matrix.params.name }} -f Dockerfile-${{ matrix.params.name }}
3944
on_retry_command: cd ../..
4045

4146
- name: Run docker image
4247
run: |
43-
docker run --init -d -p 0.0.0.0:3000:4000 tte
48+
docker run --init -d -p 0.0.0.0:3000:4000 tv-${{ matrix.params.name }}
4449
4550
- name: Test trace viewer appliance
4651
run: |
4752
yarn --ignore-scripts
48-
yarn test:browser-app
53+
cd docker
54+
yarn --cwd ${{ matrix.params.resources-folder }} test
55+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
docker/*/gen-webpack.*
2+
docker/*/lib
3+
docker/*/src-gen
4+
node_modules/
5+
docker/*/plugins
6+

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
1-
# trace-viewer-examples
2-
Trace viewer example applications and building blocks that can be used in or with them. Each application integrates either the Eclipse Theia trace viewer extension or the trace viewer extension for VS Code
1+
# Trace Viewer Examples
2+
3+
Trace viewer example applications and building blocks that can be used in or with them. Each application integrates either the [Eclipse Theia trace viewer extension](https://www.npmjs.com/package/theia-traceviewer) (npmjs.com) or the [Trace Viewer extension for VSCode](https://open-vsx.org/extension/eclipse-cdt/vscode-trace-extension) (open-vsx.org).
4+
5+
## Requirements
6+
7+
### General Requirements
8+
9+
Generally speaking, all trace viewer example applications rely on the Trace Server Protocol (TSP), and require a compatible _Trace Server_. ATM it's left to the user to provide the trace server, start it and potentially configure the example application to access it, if it's not on the default host/port (localhost:8080). For more details, please consult the following documentation:
10+
11+
- obtaining/using the Eclipse Trace Compass trace server: [doc](https://github.com/eclipse-cdt-cloud/vscode-trace-extension/blob/master/vscode-trace-extension/README.md#obtain-the-trace-server-eclipse-trace-compass)
12+
- using the theia trace viewer extension: [README](https://github.com/eclipse-cdt-cloud/theia-trace-extension#using-the-trace-extension)
13+
- using the trace viewer for vscode: [README](https://github.com/eclipse-cdt-cloud/vscode-trace-extension/blob/master/vscode-trace-extension/README.md)
14+
15+
### Development Requirements
16+
17+
To build Theia-based applications "natively", i.e. not in docker:
18+
19+
- see this page: [Theia Developing.md "Prerequisites"](https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites)
20+
21+
To build the docker images you need to have Docker, or potentially a replacement such as Podman, installed and configured to be usable as a non-admin user.
22+
23+
## Examples Applications
24+
25+
### Docker examples
26+
27+
Easy to consume _trace viewer appliance_ Docker images, that you can build yourself. For more details look under folder [docker](./docker)
28+
29+
### Electron
30+
31+
(TODO) Electron-based desktop trace viewer application, that can be packaged for distribution
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM node:18.19.1-bookworm-slim as build
1+
FROM node:18.20.4-bookworm-slim AS build
2+
ARG RESOURCES
23

34
RUN apt-get update && apt-get install -y \
45
git \
@@ -11,31 +12,32 @@ RUN apt-get update && apt-get install -y \
1112
libxkbfile-dev
1213

1314
# Build the browser theia-trace-extension application
14-
COPY example-package.json /app/tte/package.json
15-
COPY webpack.config.js /app/tte/webpack.config.js
16-
WORKDIR /app/tte/
15+
COPY ${RESOURCES}/package.json /app/tv/
16+
COPY ${RESOURCES}/webpack.config.js /app/tv/
17+
COPY yarn.lock /app/tv/
18+
WORKDIR /app/tv/
1719
RUN yarn && \
18-
npx theia build --app-target=\"browser\" --mode production && \
20+
yarn build:prod && \
1921
yarn autoclean --init && \
2022
echo *.ts >> .yarnclean && \
2123
echo *.ts.map >> .yarnclean && \
2224
echo *.spec.* >> .yarnclean && \
2325
yarn --production && \
24-
yarn cache clean && \
25-
du -hs /app/tte
26+
yarn cache clean
2627

2728
FROM node:18.19.1-bookworm-slim
29+
ARG RESOURCES
2830

29-
COPY --from=build /app/tte /app/tte
31+
COPY --from=build /app/tv /app/tv
3032

3133
RUN apt-get update && apt-get install -y \
3234
libx11-6 \
3335
libxkbfile1 \
3436
libsecret-1-0 \
3537
&& rm -rf /var/lib/apt/lists/*
36-
ENV NODE_ENV production
38+
ENV NODE_ENV=production
3739

38-
WORKDIR /app/tte
39-
COPY docker-entrypoint.sh /usr/local/bin
40+
WORKDIR /app/tv
41+
COPY ${RESOURCES}/docker-entrypoint.sh /usr/local/bin
4042
EXPOSE 4000
4143
ENTRYPOINT ["docker-entrypoint.sh"]
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM node:18.19.1-bookworm-slim as build
1+
FROM node:18.20.4-bookworm-slim AS build
2+
ARG RESOURCES
23

34
RUN apt-get update && apt-get install -y \
45
git \
@@ -11,33 +12,34 @@ RUN apt-get update && apt-get install -y \
1112
libxkbfile-dev
1213

1314
# Build the browser trace-extension application
14-
COPY example-package.json /app/tte/package.json
15-
COPY webpack.config.js /app/tte/webpack.config.js
16-
WORKDIR /app/tte/
15+
COPY ${RESOURCES}/package.json /app/tv/
16+
COPY ${RESOURCES}/webpack.config.js /app/tv/
17+
COPY yarn.lock /app/tv/
18+
WORKDIR /app/tv/
1719
RUN yarn && \
1820
yarn run download:plugins && \
19-
npx theia build --app-target=\"browser\" --mode production && \
21+
yarn build:prod && \
2022
yarn autoclean --init && \
2123
echo *.ts >> .yarnclean && \
2224
echo *.ts.map >> .yarnclean && \
2325
echo *.spec.* >> .yarnclean && \
2426
echo "!@theia/test" >> .yarnclean && \
2527
yarn --production && \
26-
yarn cache clean && \
27-
du -hs /app/tte
28+
yarn cache clean
2829

2930
FROM node:18.19.1-bookworm-slim
31+
ARG RESOURCES
3032

31-
COPY --from=build /app/tte /app/tte
33+
COPY --from=build /app/tv /app/tv
3234

3335
RUN apt-get update && apt-get install -y \
3436
libx11-6 \
3537
libxkbfile1 \
3638
libsecret-1-0 \
3739
&& rm -rf /var/lib/apt/lists/*
38-
ENV NODE_ENV production
40+
ENV NODE_ENV=production
3941

40-
WORKDIR /app/tte
41-
COPY docker-entrypoint.sh /usr/local/bin
42+
WORKDIR /app/tv
43+
COPY ${RESOURCES}/docker-entrypoint.sh /usr/local/bin
4244
EXPOSE 4000
4345
ENTRYPOINT ["docker-entrypoint.sh"]

docker/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
# Docker examples
2+
3+
This folder and sub-folders contain what's necessary to build Trace Viewer example Docker images, that each contain a Trace Viewer frontend application.
4+
5+
Each application has a `DockerFile` in this folder and its resources in a sub-folder:
6+
7+
- `DockerFile-tate, resources folder: theia-app-theia-ext/`: Dockerfile and resourced needed to build a Trace Viewer Appliance, using a Theia application that includes the _Theia Trace Viewer_ _(Theia) extension_, installed [from npm][npm package].
8+
- `DockerFile-tave, resources folder: theia-app-vscode-ext/`: Dockerfile and resources needed to build a Trace Viewer Appliance, using a Theia application that includes the _Trace Viewer for VSCode_ _(vsix) extension_, installed [from the open vsx public registry][vsix package]
9+
10+
Note:
11+
12+
- the images will contain exclusively the trace viewer front-end. If you want to run a complete _trace viewer_ application, you will need a service running the trace-server (not included here)
13+
- see section "Docker tips and tricks" if you are relatively new to Docker and want to learn about some potential alternatives or refinements about some of the commands in this document.
14+
15+
## Quickly Build/Run the example Docker images
16+
17+
(_see section further down to learn how to manually build/run the images_)
18+
19+
For convenience and use in CI, there are `package.json scripts` to build the docker images on Linux. Note that it's not necessary to build anything in the repo first:
20+
21+
```bash
22+
$ cd <repo>/docker
23+
24+
# build all docker images
25+
$ yarn build:docker
26+
27+
28+
# build docker images individually
29+
30+
# build "tate" image: Theia app that uses
31+
# the theia trace viewer extension:
32+
$ yarn build:docker:tate
33+
# Run image:
34+
$ yarn run:docker:tate
35+
36+
37+
# build "tave" image: Theia app that uses
38+
# the vscode trace viewer extension:
39+
$ yarn build:docker:tave
40+
# Run image:
41+
$ yarn run:docker:tave
42+
43+
# Access the application at http://localhost:4000/
44+
# e.g.:
45+
$ firefox http://localhost:4000
46+
47+
```
48+
49+
## Manually Build/run the example Docker images
50+
51+
The Docker images can be build from the `<repo>/docker` folder. For each image, the resources it needs are in a sub-folder, whose name is passed as a `docker build` build argument and used to retrieve expected resourced needed during image build.
52+
53+
### Build/Run the "tate" image
54+
55+
Build the image and name it _tv-tate_ (short for `"trace viewer - theia application/theia extension"`). You may use a different name if you prefer.
56+
57+
Try adding `--network host` in case of build failures related to debian packages retrieval:
58+
59+
```bash
60+
docker build -f Dockerfile-tate -t tv-tate --build-arg RESOURCES=theia-app-theia-ext .
61+
```
62+
63+
Once the image has been built, start a container named _tv-tate-1_ from the _tv-tate_ image:
64+
65+
```bash
66+
# Keep container after the execution is done:
67+
docker run --name tv-tate-1 --network="host" tv-tate
68+
# if you do not need the container after execution and want
69+
# to avoid having to clean-up:
70+
docker run --rm --name tv-tate-1 --network="host" tv-tate
71+
```
72+
73+
Find the IP address of the _tv-tate-1_ container:
74+
75+
```bash
76+
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' tv-tate-1
77+
```
78+
79+
Connect to port `4000` of the IP identified earlier using your browser. You should be able to see the theia-trace-extension UI. If it is not visible, click on `View -> Open View... -> Trace Viewer`
80+
81+
Alternatively, one may start the container using "--network host" and then the app will be accessible opening in the browser: "localhost:4000":
82+
83+
```bash
84+
docker run --name tv-tate-1 --network="host" tv-tate
85+
# open "http://localhost:4000" in browser. e.g.:
86+
firefox http://localhost:4000
87+
```
88+
89+
#### Connect to a remote trace-server
90+
91+
Let's say you have another container running the trace-server at IP 172.17.0.2, port `8080`. You can launch the _tv-tate-1_ container and connect it to the trace-server using the following command:
92+
93+
```bash
94+
docker run --name tv-tate-1 --network="host" -e TRACE_SERVER_URL=172.17.0.2:8080/tsp/api tv-tate
95+
```
96+
97+
### Build/Run the "tave" image
98+
99+
Build the image and name it _tv-tave_ (short for `"trace viewer - theia application/vscode extension"`). You may use a different name if you prefer.
100+
101+
Try adding `--network host` in case of build failures related to debian packages retrieval.
102+
103+
```bash
104+
docker build -f Dockerfile-tave -t tv-tave --build-arg RESOURCES=theia-app-vscode-ext .
105+
```
106+
107+
Once the image has been built, start a container named _tv-tave-1_ fromthe _tave_ image:
108+
109+
```bash
110+
docker run --name tv-tave-1 --network host tv-tave
111+
```
112+
113+
Connect to `localhost:4000` your browser. You should be able to see the trace-extension UI. If it is not visible, click on `View -> Open View... -> Trace Viewer`
114+
115+
## Development
116+
117+
When the _Theia applications_ are modified/updated, e.g. to update the contained trace extension or for other reasons, it's important to build the modified app(s) outside Docker and check-in the modified `yarn.lock`. The lock file is used when building in the container, to insure a known/curated set of dependencies/versions are used. Without the lock file, unexpected 3PPs or versions of 3PPs might be pulled.
118+
119+
To build the Theia applications:
120+
121+
```bash
122+
# build both apps (dev)
123+
$ yarn && yarn build
124+
125+
# build both apps (prod version)
126+
$ yarn && yarn build:prod
127+
```
128+
129+
If after the build, it turns-out that `yarn.lock` has been modified, the new version needs to be upstreamed as part of the PR that changed the Theia application.
130+
131+
## Docker tips and tricks
132+
133+
### docker run
134+
135+
#### Dangling containers
136+
137+
If a container already exists with the same name, you will get an error like this:
138+
139+
> docker: Error response from daemon: Conflict. The container name "/tv-tate-1" is already in use by container "bdc7e40b3c61d60538b54e2842c34a66e9641d00b17511096d01d7db81e4782f". You have to remove (or rename) that container to be able to reuse that name.
140+
141+
Option 1: you may delete the old version of that container:
142+
143+
```bash
144+
# The error message above provides the container id. You may use it
145+
# directly to delete the container (you may use the beginning of the SHA):
146+
docker rm bdc7e40b
147+
148+
# If you need to find the id for the old container yourself:
149+
docker ps -a
150+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
151+
bdc7e40b3c61 tv-tate "docker-entrypoint.sh" 56 minutes ago Exited (137) 13 minutes ago tv-tate-1
152+
```
153+
154+
Options 2 and 3 will avoid the error in the future:
155+
156+
Option 2: use "--rm" when running "docker run" so that docker will itself remove the container upon exit:
157+
158+
```bash
159+
# for example
160+
docker run --rm --name tv-tate-1 tv-tate
161+
```
162+
163+
option 3: do not name the containers and let Docker give them a randomly-generated name.
164+
165+
```bash
166+
# for example
167+
docker run --rm tv-tate
168+
# use "docker ps" to find the name
169+
docker ps
170+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
171+
693f53e05929 tv-tate "docker-entrypoint.sh" 4 seconds ago Up 3 seconds 4000/tcp eloquent_wozniak
172+
173+
# in this case the container is named: "eloquent_wozniak"
174+
175+
```
176+
177+
### docker build
178+
179+
If docker can't connect to the apt repository to fetch required packages, use "--network host". e.g.:
180+
181+
```bash
182+
# if this times-out accessing the apt repo
183+
docker build -f Dockerfile-tate -t tv-tate --build-arg RESOURCES=theia-app-theia-ext .
184+
185+
# try this instead:
186+
docker build --network host -f Dockerfile-tate -t tv-tate --build-arg RESOURCES=theia-app-theia-ext .
187+
```
188+
189+
### docker network
190+
191+
Using "--network host" as part of "docker run [...]": This configures the Docker container to use the host network stack directly instead of creating an isolated network namespace for the container. This can make some use-cases easier, e.g. having the trace viewer app running in the container accessing a trace server running on the host.
192+
193+
But be aware that this may have security implications in some contexts.
194+
195+
[npm package]: https://www.npmjs.com/package/theia-traceviewer
196+
[vsix package]: https://open-vsx.org/extension/eclipse-cdt/vscode-trace-extension

0 commit comments

Comments
 (0)