From dd4155ee92dfdd2b0fa85248b65bbfe3526a6446 Mon Sep 17 00:00:00 2001 From: Evgeny Grigorenko Date: Fri, 3 Nov 2023 16:22:53 +0100 Subject: [PATCH 1/3] Add Dockerfile, update runPluginStarter.sh, and CI workflow Added Dockerfile to create a containerized environment with pre-installed dependencies for running the plugin. This change will ensure ease of use and consistency across different host systems. Updated runPluginStarter.sh to add default values and better error handling for arguments. This will improve the script's usability and robustness. Updated GitHub Actions workflow (build.yml) to include building and pushing of Docker images to the GitHub Container Registry. This allows continuous delivery and deployment of changes made to the Dockerfile and the plugin. --- Dockerfile | 32 ++++++++++++++++ ide-former-plugin/.github/workflows/build.yml | 32 ++++++++++++++++ ide-former-plugin/runPluginStarter.sh | 38 ++++++++++++++++++- 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..601f7ed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM ubuntu:20.04 + +# Install Java +RUN apt-get update && apt-get install -y \ + openjdk-11-jdk \ + && java -version + +# Install Git +RUN apt-get install -y \ + git \ + && git --version + +# Install Python3 and pip3 +RUN apt-get update && apt-get install -y \ + python3 \ + python3-pip \ + python3-setuptools \ + python3-wheel \ + && python3 --version + +# Disable gradle daemon +ENV GRADLE_OPTS "-Dorg.gradle.daemon=false" + +# Copy the plugin +COPY ide-former-plugin /ide-former-plugin + +# prebuild the plugin with gradle +RUN cd /ide-former-plugin && ./gradlew buildPlugin + +ENTRYPOINT ["bash", "/ide-former-plugin/runPluginStarter.sh"] + +CMD [] \ No newline at end of file diff --git a/ide-former-plugin/.github/workflows/build.yml b/ide-former-plugin/.github/workflows/build.yml index d92b382..c41acaa 100644 --- a/ide-former-plugin/.github/workflows/build.yml +++ b/ide-former-plugin/.github/workflows/build.yml @@ -1,6 +1,9 @@ name: Gradle Build on: [push, pull_request] +branches: + only: + - master jobs: build: @@ -18,3 +21,32 @@ jobs: - uses: gradle/gradle-build-action@v2.1.5 with: arguments: build --stacktrace + +# build docker container + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3.0.0 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: ${{ github.ref == 'refs/heads/master' }} + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/${{ github.repository }}/runner:latest,ghcr.io/${{ github.repository }}/runner:${{ github.sha }} + + + + diff --git a/ide-former-plugin/runPluginStarter.sh b/ide-former-plugin/runPluginStarter.sh index 72595fd..53e18c4 100755 --- a/ide-former-plugin/runPluginStarter.sh +++ b/ide-former-plugin/runPluginStarter.sh @@ -7,4 +7,40 @@ if uname -s | grep -iq cygwin ; then PWD=$(cygpath -w "$PWD") fi -"$DIR/gradlew" -p "$DIR" runIdeAssistantPlugin -Prunner=ide-server -PpathToProject="$1" -PserverHost="$2" -PserverPort="$3" \ No newline at end of file +# check number of arguments +if [ $# -gt 3 ]; then + echo "Illegal number of parameters" + echo "Usage: runPluginStarter.sh " + echo "\t - path to the project to be opened in IDE, default is the plugin itself" + echo "\t - host of the server to connect to, default is localhost" + echo "\t - port of the server to connect to, default is 8080" + echo "" + echo "Examples:" + echo "\t./runPluginStarter.sh /project" + echo "\t./runPluginStarter.sh /project localhost 9080" + exit 1 +fi + +# set default values +if [ -z "$1" ]; then + echo "No path to project specified. Using the plugin itself at $DIR" + PATH_TO_PROJECT="$DIR" +else + PATH_TO_PROJECT=$1 +fi + +if [ -z "$2" ]; then + echo "No server host specified. Using 127.0.0.1" + SERVER_HOST="127.0.0.1" +else + SERVER_HOST=$2 +fi + +if [ -z "$3" ]; then + echo "No server port specified. Using 8080" + SERVER_PORT="8080" +else + SERVER_PORT=$3 +fi + +"$DIR/gradlew" -p "$DIR" runIdeAssistantPlugin -Prunner=ide-server -PpathToProject="$PATH_TO_PROJECT" -PserverHost="$SERVER_HOST" -PserverPort="$SERVER_PORT" \ No newline at end of file From 50e1dce83fcd0181d34101d697cf71cb6bdbc955 Mon Sep 17 00:00:00 2001 From: Evgeny Grigorenko Date: Fri, 3 Nov 2023 16:29:19 +0100 Subject: [PATCH 2/3] Move actions to the root as otherwise they are invisible to GitHub Actions --- {ide-former-plugin/.github => .github}/workflows/build.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {ide-former-plugin/.github => .github}/workflows/build.yml (100%) diff --git a/ide-former-plugin/.github/workflows/build.yml b/.github/workflows/build.yml similarity index 100% rename from ide-former-plugin/.github/workflows/build.yml rename to .github/workflows/build.yml From f1fdb5267c111f5272cac2a5d6cd427a2ac0ebf4 Mon Sep 17 00:00:00 2001 From: Evgeny Grigorenko Date: Fri, 3 Nov 2023 16:34:26 +0100 Subject: [PATCH 3/3] Fix Actions definition --- .github/workflows/build.yml | 34 +++++++++++++++++++++------------- Dockerfile | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c41acaa..f9e5b74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,18 @@ -name: Gradle Build +name: Build & Push + +on: + push: + branches: + - main + pull_request: + branches: + - main + +# cancel workflow if there is already one running +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true -on: [push, pull_request] -branches: - only: - - master jobs: build: @@ -16,13 +25,11 @@ jobs: with: java-version: 17 distribution: liberica - - name: Gradle Wrapper Validation - uses: gradle/wrapper-validation-action@v1.0.4 - - uses: gradle/gradle-build-action@v2.1.5 - with: - arguments: build --stacktrace + - name: Build plugin + run: ./gradlew buildPlugin + working-directory: ide-former-plugin -# build docker container + # build docker container docker: runs-on: ubuntu-latest @@ -43,9 +50,10 @@ jobs: with: context: . file: ./Dockerfile - push: ${{ github.ref == 'refs/heads/master' }} - platforms: linux/amd64,linux/arm64 + push: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }} + platforms: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && 'linux/amd64,linux/arm64' || 'linux/amd64' }} tags: ghcr.io/${{ github.repository }}/runner:latest,ghcr.io/${{ github.repository }}/runner:${{ github.sha }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/runner:latest diff --git a/Dockerfile b/Dockerfile index 601f7ed..1855ef5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:20.04 # Install Java RUN apt-get update && apt-get install -y \ - openjdk-11-jdk \ + openjdk-17-jdk \ && java -version # Install Git