Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
add MPS specific projector docker image creator
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoester committed Aug 30, 2023
1 parent 1b54856 commit 56c359d
Show file tree
Hide file tree
Showing 18 changed files with 466 additions and 1 deletion.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions docker/Dockerfile-projector
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG MPS_VERSION
# If the version of modelix/projector-mps is missing, run docker-build-projector-mps.sh to build and publish that image
FROM modelix/projector-mps:$MPS_VERSION AS with-zip
USER root
RUN apt-get update \
&& apt-get install unzip zip -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/apt

FROM with-zip AS patch-branding

COPY helper/patch-branding.sh /
RUN /patch-branding.sh

FROM with-zip

COPY --from=patch-branding /branding.zip /projector/ide/lib/branding.jar

RUN echo "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5071" >> /projector/ide/bin/mps64.vmoptions \
&& sed -i.bak '/-Xmx/d' /projector/ide/bin/mps64.vmoptions \
&& echo "-XX:MaxRAMPercentage=85" >> /projector/ide/bin/mps64.vmoptions \
&& mkdir -p /mps-plugins \
&& mkdir -p /mps-languages \
&& chown -R projector-user:projector-user /home/projector-user \
&& chown -R projector-user:projector-user /mps-plugins \
&& chown -R projector-user:projector-user /mps-languages \
&& chown -R projector-user:projector-user /projector/ide/

# An "End User Agreement" dialog prevents the startup if the vendor name is 'JetBrains'
# See
# - https://github.com/JetBrains/intellij-community/blob/777669cc01eb14e6fcf2ed3ba11d2c1d3832d6e2/platform/platform-impl/src/com/intellij/idea/eua.kt#L19-L20
# - https://github.com/JetBrains/MPS/blob/418307944be761dd1e62af65881c8eade086386f/plugins/mps-build/solutions/mpsBuild/source_gen/jetbrains/mps/ide/build/mps.sh#L224
# - https://github.com/JetBrains/MPS/blob/418307944be761dd1e62af65881c8eade086386f/plugins/mps-build/solutions/mpsBuild/source_gen/jetbrains/mps/ide/build/mps.sh#L57
RUN sed -i.bak "s/IDEA_VENDOR_NAME='JetBrains'/IDEA_VENDOR_NAME='Modelix'/g" /projector/ide/bin/mps.sh

USER projector-user

COPY --chown=projector-user:projector-user helper/projector-user-home /home/projector-user

# rename config directory to match the correct MPS version
RUN mv "/home/projector-user/.config/JetBrains/MPSxxxx.x" "/home/projector-user/.config/JetBrains/MPS$(grep "mpsBootstrapCore.version=" /projector/ide/build.properties|cut -d'=' -f2)"

# changing the vendor name (see above) also changes the location of the config dir
RUN ln -s /home/projector-user/.config/JetBrains /home/projector-user/.config/Modelix

COPY --chown=projector-user:projector-user helper/log.xml /projector/ide/bin/log.xml
COPY --chown=projector-user:projector-user build/artifacts/de.itemis.mps.extensions/ /mps-plugins/MPS-extensions
COPY --chown=projector-user:projector-user build/artifacts/org.modelix/plugins/ /mps-plugins/modelix

COPY helper/install-plugins.sh /
RUN /install-plugins.sh /projector/ide/plugins/
79 changes: 79 additions & 0 deletions docker/docker-build-projector-mps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh

set -e

# read variables from mps-version.properties
while IFS='=' read -r key value
do
echo "$key=$value"
eval "${key}"=\${value}
done < "mps-version.properties"
echo "MPS Version: $mpsVersion"
echo "MPS Major Version: $mpsMajorVersion"
echo "MPS Minor Version: $mpsMinorVersion"

modelixVersion=$( ./modelix-version.sh )
echo "Modelix Version: $modelixVersion"

TIMESTAMP="$(date +"%Y%m%d%H%M")"

(
cd ../
if [ -d ./projector-server ]; then
(
cd projector-server
git reset --hard
git clean -xdf
git pull
)
else
git clone https://github.com/modelix/projector-server.git
fi
(
cd projector-server
echo "useLocalProjectorClient=true" > local.properties
)

if [ -d ./projector-client ]; then
(
cd projector-client
git reset --hard
git clean -xdf
git pull
)
else
git clone https://github.com/modelix/projector-client.git
fi

if [ -d ./projector-docker ]; then
(
cd projector-docker
git reset --hard
git clean -xdf
git pull
)
else
git clone https://github.com/modelix/projector-docker.git
fi

cd projector-docker
(
cd ../projector-server
./gradlew :projector-server:distZip
)

downloadUrl="https://download.jetbrains.com/mps/${mpsMajorVersion}/MPS-${mpsVersion}.tar.gz"

# if [ "${CI}" = "true" ]; then
docker buildx build --platform linux/amd64,linux/arm64 --push \
-t "modelix/projector-mps:${mpsMajorVersion}" \
-t "modelix/projector-mps:${mpsVersion}" \
--build-arg buildGradle=false --build-arg "downloadUrl=${downloadUrl}" -f Dockerfile ..
# else
# docker buildx build \
# -t "modelix/projector-mps:${mpsMajorVersion}" \
# -t "modelix/projector-mps:${mpsVersion}" \
# --build-arg buildGradle=false --build-arg "downloadUrl=${downloadUrl}" -f Dockerfile ..
# fi
)

