From 3f69527c01c1404dade9ef9660bc35a5321bb758 Mon Sep 17 00:00:00 2001 From: Flook Peter Date: Tue, 23 Jul 2024 11:39:51 +0800 Subject: [PATCH 1/3] Add in docker image for maestro server with github action --- .github/workflows/build.yml | 32 +++++++++++++++++++++++++++ maestro-server/Dockerfile | 11 ++++++++++ maestro-server/README.md | 44 ++++++++++++++++++++++++++++++++++++- maestro-server/build.gradle | 6 +++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 maestro-server/Dockerfile diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..7ce9a147 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Build Docker image + +on: + push: + branches: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Gradle build with cache + uses: burrunan/gradle-cache-action@v1 + with: + arguments: "bootJar" + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: "{{ defaultContext }}:maestro-server" + platforms: linux/amd64,linux/arm64 + push: true + tags: datacatering/maestro:0.1.0 diff --git a/maestro-server/Dockerfile b/maestro-server/Dockerfile new file mode 100644 index 00000000..9c47b647 --- /dev/null +++ b/maestro-server/Dockerfile @@ -0,0 +1,11 @@ +FROM openjdk:21-slim as builder +ARG JAR_FILE=build/libs/maestro-server.jar +COPY ${JAR_FILE} application.jar +RUN java -Djarmode=layertools -jar application.jar extract + +FROM openjdk:21-slim +COPY --from=builder dependencies/ ./ +COPY --from=builder snapshot-dependencies/ ./ +COPY --from=builder spring-boot-loader/ ./ +COPY --from=builder application/ ./ +ENTRYPOINT ["java", "-Djava.security.manager=allow", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/maestro-server/README.md b/maestro-server/README.md index 117b2929..b2e943a9 100644 --- a/maestro-server/README.md +++ b/maestro-server/README.md @@ -1,3 +1,45 @@ -Maestro Server +# Maestro Server =================================== This module includes a Springboot app implementation of Maestro server. + +## Docker + +### Run + +Assuming you have cockroachdb already setup and running ([otherwise check these steps](#cockroachdb)): + +```shell +docker run \ + -p 8080:8080 \ + -e CONDUCTOR_CONFIGS_JDBCURL=jdbc:postgresql://cockroachdb:26257/maestro \ + -e CONDUCTOR_CONFIGS_JDBCUSERNAME=root \ + datacatering/maestro:0.1.0 +``` + +### Build + +Build the JAR file and Docker image via: + +```shell +./gradlew bootJar +docker build -t maestro-server:0.1 . +``` + +#### CockroachDB + +Spin up cockroachdb either yourself or via [insta-infra](https://github.com/data-catering/insta-infra), with database +`maestro` created. + +```shell +./run.sh cockroach +./run.sh -c cockroach +CREATE DATABASE maestro; +``` + +```shell +docker run \ + -p 8080:8080 \ + -e CONDUCTOR_CONFIGS_JDBCURL=jdbc:postgresql://cockroachdb:26257/maestro \ + -e CONDUCTOR_CONFIGS_JDBCUSERNAME=root \ + maestro-server:0.1 +``` diff --git a/maestro-server/build.gradle b/maestro-server/build.gradle index 9960119a..6bee12df 100644 --- a/maestro-server/build.gradle +++ b/maestro-server/build.gradle @@ -32,6 +32,12 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.+' } +bootJar { + layered { + enabled = true + } +} + bootRun { jvmArgs += ["-Djava.security.manager=allow"] } From bee7bfd57d0d9f2a379104297a693d8a90a89c11 Mon Sep 17 00:00:00 2001 From: Flook Peter Date: Tue, 23 Jul 2024 11:49:25 +0800 Subject: [PATCH 2/3] Set context and dockerfile in build-push-action --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ce9a147..5577d9ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,8 @@ jobs: - name: Build and push uses: docker/build-push-action@v6 with: - context: "{{ defaultContext }}:maestro-server" + context: "./maestro-server" + dockerfile: "./maestro-server/Dockerfile" platforms: linux/amd64,linux/arm64 push: true tags: datacatering/maestro:0.1.0 From b9e2fb7104042f165130175710256be7cdb0c051 Mon Sep 17 00:00:00 2001 From: Flook Peter Date: Tue, 23 Jul 2024 13:22:08 +0800 Subject: [PATCH 3/3] Clean up README instructions for docker image --- maestro-server/README.md | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/maestro-server/README.md b/maestro-server/README.md index b2e943a9..00c3ecf8 100644 --- a/maestro-server/README.md +++ b/maestro-server/README.md @@ -1,45 +1,37 @@ -# Maestro Server +Maestro Server =================================== This module includes a Springboot app implementation of Maestro server. ## Docker -### Run - -Assuming you have cockroachdb already setup and running ([otherwise check these steps](#cockroachdb)): - -```shell -docker run \ - -p 8080:8080 \ - -e CONDUCTOR_CONFIGS_JDBCURL=jdbc:postgresql://cockroachdb:26257/maestro \ - -e CONDUCTOR_CONFIGS_JDBCUSERNAME=root \ - datacatering/maestro:0.1.0 -``` - ### Build Build the JAR file and Docker image via: ```shell ./gradlew bootJar -docker build -t maestro-server:0.1 . +docker build -t maestro-server:0.1 maestro-server ``` -#### CockroachDB - -Spin up cockroachdb either yourself or via [insta-infra](https://github.com/data-catering/insta-infra), with database -`maestro` created. +### Run -```shell -./run.sh cockroach -./run.sh -c cockroach -CREATE DATABASE maestro; -``` +Assuming you have CockroachDB already setup and running ([otherwise check these steps](#cockroachdb)): ```shell docker run \ + --name maestro \ + --network host \ -p 8080:8080 \ - -e CONDUCTOR_CONFIGS_JDBCURL=jdbc:postgresql://cockroachdb:26257/maestro \ + -e CONDUCTOR_CONFIGS_JDBCURL=jdbc:postgresql://localhost:26257/maestro \ -e CONDUCTOR_CONFIGS_JDBCUSERNAME=root \ maestro-server:0.1 ``` + +#### CockroachDB + +Spin up CockroachDB with `maestro` database via the below commands: + +```shell +docker run -d -p 26257:26257 --name cockroachdb cockroachdb/cockroach:v24.1.0 start-single-node --insecure +docker exec cockroachdb cockroach sql --insecure --execute 'CREATE DATABASE maestro;' +```