From 2d596b50117ab128586ca32a5f0deda16f939940 Mon Sep 17 00:00:00 2001 From: Johannes Faltermeier Date: Tue, 26 Sep 2023 08:57:22 +0200 Subject: [PATCH] Allow to build blueprint based on local Theia sources Contributed on behalf of STMicroelectronics Signed-off-by: Johannes Faltermeier --- .github/workflows/publish-theia-builder.yml | 38 +++++++++++++++++++ docker/local-theia-build/adduser | 16 ++++++++ docker/local-theia-build/entrypoint | 41 +++++++++++++++++++++ local-theia-build.Dockerfile | 34 +++++++++++++++++ local-theia-build.md | 32 ++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 .github/workflows/publish-theia-builder.yml create mode 100644 docker/local-theia-build/adduser create mode 100755 docker/local-theia-build/entrypoint create mode 100644 local-theia-build.Dockerfile create mode 100644 local-theia-build.md diff --git a/.github/workflows/publish-theia-builder.yml b/.github/workflows/publish-theia-builder.yml new file mode 100644 index 000000000..2698626d5 --- /dev/null +++ b/.github/workflows/publish-theia-builder.yml @@ -0,0 +1,38 @@ +name: Publish Theia Builder Docker Image + +on: + push: + branches: + - jf/local-theia-build + workflow_dispatch: + inputs: + tag: + description: The image's tag + required: true + default: next + +jobs: + build: + name: Build and push theia builder image to Github Packages + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Log in to the Github Container registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: ./docker/local-theia-build + file: local-theia-build.Dockerfile + push: true + tags: | + ghcr.io/${{ github.repository }}/blueprint-theia-builder:latest + # ghcr.io/${{ github.repository }}/blueprint-theia-builder:${{ github.event.inputs.tag }} \ No newline at end of file diff --git a/docker/local-theia-build/adduser b/docker/local-theia-build/adduser new file mode 100644 index 000000000..77d26f1dc --- /dev/null +++ b/docker/local-theia-build/adduser @@ -0,0 +1,16 @@ +#!/usr/bin/expect -f +set timeout 10 + +spawn npm adduser --registry http://localhost:4873/ +match_max 100000 + +expect "Username" +send "dummy-user\r" + +expect "Password" +send "dummy-p4ssword\r" + +expect "Email: (this IS public)" +send "dummy@us.er\r" + +expect "Logged in on http://localhost:4873/." \ No newline at end of file diff --git a/docker/local-theia-build/entrypoint b/docker/local-theia-build/entrypoint new file mode 100755 index 000000000..8ae7d995d --- /dev/null +++ b/docker/local-theia-build/entrypoint @@ -0,0 +1,41 @@ +#!/bin/sh +set -e + +if [ "$#" -eq 0 ] +then + REGISTRY=http://localhost:4873/ + echo "Launching Verdaccio and adding dummy user" + verdaccio & + VERDACCIO_PID=$! + while ! nc -z localhost 4873; do + sleep 1 + done + expect -f /tmp/adduser +else + REGISTRY=$1 + if [[ -z "${AUTH_TOKEN}" ]] + then + echo "Updating npmrc" + echo //${$REGISTRY}:_authToken=${AUTH_TOKEN} >> /.npmrc + fi +fi + +echo "Building Theia" +cd /tmp/theia +yarn config set registry $REGISTRY +yarn +yarn build + + +echo "PUBLISH $PUBLISH" +if [ "$PUBLISH" = "true" ] +then + echo "Publishing Theia..." + yarn publish:local:next --registry $REGISTRY +fi + +if [ "$#" -eq 0 ] +then + echo "Waiting..." + wait $VERDACCIO_PID +fi diff --git a/local-theia-build.Dockerfile b/local-theia-build.Dockerfile new file mode 100644 index 000000000..fbbdbb76c --- /dev/null +++ b/local-theia-build.Dockerfile @@ -0,0 +1,34 @@ +# Prerequisites +# https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#prerequisites +FROM node:18.17.0 +RUN apt-get update && \ + apt-get install -y \ + make \ + gcc \ + pkg-config \ + build-essential \ + libx11-dev \ + libxkbfile-dev \ + libsecret-1-dev && \ + # install local npm registry and helper tools + yarn global add verdaccio && \ + apt-get install -y expect-dev netcat-openbsd && \ + mkdir /tmp/verdaccio && \ + # create some common default directories/files with write access for any user + touch /.yarnrc && chmod 777 /.yarnrc && \ + touch /.npmrc && chmod 777 /.npmrc && \ + mkdir /.cache && chmod 777 /.cache && \ + mkdir /.yarn && chmod 777 /.yarn && \ + mkdir /.npm && chmod 777 /.npm + +# Set storage location for verdaccio +ENV VERDACCIO_STORAGE_PATH /tmp/verdaccio +ENV PUBLISH true + +# Switch to expected workdir +WORKDIR /tmp + +COPY adduser /tmp/adduser +COPY entrypoint /tmp/entrypoint + +ENTRYPOINT ["/tmp/entrypoint"] \ No newline at end of file diff --git a/local-theia-build.md b/local-theia-build.md new file mode 100644 index 000000000..0331b5ef8 --- /dev/null +++ b/local-theia-build.md @@ -0,0 +1,32 @@ +# Local Theia Build + +## Prerequisites + +All required tools to build Theia locally can be found + +```sh +docker build -t local-theia-builder -f local-theia-build.Dockerfile ./docker/local-theia-build +``` + +## Local Build + +```sh +# switch to your checked out theia code +cd ~/git/theia + +# optional: if you built Theia locally before, you may want to clean local changes in order to get a reproducible clean build +# git clean -xfd + +# export the location where you want the local registry to store your results +export VERDACCIO_STORAGE_PATH=~/tmp/verdaccio + +# build Theia with our builder image +docker run --rm \ + -v ${PWD}:/tmp/theia \ + -v ${VERDACCIO_STORAGE_PATH}:/tmp/verdaccio \ + -u $(id -u ${USER}):$(id -g ${USER}) \ + -p=4873:4873 \ + local-theia-builder + # or use the published version + # ghcr.io/eclipse-theia/theia-blueprint/blueprint-theia-builder:latest +```