20 changes: 20 additions & 0 deletions docker/docker-build-projector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

cd "$(dirname "$0")"

set -e

mkdir -p build/artifacts
cp -r ../artifacts/de.itemis.mps.extensions build/artifacts/
cp -r ../build/org.modelix/build/artifacts/org.modelix build/artifacts/

MPS_VERSION=$( ./helper/mps-version.sh )
MODELIX_VERSION=$( ./helper/modelix-version.sh )

if [ "${CI}" = "true" ]; then
docker buildx build --platform linux/amd64,linux/arm64 --push --build-arg MPS_VERSION=${MPS_VERSION} -f Dockerfile-projector \
-t "modelix/modelix-projector:${MODELIX_VERSION}" .
else
docker build --build-arg MPS_VERSION=${MPS_VERSION} -f Dockerfile-projector \
-t "modelix/modelix-projector:${MODELIX_VERSION}" .
fi
33 changes: 33 additions & 0 deletions docker/helper/install-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

# Only used in the modelix/modelix-mps docker image as an easy way to build custom images with additional plugins.
# Finds and copies all MPS plugins from SOURCE_FOLDER to TARGET_FOLDER. Zip files containing plugins are extracted.

TARGET_FOLDER="${1:-/usr/modelix-ui/mps/plugins/}"
SOURCE_FOLDER="${2:-/mps-plugins/}"
DELETE_INPUT_FOLDER="${3:-1}"

#SOURCE_FOLDER=../test_input
#TARGET_FOLDER=../test_output/
#rm -rf $SOURCE_FOLDER
#rm -rf $TARGET_FOLDER
#mkdir $SOURCE_FOLDER
#mkdir $TARGET_FOLDER
#cp -R ./build $SOURCE_FOLDER

find $SOURCE_FOLDER -name '*.zip' |
while IFS= read -r line; do
ZIP_OUTPUT_DIR="$line-unzip"
unzip -d $ZIP_OUTPUT_DIR $line
done

find $SOURCE_FOLDER -path '**/META-INF/plugin.xml' |
while IFS= read -r line; do
PLUGIN_DIR="$(dirname "$(dirname $line)")"
mv $PLUGIN_DIR $TARGET_FOLDER
echo "Installed plugin from $PLUGIN_DIR"
done

