From 37103622903086f05da723649ecec11ea453f8af Mon Sep 17 00:00:00 2001 From: Yutaro Sakamoto Date: Mon, 25 Nov 2024 21:45:53 +0900 Subject: [PATCH] feat: build Dockerfile --- .github/workflows/server-app.yml | 2 +- server/app/Dockerfile | 15 +++++++++++++++ server/app/build.gradle.kts | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 server/app/Dockerfile diff --git a/.github/workflows/server-app.yml b/.github/workflows/server-app.yml index 457d98f..f0cfd84 100644 --- a/.github/workflows/server-app.yml +++ b/.github/workflows/server-app.yml @@ -29,7 +29,7 @@ jobs: java-version: "17" - name: Build with Gradle - run: ./gradlew bootJar + run: ./gradlew buildDockerImage #- name: Run tests # if: ${{ github.event.inputs.run_tests }} diff --git a/server/app/Dockerfile b/server/app/Dockerfile new file mode 100644 index 0000000..953e093 --- /dev/null +++ b/server/app/Dockerfile @@ -0,0 +1,15 @@ +# ベースイメージを指定 +FROM openjdk:17-jdk-alpine + +# 作業ディレクトリを作成 +WORKDIR /app + +# 依存関係のコピー +COPY lib /app/lib + +# アプリケーションのJARファイルをコピー +ARG JAR_FILE=build/libs/app.jar +COPY ${JAR_FILE} app.jar + +# アプリケーションを実行 +ENTRYPOINT ["java", "-cp", "app.jar:lib/*", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/server/app/build.gradle.kts b/server/app/build.gradle.kts index a6963bc..db2d942 100644 --- a/server/app/build.gradle.kts +++ b/server/app/build.gradle.kts @@ -15,6 +15,7 @@ val javaDir = "${project.projectDir}/src/main/java/cobol4j/aws/web/" val libDir = "${project.projectDir}/lib" val libLibcobjJar = "${libDir}/libcobj.jar" val javaPackage = "cobol4j.aws.web" +val dockerImageTag = "cobol4j-aws-web:latest" plugins { // Apply the application plugin to add support for building a CLI application in Java. @@ -158,7 +159,18 @@ tasks.register("buildCobol") { """) } + tasks.named("compileJava") { dependsOn("buildCobol") dependsOn("moveLibcobjJar") } + +tasks.register("buildDockerImage") { + dependsOn("compileJava") + + inputs.files( + file("Dockerfile"), + ) + + commandLine("sh", "-c", "docker build -t ${dockerImageTag} .") +} \ No newline at end of file