Skip to content

Commit

Permalink
Add IDEA dev server
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Zatsarynnyi <[email protected]>
  • Loading branch information
azatsarynnyy committed Nov 30, 2023
1 parent ea4ad45 commit e8a189b
Show file tree
Hide file tree
Showing 10 changed files with 1,260 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/image-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: image-publish

on:
push:
branches:
- 'main'

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.CHE_INCUBATOR_BOT_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build and push image
uses: docker/build-push-action@v4
with:
context: .
file: build/dockerfiles/Dockerfile
push: true
tags: quay.io/che-incubator/che-idea-dev-server:next
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# che-idea
# IDEA dev server for Che [![Dev](https://img.shields.io/static/v1?label=Open%20in&message=Che%20dogfooding%20server%20&logo=eclipseche&color=FDB940&labelColor=525C86)](https://che-dogfooding.apps.che-dev.x6e0.p1.openshiftapps.com/f?url=https://github.com/azatsarynnyy/web-nodejs-sample/tree/idea-server&policies.create=peruser) [![Dev](https://img.shields.io/static/v1?label=Open%20in&message=DevSandbox%20(hosted%20by%20Red%20Hat)&logo=eclipseche&color=FDB940&labelColor=525C86)](https://devspaces.apps.sandbox-m4.g2pi.p1.openshiftapps.com/f?url=https://github.com/azatsarynnyy/web-nodejs-sample/tree/idea-server&policies.create=peruser)

## Image build

`podman build . -f build/dockerfiles/Dockerfile -t che-idea-dev-server:next`

## License

- [Eclipse Public License 2.0](LICENSE)

## Trademark

"Che" is a trademark of the Eclipse Foundation.
37 changes: 37 additions & 0 deletions build/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2023 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 registry.access.redhat.com/ubi8/nodejs-18:1-60 AS ubi-builder

WORKDIR /idea-dist/
RUN curl -sL https://download-cdn.jetbrains.com/idea/ideaIU-2023.2.5.tar.gz | tar xzf - --strip-components=1

USER 0

COPY --chmod=755 /build/dockerfiles/*.sh /
COPY /status-app/ /idea-dist/status-app/

# Create a directory for mounting a volume.
RUN mkdir /idea-server

# Adjust permissions on some items so they're writable by group root.
RUN for f in "${HOME}" "/etc/passwd" "/etc/group" "/idea-dist/status-app" "/idea-server"; do\
chgrp -R 0 ${f} && \
chmod -R g+rwX ${f}; \
done

# Build the status app.
WORKDIR /idea-dist/status-app/
RUN npm install

# Switch to unprivileged user.
USER 10001

ENTRYPOINT /entrypoint.sh
19 changes: 19 additions & 0 deletions build/dockerfiles/entrypoint-init-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
#
# Copyright (c) 2023 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
#

# Copy IDEA server stuff to the shared volume.
cp -r /idea-dist/* /idea-server/
cp /entrypoint-volume.sh /idea-server/

echo "Volume content:"
ls -la /idea-server
35 changes: 35 additions & 0 deletions build/dockerfiles/entrypoint-volume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
#
# Copyright (c) 2023 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
#

# Register the current (arbitrary) user.
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "Registering the current (arbitrary) user."
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
fi
fi

echo "Volume content:"
ls -la /idea-server/

# Start the app that checks the IDEA server status.
# This should be the editor's 'main' endpoint.
cd /idea-server/status-app
nohup yarn start &

# Skip all interactive shell prompts.
export REMOTE_DEV_NON_INTERACTIVE=1

cd /idea-server/bin
./remote-dev-server.sh run ${PROJECT_SOURCE}
27 changes: 27 additions & 0 deletions build/dockerfiles/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
#
# Copyright (c) 2023 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
#

# Register the current (arbitrary) user.
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "Registering the current (arbitrary) user."
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
fi
fi

# Skip all interactive shell prompts.
export REMOTE_DEV_NON_INTERACTIVE=1

cd /idea-dist/bin
./remote-dev-server.sh run ~
59 changes: 59 additions & 0 deletions status-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2023 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
*/

const chokidar = require('chokidar');
const fs = require("fs");
const express = require('express');

// path to the IDEA server's output
const logsFile = '/idea-server/std.out';

// watch for the 'Join-link' in the IDEA server's output
var joinLink = new Promise((resolve) => {
const watcher = chokidar.watch(logsFile);
watcher.on('change', (event, path) => {
fs.readFile(logsFile, "utf-8", (err, data) => {
if (err)
throw err;

if (data.includes('Join link: tcp://')) {
const tcpLinkRegex = /(tcp:\/\/[^\s]+)/g;
data.replace(tcpLinkRegex, function (link) {
console.log('TCP join link is accuired: ' + link);
resolve(link);
watcher.close().then(() => console.log('Watcher is closed!'));
});
}
});
});
});

// return the status page
const app = express();
app.set('view engine', 'ejs');
app.get('/', async function (req, res) {
const invitationLink = await joinLink;
const dwName = process.env.DEVWORKSPACE_NAME;
const clusterConsoleURL = process.env.CLUSTER_CONSOLE_URL;
const podName = process.env.HOSTNAME;

res.render('status', { dwName, clusterConsoleURL, podName, invitationLink });
});

// server setup
const appPort = '3100';
app.listen(appPort, function (err) {
if (err)
throw err;

console.log('Status app is listening on port', appPort);
});
Loading

0 comments on commit e8a189b

Please sign in to comment.