if [ $DELETE_INPUT_FOLDER -eq "1" ]; then
rm -rf "${SOURCE_FOLDER:?}"/*
fi
160 changes: 160 additions & 0 deletions docker/helper/log.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<!--
IntelliJ Platform log all STDOUT and STDERR output to idea.log file by default.
See com.intellij.idea.StartupUtil#setupLogger system property 'intellij.log.stdout'.
Two main appenders are FILE and DIALOG:
FILE is responsible for logging to the idea.log file.
DIALOG is responsible for showing ERROR level (at least) events in UI (events are ignored in command line mode).
MPS additionally logs VCS events to mpsvcs.log file: categories are used for that.
Appenders CONSOLE-* can be used to debug purposes to get application output to the console.
Note that adding this appenders to root appender will result in duplication of entries in idea.log file.
CONTINUOUS_FILE appender can also be used for debugging.
It does not interfere with console output and idea.log, but uses separate continuous.log file.
All file appenders use $LOG_DIR$ folder for store files.
In MPS sources some run configurations override this path by setting 'idea.log.path' variable to '$PROJECT_DIR$/log'.
-->

<!-- Parameter 'follow = true' in appenders with class 'ConsoleAppender' is required for proper test light execution -->

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Output events with level at least WARN to console. See org.apache.log4j.Level.WARN -->
<appender name="CONSOLE-WARN" class="org.apache.log4j.ConsoleAppender">
<param name="follow" value="true"/>
<param name="target" value="System.err"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%7r] %6p - %30.60c - %m \n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="WARN"/>
</filter>
</appender>

<!-- Output only events with level DEBUG to console. See org.apache.log4j.Level.DEBUG -->
<appender name="CONSOLE-DEBUG" class="org.apache.log4j.ConsoleAppender">
<param name="follow" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%7r] %6p - %30.60c - %m \n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="DEBUG"/>
<param name="LevelMax" value="DEBUG"/>
</filter>
</appender>

<!-- Output only events with level TRACE to console. See org.apache.log4j.Level.TRACE -->
<appender name="CONSOLE-TRACE" class="org.apache.log4j.ConsoleAppender">
<param name="follow" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%7r] %6p - %30.60c - %m \n"/>
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="TRACE"/>
<param name="LevelMax" value="TRACE"/>
</filter>
</appender>

<!-- Output all events to console -->
<appender name="CONSOLE-ALL" class="org.apache.log4j.ConsoleAppender">
<param name="follow" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%7r] %6p - %30.60c - %m \n"/>
</layout>
</appender>

<!-- Show events with level at least ERROR in UI -->
<appender name="DIALOG" class="com.intellij.diagnostic.DialogAppender">
<!-- DialogAppender does nothing with event which level is less then ERROR so there is no need to pass them to DialogAppender -->
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="ERROR"/>
</filter>
</appender>

<!-- Log all events to idea.log file. Maintain number of logs and file sizes. -->
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="MaxFileSize" value="1Mb"/>
<param name="MaxBackupIndex" value="12"/>
<param name="File" value="$LOG_DIR$/idea.log"/>
<param name="Encoding" value="UTF-8"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%7r] %6p - %30.60c - %m \n"/>
</layout>
</appender>

<!-- Log all events to continuous.log file. Note that file is overridden on each application start -->
<appender name="CONTINUOUS_FILE" class="org.apache.log4j.FileAppender">
<param name="File" value="$LOG_DIR$/continuous.log"/>
<param name="Encoding" value="UTF-8"/>
<param name="append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%7r] %6p - %30.60c - %m \n"/>
</layout>
</appender>

<!-- Log events to mpsvcs.log file -->
<appender name="FILE-VCS" class="org.apache.log4j.RollingFileAppender">
<param name="MaxFileSize" value="2Mb"/>
<param name="MaxBackupIndex" value="5"/>
<param name="file" value="$LOG_DIR$/mpsvcs.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%7r] %6p - %30.60c - %m \n"/>
</layout>
</appender>

<!-- Additionally log MPS specific vcs events to mpsvcs.log -->
<category name="jetbrains.mps.vcs">
<priority value="INFO"/>
<appender-ref ref="FILE-VCS"/>
</category>

<!-- Additionally log IntelliJ Platform vcs events to mpsvcs.log -->
<category name="com.intellij.openapi.vcs">
<priority value="INFO"/>
<appender-ref ref="FILE-VCS"/>
</category>

<category name="de.q60" additivity="true">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE-ALL"/>
</category>

<category name="org.modelix" additivity="true">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE-ALL"/>
</category>

<!--
Template category for debugging:
Set required logger prefix and choose appropriate appender.
Set required priority: TRACE, DEBUG, INFO, WARN, ERROR etc (See org.apache.log4j.Level).
Choose required debug appender or add your own.
-->
<!--
<category name="logger.prefix">
<priority value="TRACE"/>
<appender-ref ref="CONSOLE-WARN"/>
<appender-ref ref="CONSOLE-DEBUG"/>
<appender-ref ref="CONSOLE-TRACE"/>
<appender-ref ref="CONSOLE-ALL"/>
<appender-ref ref="CONTINUOUS_FILE" />
</category>
-->

<root>
<priority value="INFO"/>
<appender-ref ref="DIALOG"/>
<appender-ref ref="FILE"/>
<!-- For quick debug -->
<!--<appender-ref ref="CONSOLE-ALL" />-->
<appender-ref ref="CONSOLE-WARN"/>
<!--<appender-ref ref="CONSOLE-DEBUG"/>-->
<!--<appender-ref ref="CONSOLE-TRACE"/>-->
<!--<appender-ref ref="CONTINUOUS_FILE" />-->
</root>
</log4j:configuration>
15 changes: 15 additions & 0 deletions docker/helper/modelix-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

MPS_VERSION=$( ./helper/mps-version.sh )
VERSION_FILE="../modelix.version"

if [ -f "VERSION_FILE" ]; then
MODELIX_VERSION=$(cat ${VERSION_FILE})
else
MODELIX_VERSION="${MPS_VERSION}-$(date +"%Y%m%d%H%M")-SNAPSHOT"
echo "$MODELIX_VERSION" > ${VERSION_FILE}
fi

echo "${MODELIX_VERSION}"
14 changes: 14 additions & 0 deletions docker/helper/mps-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# assumes to be executed in the docker folder

set -e

MPS_VERSION=$(cat "../gradle/mps.versions.toml" | grep "mpsbase =" | cut -d " " -f3 | tr -d "\"")


if [ -z "${MPS_VERSION}" ]; then
echo "Error: Unable to read MPS version from gradle toml"
exit 1
fi

echo "${MPS_VERSION}"
11 changes: 11 additions & 0 deletions docker/helper/patch-branding.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

# patch branding.jar to not show EULA and data sharing agreement at startup

unzip -d /branding /projector/ide/lib/branding.jar
(
cd /branding
sed -i.bak -E "s/JetBrains s.r.o./Modelix/" idea/IdeaApplicationInfo.xml
rm idea/IdeaApplicationInfo.xml.bak
zip -r /branding.zip ./*
)
Loading

0 comments on commit 56c359d

Please sign in to comment.