Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add docker images for building the different platforms #11397

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ermshiperete
Copy link
Contributor

@ermshiperete ermshiperete commented May 8, 2024

This change adds the ability to build several docker images which can be used to build the different platforms (core, linux, web, android) and run tests. This can be used on a developer's machine but also on CI.

This change also updates the minimum node version to Node 20 as a temporary step until we try if we can use Node 22. This is necessary because the latest release of Node 18 still comes with the buggy npm that crashes the network. A better solution might have been to use nvm in the docker images (which would allow to easily update to the latest npm), but that would have required more changes and I decided to do it this way for now in order to finish this PR.

@keymanapp-test-bot skip

@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented May 8, 2024

@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S1 milestone May 8, 2024
@darcywong00 darcywong00 modified the milestones: A18S1, A18S2 May 11, 2024
@mcdurdin mcdurdin modified the milestones: A18S2, A18S3 May 24, 2024
@mcdurdin mcdurdin modified the milestones: A18S3, A18S4 Jun 7, 2024
@ermshiperete ermshiperete force-pushed the chore/linux/cicontainer branch 2 times, most recently from 90fe8aa to 1e10c81 Compare June 14, 2024 07:14
@darcywong00 darcywong00 modified the milestones: A18S4, A18S5 Jun 21, 2024
This updates the minimum required node version to Node 20. The latest
version of Node 18 still contains the npm bug
(npm/cli#7072) whereas Node 20 got updated to
a npm version that contains a fix. Node 20 is known to work with our
current code, so this change updates to that as an intermediate step
before we investigate if we can update to Node 22 as discussed for
Keyman 18.
This change allows to build a docker image that can build Keyman
for Linux with test coverage reports, and installs the necessary
dependencies for running integration tests.
@ermshiperete ermshiperete force-pushed the chore/linux/cicontainer branch from 1e10c81 to 8a4cdce Compare July 4, 2024 14:39
@github-actions github-actions bot added the core/ Keyman Core label Jul 4, 2024
@ermshiperete ermshiperete changed the base branch from master to fix/core/build July 4, 2024 14:40
@ermshiperete ermshiperete marked this pull request as ready for review July 4, 2024 14:41
@ermshiperete ermshiperete requested a review from mcdurdin as a code owner July 4, 2024 14:41
@ermshiperete ermshiperete removed the core/ Keyman Core label Jul 4, 2024
Base automatically changed from fix/core/build to master July 5, 2024 05:39
@darcywong00 darcywong00 modified the milestones: A18S5, A18S6 Jul 8, 2024
@darcywong00 darcywong00 modified the milestones: A18S6, A18S7 Jul 19, 2024
@darcywong00 darcywong00 modified the milestones: A18S7, A18S8 Aug 2, 2024
@darcywong00 darcywong00 modified the milestones: A18S8, A18S9 Aug 17, 2024
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good, let's also discuss how we can make this available from regular /build.sh, /android/build.sh etc as a parameter?

## Prerequisites

You'll need Docker Buildx installed to successfully be able to build the
container images. This is easiest achieved by installing the [official
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
container images. This is easiest achieved by installing the [official
container images. This is most easily achieved by installing the [official

By default this will create 64-bit images for building
Keyman for Android, Keyman for Linux and Keyman for Web. These images
are based on the Ubuntu 24.04 with Node 20 and Emscripten
3.1.44 (for the exact versions, see [`minimum-versions.inc.sh`](../build/minimum-versions.inc.sh))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3.1.44 (for the exact versions, see [`minimum-versions.inc.sh`](../build/minimum-versions.inc.sh))
3.1.58 (for the exact versions, see
[`minimum-versions.inc.sh`](../build/minimum-versions.inc.sh))

Comment on lines 46 to 54
```shell
# build 'Keyman Core' in docker
# keep build artifacts separate
mkdir -p $(git rev-parse --show-toplevel)/core/build/docker-core
docker run -it --rm -v $(git rev-parse --show-toplevel):/home/build/build \
-v $(git rev-parse --show-toplevel)/core/build/docker-core:/home/build/build/core/build \
keymanapp/keyman-core-ci:default \
core/build.sh --debug build
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this into a script under resources/docker-images, so we can e.g. ./resources/docker-images/run.sh core core/build.sh --debug build (then we'd need something for each of android,core,web,linux I guess)

(For example, we might also want to ./resources/docker-images/run.sh web common/web/build.sh)


```shell
# build 'Keyman Web' in docker
docker run --privileged -it --rm \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is --privileged needed for web build?

- Keyman Core

```shell
# build 'Keyman Core' in docker
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this script is moving into run.sh but it should be:

Suggested change
# build 'Keyman Core' in docker
# test 'Keyman Core' in docker

Comment on lines 14 to 23
#### TMP until we properly figure out the dependencies needed for Core
#### We should not need to install /tmp/control
# Install dependencies
ADD control /tmp/control
RUN apt-get install -qy python3 python3-setuptools python3-coverage \
devscripts equivs libdatetime-perl meson pkgconf lcov gcovr xvfb \
xserver-xephyr metacity mutter dbus-x11 weston xwayland && \
(yes | mk-build-deps --install /tmp/control) || true && \
rm /tmp/control
#### TMP END
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TMP ?

Comment on lines 25 to 32
# Install node
ARG NODE_MAJOR
RUN set -eu; \
NODE_VERSION=$(curl -sSL https://unofficial-builds.nodejs.org/download/release/ | cut -d'>' -f2 | cut -d'/' -f1 | grep v${NODE_MAJOR} | sort -V | tail -1) && \
echo "Installing node version ${NODE_VERSION}" && \
curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-glibc-217.tar.xz" && \
tar -xJf "node-${NODE_VERSION}-linux-x64-glibc-217.tar.xz" -C /usr/local --strip-components=1 --no-same-owner && \
ln -s /usr/local/bin/node /usr/local/bin/nodejs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use https://nvm.sh instead

Comment on lines 39 to 41
cd emsdk && \
./emsdk install ${EMSCRIPTEN_VERSION} && \
./emsdk activate ${EMSCRIPTEN_VERSION} && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have KEYMAN_USE_EMSDK we shouldn't need to do this first

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a test to stop this if not running in a Docker image, for user safety

Comment on lines 15 to 33
# Install node
ARG NODE_MAJOR
RUN set -eu; \
NODE_VERSION=$(curl -sSL https://unofficial-builds.nodejs.org/download/release/ | cut -d'>' -f2 | cut -d'/' -f1 | grep v${NODE_MAJOR} | sort -V | tail -1) && \
echo "Installing node version ${NODE_VERSION}" && \
curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/${NODE_VERSION}/node-${NODE_VERSION}-linux-x64-glibc-217.tar.xz" && \
tar -xJf "node-${NODE_VERSION}-linux-x64-glibc-217.tar.xz" -C /usr/local --strip-components=1 --no-same-owner && \
ln -s /usr/local/bin/node /usr/local/bin/nodejs

# Install emscripten
ARG EMSCRIPTEN_VERSION
RUN echo "Installing emscripten version ${EMSCRIPTEN_VERSION}" && \
cd /usr/share && \
git clone https://github.com/emscripten-core/emsdk.git && \
cd emsdk && \
./emsdk install ${EMSCRIPTEN_VERSION} && \
./emsdk activate ${EMSCRIPTEN_VERSION} && \
echo "#!/bin/bash" > /usr/bin/bashwrapper && \
echo "export EMSCRIPTEN_BASE=/usr/share/emsdk/upstream/emscripten" >> /usr/bin/bashwrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm.sh and keyman_use_emsdk as per core's Dockerfile

@darcywong00 darcywong00 modified the milestones: A18S9, A18S10 Aug 31, 2024
- use KEYMAN_USE_NVM and KEYMAN_USE_EMSDK
- pre-install node (where necessary) to prevent having to do it on each
  build
- adjust to current `master`
- fix a few bugs in the Dockerfile
- get required node version from package.json (through
  `shellHelperFunctions.sh`)
By default this will create 64-bit images for building
Keyman Core, Keyman for Android, Keyman for Linux and
Keyman for Web. These images are based on the Ubuntu 24.04
with Node 20 and Emscripten 3.1.58 (for the exact versions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the Dockerfiles below use Node 18?

ARG REQUIRED_NODE_VERSION=18

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's just the default value that doesn't get used. The node version get's passed in. I had to put something here, so I choose a somewhat sensible value that is different from what we currently have so that it's easier noticable if passing the value doesn't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be node 20 -- I think the req shifted since this PR started

Also add test action to build.sh which builds all images and then tests
them by running configure,build,test on each.

Also add new dependencies to web image which Playwright requires.
These changes bring us one step further, but the build is still failing.
Setting permissions is now done in the base image.
@mcdurdin mcdurdin modified the milestones: A18S10, 19.0 Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants