Skip to content

Commit

Permalink
docker: fix and improve docker example
Browse files Browse the repository at this point in the history
Before this commit the docker example was not properly building.
The issue was introduced when moving from Theia 1.3x to 1.4x, where
an extra step in the build process was introduced (i.e. running "yarn"
was not enough, an extra "theia" command was needed).

After this commit:
- the docker example is building again
- the docker image generated is stable and reproducible,
  not based on "next"
- the docker image is much smaller thanks to a multistage build

Signed-off-by: Francesco Robino <francesco.robino@ericsson.com>
  • Loading branch information
frallax authored and marcdumais-work committed Dec 15, 2023
1 parent ff0943f commit 3b6004e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
46 changes: 33 additions & 13 deletions examples/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
FROM node:16-alpine
FROM node:16.20.2-bookworm-slim as build

RUN mkdir /home/app
WORKDIR /home/app

RUN apk add --no-cache bash git python3 make pkgconfig libsecret-dev g++
# Use "bash" as replacement for "sh"
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update && apt-get install -y \
git \
python3 \
make \
pkg-config \
libsecret-1-dev \
g++ \
libx11-dev \
libxkbfile-dev

# Build the browser theia-trace-extension application
COPY example-package.json /home/app/package.json
RUN npx yarn
COPY example-package.json /app/tte/package.json
WORKDIR /app/tte/
RUN yarn && \
npx theia build --app-target=\"browser\" --mode development && \
yarn autoclean --init && \
echo *.ts >> .yarnclean && \
echo *.ts.map >> .yarnclean && \
echo *.spec.* >> .yarnclean && \
yarn cache clean

FROM node:16.20.2-bookworm-slim

COPY --from=build /app/tte /app/tte

COPY startup.sh /home/app
RUN ["chmod", "+x", "/home/app/startup.sh"]
RUN apt-get update && apt-get install -y \
libx11-6 \
libxkbfile1 \
libsecret-1-0 \
&& rm -rf /var/lib/apt/lists/*
ENV NODE_ENV production

# Start the service
ENTRYPOINT ["/home/app/startup.sh"]
WORKDIR /app/tte
COPY docker-entrypoint.sh /usr/local/bin
EXPOSE 4000
ENTRYPOINT ["docker-entrypoint.sh"]
7 changes: 4 additions & 3 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Notes:
If you want to run a complete application, you will need a service
running the trace-server (not included here);

- the image will be built using the latest [npm package] of the
theia-trace-extension, and not the code in this repo;
- the image will be built using a specific [npm package] of the
theia-trace-extension, and not the latest code in this repo;

- the *example-package.json* file is not named *package.json* because
at the time this change was proposed building the theia-trace-extension
Expand All @@ -20,7 +20,8 @@ Notes:

## How to build and run

Build the image and name it *tte*:
Build the image and name it *tte*. Try adding `--network host` in case
of build failures related to debian packages retrieval:

```bash
docker build -t tte .
Expand Down
2 changes: 2 additions & 0 deletions examples/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
yarn start --hostname 0.0.0.0 --port 4000
9 changes: 5 additions & 4 deletions examples/docker/example-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
}
},
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@mui/material": "^5.10.14",
"@theia/core": "1.43.1",
"@theia/editor": "1.43.1",
"@theia/filesystem": "1.43.1",
Expand All @@ -27,9 +30,8 @@
"@theia/preferences": "1.43.1",
"@theia/process": "1.43.1",
"@theia/terminal": "1.43.1",
"@theia/vsx-registry": "1.43.1",
"@theia/workspace": "1.43.1",
"theia-traceviewer": "next"
"theia-traceviewer": "0.2.0-next.20231206220005.ff0943f.0"
},
"devDependencies": {
"@theia/cli": "1.43.1"
Expand All @@ -42,6 +44,5 @@
"engines": {
"yarn": "1.0.x || >=1.2.1",
"node": ">=12.14.1 <17"
},
"theiaPluginsDir": "../plugins"
}
}
3 changes: 0 additions & 3 deletions examples/docker/startup.sh

This file was deleted.

0 comments on commit 3b6004e

Please sign in to comment.