From 2e36004a245cf9aacda3b5e016eadd55230a085c Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sat, 1 Jun 2024 20:19:48 +0100 Subject: [PATCH 1/7] Create Dockerfile --- Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000000..45f015480b2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# First stage: Build stage +FROM schoolofdevops/maven:spring AS build + +WORKDIR /app + + +# Copy the source code and build the application +COPY . . +RUN mvn package + +# Second stage: Runtime stage +FROM openjdk:17-jdk-slim + +WORKDIR /app + +# Copy the built jar file from the build stage +COPY --from=build /app/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar + +EXPOSE 8080 + +CMD ["java", "-jar", "/run/petclinic.jar"] From f7ca613fdd269d42a619d5478dc85fb9e5512b25 Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 2 Jun 2024 09:44:17 +0100 Subject: [PATCH 2/7] Update Dockerfile --- Dockerfile | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45f015480b2..678479d8f16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,13 @@ -# First stage: Build stage -FROM schoolofdevops/maven:spring AS build +FROM schoolofdevops/maven:spring WORKDIR /app - -# Copy the source code and build the application COPY . . -RUN mvn package - -# Second stage: Runtime stage -FROM openjdk:17-jdk-slim -WORKDIR /app - -# Copy the built jar file from the build stage -COPY --from=build /app/target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar +RUN mvn package && \ + mv target/spring-petclinic-2.3.1.BUILD-SNAPSHOT.jar /run/petclinic.jar EXPOSE 8080 -CMD ["java", "-jar", "/run/petclinic.jar"] +CMD java -jar /run/petclinic.jar + From ef249443caf34443b968a68477467cb6ae3e1f31 Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 2 Jun 2024 09:57:22 +0100 Subject: [PATCH 3/7] Create manifest.yml --- manifest.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 manifest.yml diff --git a/manifest.yml b/manifest.yml new file mode 100644 index 00000000000..0f88f56840c --- /dev/null +++ b/manifest.yml @@ -0,0 +1,37 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mavenwebappdeployment +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: mavenwebapp + template: + metadata: + name: mavenwebapppod + labels: + app: mavenwebapp + spec: + containers: + - name: mavenwebappcontainer + image: willywan/pet_app + imagePullPolicy: Always + ports: + - containerPort: 8080 +--- +apiVersion: v1 +kind: Service +metadata: + name: mavenwebappsvc +spec: + type: LoadBalancer + selector: + app: mavenwebapp + ports: + - port: 80 + targetPort: 8080 +... From 66cbbfe08679f05723c763cd3f84a7423135d22e Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 30 Jun 2024 08:51:32 +0100 Subject: [PATCH 4/7] Create maven.yml --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000000..b3f47a88e68 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From b585997e7bfa76a96500b804b7fc7e1ffa5ee863 Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 30 Jun 2024 08:54:23 +0100 Subject: [PATCH 5/7] Update maven.yml --- .github/workflows/maven.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b3f47a88e68..852ca24a8e1 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -13,6 +13,8 @@ on: branches: [ "master" ] pull_request: branches: [ "master" ] + commit: + branches: [ "master" ] jobs: build: From a1b860b5f3fdefc85a752552a4f9375d6b563865 Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 30 Jun 2024 08:58:36 +0100 Subject: [PATCH 6/7] Update readme.md From 58749899a6ef38ea3a8ed7c44baf9fc22a9b4086 Mon Sep 17 00:00:00 2001 From: William-eng <63299223+William-eng@users.noreply.github.com> Date: Sun, 30 Jun 2024 09:00:25 +0100 Subject: [PATCH 7/7] Rename maven.yml to ci.yml --- .github/workflows/{maven.yml => ci.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{maven.yml => ci.yml} (100%) diff --git a/.github/workflows/maven.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/workflows/maven.yml rename to .github/workflows/ci.yml