From adf467749a86f39b8e18f028d575c52722603ad2 Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 17:50:20 +0000 Subject: [PATCH 01/10] Download the Micronaut backend JAR --- .github/workflows/docker-image.yml | 31 +++++++++++++++++++++++++ .gitignore | 1 + pom.xml | 36 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 .gitignore create mode 100644 pom.xml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..469c0b5 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,31 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - uses: s4u/maven-settings-action@64e42c454dbd42ef6370ac8539685755aedd205b + with: + servers: | + [{ + "id": "github-playground-micronaut", + "username": "epsilonlabs", + "password": "${{ secrets.GH_TOKEN_READ_MICRONAUT }}" + }] + - name: Download the backend JAR + run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true && ls target/dependency + - name: Build the Docker image + run: docker build --tag playground-docker:$(date +%s) . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9049f3a --- /dev/null +++ b/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + + org.eclipse.epsilon.labs.playground + playground-docker + 1.0-SNAPSHOT + pom + + + + github-playground-micronaut + GitHub Epsilon Labs Playground Micronaut Apache Maven Packages + https://maven.pkg.github.com/epsilonlabs/playground-micronaut + + true + + + + + + UTF-8 + 17 + + + + + org.eclipse.epsilon.labs.playground.micronaut + http-server + 0.1-SNAPSHOT + all + + + + \ No newline at end of file From e88e51c1a3068b4db8266eb7e02f16812c8dad6a Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:07:18 +0000 Subject: [PATCH 02/10] Docker image now uses the Micronaut functions --- .github/workflows/docker-image.yml | 2 +- Dockerfile | 13 +++++-------- nginx.conf.template | 6 +++--- start.sh | 10 ++-------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 469c0b5..2675c14 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -28,4 +28,4 @@ jobs: - name: Download the backend JAR run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true && ls target/dependency - name: Build the Docker image - run: docker build --tag playground-docker:$(date +%s) . + run: docker build --tag playground-docker:micronaut . diff --git a/Dockerfile b/Dockerfile index 26571c0..87ddf1a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,5 @@ FROM bitnami/git AS git_clones -# Clone the Epsilon Playground repo that contains the back-end -RUN git clone --depth=1 https://github.com/epsilonlabs/playground - # Clone the Epsilon website repo that contains the front-end RUN git clone --depth=1 https://github.com/eclipse/epsilon-website epsilon @@ -20,17 +17,17 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* # Copy playground sources -COPY --from=git_clones /playground/ /playground/ COPY --from=git_clones /epsilon/mkdocs/docs/playground/ /etc/nginx/html/ -# Redirect /services/ URLs to the backend services running on ports 8001-8003 +# Create directory for playground all-in-one JAR +RUN mkdir -p /opt/playground +COPY ./target/dependency/http-server-*-all.jar /opt/playground/backend.jar + +# Redirect /services/ URLs to the backend services running on port 8080 ADD ./nginx.conf.template /etc/nginx.conf.template WORKDIR /playground -# Build fat jar with all services and dependencies -RUN mvn package - # Copy start script and make it executable ADD start.sh / RUN chmod +x /start.sh diff --git a/nginx.conf.template b/nginx.conf.template index 980753d..06662f6 100644 --- a/nginx.conf.template +++ b/nginx.conf.template @@ -2,14 +2,14 @@ server { listen ${PORT}; location /services/RunEpsilonFunction { - proxy_pass http://127.0.0.1:8001/; + proxy_pass http://127.0.0.1:8080/epsilon; } location /services/FlexmiToPlantUMLFunction { - proxy_pass http://127.0.0.1:8002/; + proxy_pass http://127.0.0.1:8080/flexmi2plantuml; } location /services/EmfaticToPlantUMLFunction { - proxy_pass http://127.0.0.1:8003/; + proxy_pass http://127.0.0.1:8080/emfatic2plantuml; } } diff --git a/start.sh b/start.sh index 0c8ea26..271124a 100644 --- a/start.sh +++ b/start.sh @@ -27,14 +27,8 @@ wait_for_service() { } # Functions for running Epsilon -java -cp target/org.eclipse.epsilon.playground.jar com.google.cloud.functions.invoker.runner.Invoker --target org.eclipse.epsilon.playground.RunEpsilonFunction --port 8001 & -wait_for_service Epsilon 127.0.0.1 8001 - -java -cp target/org.eclipse.epsilon.playground.jar com.google.cloud.functions.invoker.runner.Invoker --target org.eclipse.epsilon.playground.FlexmiToPlantUMLFunction --port 8002 & -wait_for_service Flexmi 127.0.0.1 8002 - -java -cp target/org.eclipse.epsilon.playground.jar com.google.cloud.functions.invoker.runner.Invoker --target org.eclipse.epsilon.playground.EmfaticToPlantUMLFunction --port 8003 & -wait_for_service Emfatic 127.0.0.1 8003 +java -jar /opt/playground/backend.jar & +wait_for_service Epsilon 127.0.0.1 8080 # nginx as frontend + reverse proxy envsubst < /etc/nginx.conf.template > /etc/nginx/conf.d/default.conf From afb083878bd4811f63603d40b589c50d2e850ef8 Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:17:19 +0000 Subject: [PATCH 03/10] Add README with instructions for local build --- README.md | 37 ++++++++++++++++++++++++++++++++----- docker-build.sh | 4 ++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100755 docker-build.sh diff --git a/README.md b/README.md index 989f767..bb16526 100644 --- a/README.md +++ b/README.md @@ -12,22 +12,47 @@ docker run -p 8000:80 eclipseepsilon/playground:latest ## Build and Run the Docker Image -If you prefer to build the image from source instead of fetching it from Docker Hub, clone the repository and use this command to build the image: +### Setting up token-based access to the playground-micronaut packages + +If you prefer to build the image from source instead of fetching it, first ensure that your `$HOME/.m2/settings.xml` has a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) that can read public repositories associated to the `github-playground-micronaut` server. + +The `settings.xml` file could look like this: + +```xml + + + + github-playground-micronaut + YOUR_GITHUB_USERNAME + YOUR_GITHUB_TOKEN + + + +``` + +### Building the image + +You can now clone the repository and use this command to build the image: ```shell -docker image build -t playground:latest . +./docker-build.sh ``` -and this command to run the image in a container: +### Running the image + +Use this command to run the image in a container: ```shell -docker run -p 8000:80 playground:latest +docker run -p 8000:80 playground:micronaut ``` Should you need to customise the port that `nginx` runs on, you can do so through the `PORT` environment variable (as required by Google Cloud Build): ```shell -docker run --env PORT=8020 -p 8000:8020 playground:latest +docker run --env PORT=8020 -p 8000:8020 playground:micronaut ``` ## Access the Epsilon Playground @@ -53,6 +78,8 @@ docker run -p 8000:80 -v :/etc/nginx/html playgr ``` Your front-end folder should contain an `index.html` file. A minimal alternative front-end that you can use as a starting point for developing your custom front-end is available in the `miniground` folder of [this repository](miniground). +Alternatively, you may want to use the [Docker image for the Micronaut-based backend](https://github.com/epsilonlabs/playground-micronaut/pkgs/container/playground-micronaut) directly, without using this image. + ## Publish to Docker Hub Run the following command to build a `linux/amd64` image (replace `x.y.z` with the actual version you wish to release) diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 0000000..ca10ece --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +mvn dependency:copy-dependencies -DexcludeTransitive=true +docker build -t playground-docker:micronaut . \ No newline at end of file From 72966183392a6919de1e69b89d2936cccb6f745e Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:29:16 +0000 Subject: [PATCH 04/10] Add workflow for pushing image to Github Packages --- ...ocker-image.yml => build-docker-image.yml} | 2 +- .github/workflows/push-docker-image.yml | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) rename .github/workflows/{docker-image.yml => build-docker-image.yml} (97%) create mode 100644 .github/workflows/push-docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/build-docker-image.yml similarity index 97% rename from .github/workflows/docker-image.yml rename to .github/workflows/build-docker-image.yml index 2675c14..09fea59 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,4 +1,4 @@ -name: Docker Image CI +name: Build Docker Image on: push: diff --git a/.github/workflows/push-docker-image.yml b/.github/workflows/push-docker-image.yml new file mode 100644 index 0000000..7e8ebb5 --- /dev/null +++ b/.github/workflows/push-docker-image.yml @@ -0,0 +1,61 @@ +name: Push Docker Image + +on: + push: + branches: [ "micronaut" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - uses: s4u/maven-settings-action@64e42c454dbd42ef6370ac8539685755aedd205b + with: + servers: | + [{ + "id": "github-playground-micronaut", + "username": "epsilonlabs", + "password": "${{ secrets.GH_TOKEN_READ_MICRONAUT }}" + }] + - name: Download the backend JAR + run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true && ls target/dependency + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true From 96e07c40aa02d5bd24f49d4be779f017e3564926 Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:35:03 +0000 Subject: [PATCH 05/10] Mention Epsilon email in image labels --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 87ddf1a..8b69018 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,9 @@ RUN git clone --depth=1 https://github.com/eclipse/epsilon-website epsilon FROM nginx:latest AS webapp +LABEL maintainer "epsilon.devs@gmail.com" +LABEL org.opencontainers.image.authors="epsilon.devs@gmail.com" + # Needed to avoid prompts blocking the build process ENV DEBIAN_FRONTEND=noninteractive From 42ff24ae6e84c6a8c65b5ac6e9b6c1aec15dc1fc Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:41:12 +0000 Subject: [PATCH 06/10] Mention EPL 2.0 license in image --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 8b69018..03093c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ FROM nginx:latest AS webapp LABEL maintainer "epsilon.devs@gmail.com" LABEL org.opencontainers.image.authors="epsilon.devs@gmail.com" +LABEL org.opencontainers.image.licenses="EPL-2.0" # Needed to avoid prompts blocking the build process ENV DEBIAN_FRONTEND=noninteractive From 047b56375d9136195c3b16799488fcac214b738f Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:46:53 +0000 Subject: [PATCH 07/10] Update README with GH Packages instructions --- README.md | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bb16526..74b9543 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # Dockerized Epsilon Playground -This is a dockerized version of the [Epsilon Playground](https://eclipse.org/epsilon/playground). +This is a Dockerized version of the [Epsilon Playground](https://eclipse.org/epsilon/playground). -## Fetch and Run the Docker Hub Image +## Fetch and Run the Image -Use this command to fetch the latest version of the Epsilon Playground image from Docker Hub and run it in a container: +Use this command to fetch the latest version of the Epsilon Playground image from Github Packages and run it in a container: ```shell -docker run -p 8000:80 eclipseepsilon/playground:latest +docker run --rm -p 8000:80 ghcr.io/epsilonlabs/playground-docker:micronaut ``` ## Build and Run the Docker Image @@ -46,13 +46,13 @@ You can now clone the repository and use this command to build the image: Use this command to run the image in a container: ```shell -docker run -p 8000:80 playground:micronaut +docker run -p 8000:80 playground-docker:micronaut ``` Should you need to customise the port that `nginx` runs on, you can do so through the `PORT` environment variable (as required by Google Cloud Build): ```shell -docker run --env PORT=8020 -p 8000:8020 playground:micronaut +docker run --env PORT=8020 -p 8000:8020 playground-docker:micronaut ``` ## Access the Epsilon Playground @@ -64,7 +64,7 @@ Once the container is up, go to http://localhost:8000 in your browser to access The dockerized version of the playground comes with the same set of examples as the [online version](https://eclipse.org/epsilon/playground). To start an instance with your own examples on the left hand side, use the following command, replacing `` with the **absolute** path of your `examples` folder. ```shell -docker run -p 8000:80 -v :/etc/nginx/html/examples playground:latest +docker run -p 8000:80 -v :/etc/nginx/html/examples playground-docker:micronaut ``` Your `examples` folder should contain an `examples.json` file with at least one example. A sample `examples` folder with a single example is provided [in this repository](examples) and more examples are available in the `examples` folder of [Epsilon's website repository](https://github.com/eclipse-epsilon/epsilon-website/tree/main/mkdocs/docs/playground/examples). @@ -74,25 +74,8 @@ Your `examples` folder should contain an `examples.json` file with at least one If you would like to use only the backend services and replace the front-end altogether, you can start an instance using the following command, replacing `` with the **absolute** path of your custom front-end folder. ```shell -docker run -p 8000:80 -v :/etc/nginx/html playground:latest +docker run -p 8000:80 -v :/etc/nginx/html playground-docker:micronaut ``` Your front-end folder should contain an `index.html` file. A minimal alternative front-end that you can use as a starting point for developing your custom front-end is available in the `miniground` folder of [this repository](miniground). Alternatively, you may want to use the [Docker image for the Micronaut-based backend](https://github.com/epsilonlabs/playground-micronaut/pkgs/container/playground-micronaut) directly, without using this image. - -## Publish to Docker Hub - -Run the following command to build a `linux/amd64` image (replace `x.y.z` with the actual version you wish to release) - -``` -docker buildx build --no-cache --platform linux/amd64 -t eclipseepsilon/playground:x.y.z . -docker tag eclipseepsilon/playground:x.y.z eclipseepsilon/playground:latest -``` - -And then push it to Docker Hub - -``` -docker push eclipseepsilon/playground:x.y.z -docker push eclipseepsilon/playground:latest -``` - From 02d8fa988834030fc7d7baa591ccba5b2c2b509e Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:47:30 +0000 Subject: [PATCH 08/10] Use Ubuntu 24 and prepare workflow for merging --- .github/workflows/push-docker-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push-docker-image.yml b/.github/workflows/push-docker-image.yml index 7e8ebb5..5a26231 100644 --- a/.github/workflows/push-docker-image.yml +++ b/.github/workflows/push-docker-image.yml @@ -2,7 +2,7 @@ name: Push Docker Image on: push: - branches: [ "micronaut" ] + branches: [ "main", "micronaut" ] env: REGISTRY: ghcr.io @@ -10,7 +10,7 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 permissions: contents: read packages: write From 5f030431a7468308ee9f764b34ba05768b394081 Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 19:55:22 +0000 Subject: [PATCH 09/10] Reduce image size: headless JRE is enough --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 03093c3..8ddbda8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ ENV PORT=80 # Install Python RUN apt-get update \ - && apt-get install -y python3-minimal maven tini netcat-traditional \ + && apt-get install -y python3-minimal openjdk-17-jre-headless tini netcat-traditional \ && rm -rf /var/lib/apt/lists/* # Copy playground sources From 0ccbb7b5638f164c6fa58887d144f59fe21629a5 Mon Sep 17 00:00:00 2001 From: Antonio Garcia-Dominguez Date: Mon, 2 Dec 2024 20:02:25 +0000 Subject: [PATCH 10/10] Remove unnecessary "ls" --- .github/workflows/build-docker-image.yml | 2 +- .github/workflows/push-docker-image.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 09fea59..07e39fd 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -26,6 +26,6 @@ jobs: "password": "${{ secrets.GH_TOKEN_READ_MICRONAUT }}" }] - name: Download the backend JAR - run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true && ls target/dependency + run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true - name: Build the Docker image run: docker build --tag playground-docker:micronaut . diff --git a/.github/workflows/push-docker-image.yml b/.github/workflows/push-docker-image.yml index 5a26231..587e23e 100644 --- a/.github/workflows/push-docker-image.yml +++ b/.github/workflows/push-docker-image.yml @@ -33,7 +33,7 @@ jobs: "password": "${{ secrets.GH_TOKEN_READ_MICRONAUT }}" }] - name: Download the backend JAR - run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true && ls target/dependency + run: mvn -B dependency:copy-dependencies -DexcludeTransitive=true - name: Log in to the Container registry uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 with: