Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update java-spring-boot example #232

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Examples/java-spring-boot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM openjdk:11

RUN apt-get update && \
apt-get install -y openjdk-11-jdk
FROM openjdk:21-jdk-slim

COPY spring-boot-web-service/build/libs/spring-boot-web-service-0.0.1-SNAPSHOT.jar .

Expand Down
36 changes: 17 additions & 19 deletions Examples/java-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,69 @@ runs inside the SGX enclave. For more information on Spring Boot, please visit h
* Tested on:
- Type: Azure Confidential Computing SGX Virtual Machine
- Size: Standard DC1s v3 (1 vCPU, 8 GiB memory)
- OS: Linux (Ubuntu 20.04)
- OS: Linux (Ubuntu 24.04)

* Install the OpenJDK 11 package so that Gradle can consume the files:
* Install the OpenJDK 21 package so that Gradle can consume the files:

```bash
$ sudo apt-get install openjdk-11-jdk
sudo apt-get install openjdk-21-jdk
```

* Follow the installation guide at https://gradle.org/install/ to install Gradle v7.6.
* Follow the installation guide at https://gradle.org/install/ to install Gradle v8.12.

## Build and run graminized Docker image

1. Build a project using Gradle:

```bash
$ (cd spring-boot-web-service/ && gradle build)
(cd spring-boot-web-service/ && gradle build)
```

2. Build Docker image:

```bash
$ docker build -t openjdk-11-java-spring-boot .
docker build -t openjdk-21-java-spring-boot .
```

3. Clean up files that will be no longer used:

```bash
$ (cd spring-boot-web-service/ && gradle clean)
(cd spring-boot-web-service/ && gradle clean)
```

4. Graminize the Docker image (this step can take some time!):

```bash
$ (cd ../.. && ./gsc build openjdk-11-java-spring-boot \
Examples/java-spring-boot/java-spring-boot.manifest \
-c <PATH-TO-CONFIG-FILE>)
(cd ../.. && ./gsc build openjdk-21-java-spring-boot \
Examples/java-spring-boot/java-spring-boot.manifest)
```

5. Sign the graminized Docker image:

```bash
$ (cd ../.. && ./gsc sign-image openjdk-11-java-spring-boot \
<PATH-TO-KEY-FILE> \
-c <PATH-TO-CONFIG-FILE>)
(cd ../.. && ./gsc sign-image openjdk-21-java-spring-boot \
<PATH-TO-KEY-FILE>)
```

6. Run graminized image (the application may take a while to load):

* On the default port set to 8080:

```bash
$ docker run --rm --device=/dev/sgx_enclave \
docker run --rm --device=/dev/sgx_enclave \
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
-p 8080:8080 \
-d gsc-openjdk-11-java-spring-boot
-d gsc-openjdk-21-java-spring-boot
```

* On a customized port using an environment variable, e.g. 9080:

```bash
$ docker run --rm --device=/dev/sgx_enclave \
docker run --rm --device=/dev/sgx_enclave \
-v /var/run/aesmd/aesm.socket:/var/run/aesmd/aesm.socket \
-e SERVER_PORT=9080 \
-p 9080:9080 \
-d gsc-openjdk-11-java-spring-boot
-d gsc-openjdk-21-java-spring-boot
```


Expand All @@ -82,11 +80,11 @@ $ (cd ../.. && ./gsc sign-image openjdk-11-java-spring-boot \
Boot application":

```bash
$ wget -qO- localhost:<port>
wget -qO- localhost:<port>
```

8. To stop the graminized container with Spring-Boot application, run the command:

```bash
$ docker stop <containerID>
docker stop <containerID>
```