From a7bc5151b0e96d8017511aebf561b52faca77f30 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 28 Aug 2023 09:47:57 +0000 Subject: [PATCH 1/5] Task-187--craft a dockerfile --- Dockerfile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bd29e77 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM openjdk:17 +EXPOSE 8080 +ADD ./target/spring-petclinic-3.1.0-SNAPSHOT.jar spring-petclinic-3.1.0-SNAPSHOT.jar +ENTRYPOINT ["java", "-jar", "/spring-petclinic-3.1.0-SNAPSHOT.jar"] + From dcc99783abbdbcf56e26c42679ba3973c2da065a Mon Sep 17 00:00:00 2001 From: Naman Jain <56442920+NamanJain1902@users.noreply.github.com> Date: Mon, 28 Aug 2023 16:28:23 +0530 Subject: [PATCH 2/5] Create azure-webapps-java-jar.yml --- .github/workflows/azure-webapps-java-jar.yml | 79 ++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/azure-webapps-java-jar.yml diff --git a/.github/workflows/azure-webapps-java-jar.yml b/.github/workflows/azure-webapps-java-jar.yml new file mode 100644 index 0000000..ae4aeb1 --- /dev/null +++ b/.github/workflows/azure-webapps-java-jar.yml @@ -0,0 +1,79 @@ +# This workflow will build and push a Java application to an Azure Web App when a commit is pushed to your default branch. +# +# This workflow assumes you have already created the target Azure App Service web app. +# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-linux +# +# To configure this workflow: +# +# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal. +# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials +# +# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. +# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret +# +# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the JAVA_VERSION environment variable below. +# +# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions +# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples + +name: Build and deploy JAR app to Azure Web App + +env: + AZURE_WEBAPP_NAME: nj-streamline-solutions # set this to the name of your Azure Web App + JAVA_VERSION: '17' # set this to the Java version to use + DISTRIBUTION: openjdk # set this to the Java distribution + +on: + push: + branches: [ "feature-192-github-setup-and-vm-configuration" ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Java version + uses: actions/setup-java@v3.0.0 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.DISTRIBUTION }} + cache: 'maven' + + - name: Build with Maven + run: mvn clean install + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v3 + with: + name: java-app + path: '${{ github.workspace }}/target/*.jar' + + deploy: + permissions: + contents: none + runs-on: ubuntu-latest + needs: build + environment: + name: 'Development' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v3 + with: + name: java-app + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }} + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: '*.jar' From 78b83cca58d830dcff72f6d59632d4acbec5eb0c Mon Sep 17 00:00:00 2001 From: Naman Jain <56442920+NamanJain1902@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:15:30 +0530 Subject: [PATCH 3/5] update: dockerfile updated --- .github/workflows/azure-webapps-java-jar.yml | 99 +++++++------------- 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/.github/workflows/azure-webapps-java-jar.yml b/.github/workflows/azure-webapps-java-jar.yml index ae4aeb1..03120fd 100644 --- a/.github/workflows/azure-webapps-java-jar.yml +++ b/.github/workflows/azure-webapps-java-jar.yml @@ -1,79 +1,48 @@ -# This workflow will build and push a Java application to an Azure Web App when a commit is pushed to your default branch. -# -# This workflow assumes you have already created the target Azure App Service web app. -# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-linux -# -# To configure this workflow: -# -# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal. -# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials -# -# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. -# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret -# -# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the JAVA_VERSION environment variable below. -# -# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions -# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy -# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples +# 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 -name: Build and deploy JAR app to Azure Web App + -env: - AZURE_WEBAPP_NAME: nj-streamline-solutions # set this to the name of your Azure Web App - JAVA_VERSION: '17' # set this to the Java version to use - DISTRIBUTION: openjdk # set this to the Java distribution +# 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: [ "feature-192-github-setup-and-vm-configuration" ] - workflow_dispatch: + branches: [ "main" ] + pull_request: + branches: [ "main" ] -permissions: - contents: read + jobs: build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up Java version - uses: actions/setup-java@v3.0.0 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.DISTRIBUTION }} - cache: 'maven' - - - name: Build with Maven - run: mvn clean install - - name: Upload artifact for deployment job - uses: actions/upload-artifact@v3 - with: - name: java-app - path: '${{ github.workspace }}/target/*.jar' + - deploy: - permissions: - contents: none runs-on: ubuntu-latest - needs: build - environment: - name: 'Development' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v3 - with: - name: java-app + - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: ${{ env.AZURE_WEBAPP_NAME }} - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: '*.jar' + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean install -D skipTests --file pom.xml + + + + - name: Build Docker Image + run: docker build -t ayush0909/github-actions-docker-java-app . \ No newline at end of file From f457a0b87b095516c4798ac3d11697083f877369 Mon Sep 17 00:00:00 2001 From: Naman Jain <56442920+NamanJain1902@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:25:49 +0530 Subject: [PATCH 4/5] update: docker file updated --- .github/workflows/azure-webapps-java-jar.yml | 59 ++++++++++---------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/azure-webapps-java-jar.yml b/.github/workflows/azure-webapps-java-jar.yml index 03120fd..3ec92ea 100644 --- a/.github/workflows/azure-webapps-java-jar.yml +++ b/.github/workflows/azure-webapps-java-jar.yml @@ -1,48 +1,49 @@ -# 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 +[9:17 PM] Chopra, Vyom SBOBNG-PTIY/TAF - - -# 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 +name: Ready the VM after PR merge on: - push: - branches: [ "main" ] + pull_request: - branches: [ "main" ] + + types: + + - closed jobs: - build: - + deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn clean install -D skipTests --file pom.xml + + - name: Check out code + + uses: actions/checkout@v2 - - name: Build Docker Image - run: docker build -t ayush0909/github-actions-docker-java-app . \ No newline at end of file + - name: Deploy to VM + + env: + + VM_IP: "52.141.91.23" + + VM_USERNAME: "part347" + + VM_PASSWORD: "w@!@#$5431fsaW" + + run: | + + sudo apt update + + sudo apt install -y openssh-client + + echo "$VM_PASSWORD" | sshpass -e ssh -o StrictHostKeyChecking=no "$VM_USERNAME@$VM_IP" "sudo apt update && sudo apt install -y git maven prometheus && sudo apt install -y docker.io" From 79105bc7b24673c02bfc1571c807c88400bae317 Mon Sep 17 00:00:00 2001 From: Naman Jain <56442920+NamanJain1902@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:26:26 +0530 Subject: [PATCH 5/5] update: docker file updated --- .github/workflows/azure-webapps-java-jar.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/azure-webapps-java-jar.yml b/.github/workflows/azure-webapps-java-jar.yml index 3ec92ea..9304b78 100644 --- a/.github/workflows/azure-webapps-java-jar.yml +++ b/.github/workflows/azure-webapps-java-jar.yml @@ -1,5 +1,3 @@ -[9:17 PM] Chopra, Vyom SBOBNG-PTIY/TAF - name: Ready the VM after PR merge