Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Remote binary #267

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build_and_push_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ DOCKER_FILES_LOCATIONS=(
dockerfiles/theia-dev
dockerfiles/theia
dockerfiles/theia-endpoint-runtime
dockerfiles/theia-endpoint-runtime-binary
dockerfiles/remote-plugin-java8
dockerfiles/remote-plugin-java11
dockerfiles/remote-plugin-go-1.10.7
Expand All @@ -32,6 +33,7 @@ IMAGES_LIST=(
eclipse/che-theia-dev
eclipse/che-theia
eclipse/che-theia-endpoint-runtime
eclipse/che-theia-endpoint-runtime-binary
eclipse/che-remote-plugin-runner-java8
eclipse/che-remote-plugin-runner-java11
eclipse/che-remote-plugin-go-1.10.7
Expand Down
8 changes: 8 additions & 0 deletions dockerfiles/theia-endpoint-runtime-binary/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
theia-plugin-ext
docker-build
.browser_modules
*.log
*-app/*
!*-app/package.json
.idea
.Dockerfile
78 changes: 78 additions & 0 deletions dockerfiles/theia-endpoint-runtime-binary/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation

FROM ${BUILD_ORGANIZATION}/${BUILD_PREFIX}-theia-dev:${BUILD_TAG} as builder


# define in env variable GITHUB_TOKEN only if it is defined
# else check if github rate limit is enough, else will abort requiring to set GITHUB_TOKEN value
ARG GITHUB_TOKEN

# Check github limit
RUN if [ ! -z "${GITHUB_TOKEN-}" ]; then \
export GITHUB_TOKEN=$GITHUB_TOKEN; \
echo "Setting GITHUB_TOKEN value as provided"; \
else \
export GITHUB_LIMIT=$(curl -s 'https://api.github.com/rate_limit' | jq '.rate .remaining'); \
echo "Current API rate limit https://api.github.com is ${GITHUB_LIMIT}"; \
if [ "${GITHUB_LIMIT}" -lt 10 ]; then \
printf "\033[0;31m\n\n\nRate limit on https://api.github.com is reached so in order to build this image, "; \
printf "the build argument GITHUB_TOKEN needs to be provided so build will not fail.\n\n\n\033[0m"; \
exit 1; \
else \
echo "GITHUB_TOKEN variable is not set but https://api.github.com rate limit has enough slots"; \
fi \
fi

#invalidate cache
ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/theia-ide/theia/git/refs/head /tmp/branch_info.json
ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/eclipse/che-theia/git/refs/head /tmp/branch_info.json

# Grab dependencies
COPY /docker-build/theia-plugin-remote/package.json /home/workspace/packages/theia-remote/
RUN cd /home/workspace/packages/theia-remote/ && yarn install --ignore-scripts

# Compile
COPY /docker-build/configs /home/workspace/configs
COPY /docker-build/theia-plugin-remote/*.json /home/workspace/packages/theia-remote/
COPY /docker-build/theia-plugin-remote/src /home/workspace/packages/theia-remote/src
COPY /docker-build/theia-plugin-ext /home/workspace/packages/theia-plugin-ext
COPY /docker-build/theia-plugin /home/workspace/packages/theia-plugin
COPY /docker-build/theia-plugin-remote/tsconfig.json /home/workspace/packages/theia-plugin/tsconfig.json

COPY /etc/package.json /home/workspace
RUN cd /home/workspace/ && yarn install

RUN yarn global add nexe@3.2.0 && nexe -v
WORKDIR /home/workspace

# Fix theia-plugin-ext dependency
RUN rm -rf /home/workspace/node_modules/@eclipse-che/theia-plugin-ext /home/workspace/node_modules/@eclipse-che/theia-remote
RUN cp -rf /home/workspace/packages/theia-plugin-ext /home/workspace/node_modules/@eclipse-che/theia-plugin-ext

RUN nexe packages/theia-remote/lib/node/plugin-remote.js -t alpine-x64-10.14.2 -o plugin-remote
Copy link
Contributor

Choose a reason for hiding this comment

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

is that the binary is running on pure alpine image after that ? AFAIK there was still some mandatory libraries required to run on a plain alpine image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... I tested two remote plugins: typescript and my custom with this binary on the pure alpine - they were working... 99ae354#diff-f7eaf7e082319e42b2dfd26a86ca0736R80
Could you elaborate more about mandatory libraries ?

Copy link
Contributor

Choose a reason for hiding this comment

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

alpine image is just alpine:latest or was there some other packages installed?
my attempt was with pkg and not nexe so it might different, it was requiring libstdc++ package
vercel/pkg#555



FROM registry.access.redhat.com/ubi8/ubi-minimal

COPY --from=builder /home/workspace/plugin-remote /plugin-remote

RUN mkdir /projects /home/theia \
# Store passwd/group as template files
&& cat /etc/passwd | sed s#root:x.*#root:x:\${USER_ID}:\${GROUP_ID}::\${HOME}:/bin/sh#g > ${HOME}/passwd.template \
&& cat /etc/group | sed s#root:x:0:#root:x:0:0,\${USER_ID}:#g > ${HOME}/group.template \
# Change permissions to let any arbitrary user
&& for f in "${HOME}" "/etc/passwd" "/etc/group" "/projects"; do \
echo "Changing permissions on ${f}" && chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done

ADD etc/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
48 changes: 48 additions & 0 deletions dockerfiles/theia-endpoint-runtime-binary/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0

base_dir=$(cd "$(dirname "$0")"; pwd)
. "${base_dir}"/../build.include

DIR=$(cd "$(dirname "$0")"; pwd)
LOCAL_ASSEMBLY_DIR="${DIR}"/docker-build

if [ -d "${LOCAL_ASSEMBLY_DIR}" ]; then
rm -rf "${LOCAL_ASSEMBLY_DIR}"
fi

#in mac os 'cp' cannot create destination dir, so create it first
mkdir ${LOCAL_ASSEMBLY_DIR}

app_root=${base_dir}/../..

echo "Copying ${app_root}/extensions/eclipse-che-theia-plugin --> ${LOCAL_ASSEMBLY_DIR}/theia-plugin"
mkdir ${LOCAL_ASSEMBLY_DIR}/theia-plugin
cp -r "${app_root}/extensions/eclipse-che-theia-plugin/src/." "${LOCAL_ASSEMBLY_DIR}/theia-plugin/src/"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin/package.json" "${LOCAL_ASSEMBLY_DIR}/theia-plugin"

echo "Copying ${app_root}/extensions/eclipse-che-theia-plugin-ext --> ${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext"
mkdir ${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-ext/src/." "${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext/src/"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-ext/package.json" "${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-ext/tsconfig.json" "${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-ext/webpack.config.js" "${LOCAL_ASSEMBLY_DIR}/theia-plugin-ext"

echo "Copying ${app_root}/configs --> ${LOCAL_ASSEMBLY_DIR}/configs"
cp -r "${app_root}/configs/." "${LOCAL_ASSEMBLY_DIR}/configs"

echo "Copying ${app_root}/extensions/eclipse-che-theia-plugin-remote --> ${LOCAL_ASSEMBLY_DIR}/theia-plugin-remote"
mkdir ${LOCAL_ASSEMBLY_DIR}/theia-plugin-remote
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-remote/src/." "${LOCAL_ASSEMBLY_DIR}/theia-plugin-remote/src/"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-remote/package.json" "${LOCAL_ASSEMBLY_DIR}/theia-plugin-remote"
cp -r "${app_root}/extensions/eclipse-che-theia-plugin-remote/tsconfig.json" "${LOCAL_ASSEMBLY_DIR}/theia-plugin-remote"


init --name:theia-endpoint-runtime-binary "$@"
build
68 changes: 68 additions & 0 deletions dockerfiles/theia-endpoint-runtime-binary/etc/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
#
# Copyright (c) 2018-2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

export USER_ID=$(id -u)
export GROUP_ID=$(id -g)

if ! grep -Fq "${USER_ID}" /etc/passwd; then
# current user is an arbitrary
# user (its uid is not in the
# container /etc/passwd). Let's fix that
cat ${HOME}/passwd.template | \
sed "s/\${USER_ID}/${USER_ID}/g" | \
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
sed "s/\${HOME}/\/home\/theia/g" > /etc/passwd

cat ${HOME}/group.template | \
sed "s/\${USER_ID}/${USER_ID}/g" | \
sed "s/\${GROUP_ID}/${GROUP_ID}/g" | \
sed "s/\${HOME}/\/home\/theia/g" > /etc/group
fi

# Grant access to projects volume in case of non root user with sudo rights
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
sudo chown ${USER_ID}:${GROUP_ID} /projects
fi

# SITTERM / SIGINT
responsible_shutdown() {
echo ""
echo "Received SIGTERM"
kill -INT ${PID}
wait ${PID}
exit;
}

set -e

# setup handlers
# on callback, kill the last background process, which is `tail -f /dev/null` and execute the specified handler
trap 'responsible_shutdown' HUP TERM INT

cd ${HOME}

# run theia endpoint
/plugin-remote &

PID=$!

# See: http://veithen.github.io/2014/11/16/sigterm-propagation.html
wait ${PID}
wait ${PID}
EXIT_STATUS=$?

# wait forever
while true
do
tail -f /dev/null & wait ${!}
done
21 changes: 21 additions & 0 deletions dockerfiles/theia-endpoint-runtime-binary/etc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"devDependencies": {
"tslint": "5.10.0",
"rimraf": "2.6.2",
"typescript": "3.1.3",
"typescript-formatter": "7.2.2"
},
"scripts": {
"prepare": "yarn run clean && yarn run tslint && yarn run build",
"tslint-fix": "tslint --fix --project packages/theia-remote",
"tslint": "tslint --project packages/theia-remote",
"clean": "rimraf packages/**/lib",
"format-code": "tsfmt -r --baseDir packages/theia-remote && tsfmt -r --baseDir packages/theia-plugin-ext",
"compile": "tsc -b packages/**",
"build": "yarn run format-code && yarn run compile && yarn run tslint-fix"
}
}
3 changes: 1 addition & 2 deletions dockerfiles/theia-endpoint-runtime/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN if [ ! -z "${GITHUB_TOKEN-}" ]; then \
fi \
fi

#invalidate cashe
#invalidate cache
ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/theia-ide/theia/git/refs/head /tmp/branch_info.json
ADD https://${GITHUB_TOKEN}:x-oauth-basic@api.github.com/repos/eclipse/che-theia/git/refs/head /tmp/branch_info.json

Expand Down Expand Up @@ -67,4 +67,3 @@ RUN mkdir /projects \
done
ADD etc/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import { ExtPluginApiProvider, ExtPluginApi } from '@theia/plugin-ext/lib/common/plugin-ext-api-contribution';
import { injectable } from 'inversify';
import * as path from 'path';

@injectable()
export class ChePluginApiProvider implements ExtPluginApiProvider {
Expand All @@ -22,7 +21,7 @@ export class ChePluginApiProvider implements ExtPluginApiProvider {
initFunction: 'initializeApi',
initVariable: 'che_api_provider'
},
backendInitPath: path.join(__dirname, '../plugin/node/che-api-node-provider.js')
backendInitPath: '@eclipse-che/theia-plugin-ext/lib/plugin/node/che-api-node-provider.js'
Copy link
Contributor

Choose a reason for hiding this comment

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

in theia, we don't have path.join as well anymore ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const localModule = ConnectionContainerModule.create(({ bind }) => {
});

export default new ContainerModule(bind => {
try {
// Force nexe to include theia-plugin-ext inside binary
require('@eclipse-che/theia-plugin-ext/lib/node/che-plugin-api-provider.js');
} catch (err) {
console.log('Unable to set up che theia plugin api: ', err);
}

bind(HostedPluginMapping).toSelf().inSingletonScope();
bind(MetadataProcessor).to(RemoteMetadataProcessor).inSingletonScope();
bind(ConnectionContainerModule).toConstantValue(localModule);
Expand Down