diff --git a/.github/workflows/java-cicd.yml b/.github/workflows/java-cicd.yml new file mode 100644 index 00000000..e45e98e2 --- /dev/null +++ b/.github/workflows/java-cicd.yml @@ -0,0 +1,506 @@ +name: Java CI Pipeline multiple java service per repo + +on: + push: + branches: [main, dev, uat, prod] + paths: + - '**/microservice-one/**' + - '**/microservice-two/**' + pull_request: + branches: [main, dev, uat, prod] + paths: + - '**/microservice-one/**' + - '**/microservice-two/**' + workflow_dispatch: + +env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + API_TOKEN_GITHUB: ${{ secrets.GH_PAT_DEST_REPO1 }} +jobs: + check_changes: + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + outputs: + microservice_one_changed: ${{ steps.detect.outputs.microservice_one_changed }} + microservice_two_changed: ${{ steps.detect.outputs.microservice_two_changed }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect folder changes + id: detect + run: | + echo "Checking for changes in microservices..." + CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }}) + echo "Changed files:" + echo "$CHANGED_FILES" + + if echo "$CHANGED_FILES" | grep -q '^microservice-one/'; then + echo "microservice_one_changed=true" >> $GITHUB_OUTPUT + else + echo "microservice_one_changed=false" >> $GITHUB_OUTPUT + fi + + if echo "$CHANGED_FILES" | grep -q '^microservice-two/'; then + echo "microservice_two_changed=true" >> $GITHUB_OUTPUT + else + echo "microservice_two_changed=false" >> $GITHUB_OUTPUT + fi + + microservice-one-job-ci: + needs: check_changes + if: needs.check_changes.outputs.microservice_one_changed == 'true' + runs-on: ubuntu-latest + env: + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + steps: + - name: Checkout only microservice-one + uses: actions/checkout@v4 + with: + repository: ashishrlad/simple-java-project + token: ${{ secrets.GITHUB_TOKEN }} + path: . + sparse-checkout: microservice-one/ + sparse-checkout-cone-mode: true + fetch-depth: 1 + ssh-strict: true + ssh-user: git + persist-credentials: true + clean: true + fetch-tags: false + show-progress: true + lfs: false + submodules: false + set-safe-directory: true + + # SonarQube Scan + #- name: SonarQube Scan + #run: | + #mvn clean verify sonar:sonar \ + #-Dsonar.projectKey=${{ vars.PROJECT_KEY }} \ + #-Dsonar.projectName=${{ vars.PROJECT_NAME }} \ + #-Dsonar.host.url=http://13.233.71.33:9000 \ + #-Dsonar.token=${{ secrets.SONAR_TOKEN }} + + # Build Java with Maven in container + - name: Build with Maven + run: | + cd microservice-one/ + docker run --rm \ + -v ${{ github.workspace }}:/app \ + -w /app \ + maven:3.9.4-eclipse-temurin-17 \ + mvn clean package + + # Docker Build + - name: Build Docker Image + run: | + IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV + docker build -t $IMAGE_NAME . + + # Trivy Security Scan + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: '${{ env.IMAGE_NAME }}' + format: 'table' + exit-code: '0' + ignore-unfixed: true + severity: 'CRITICAL,HIGH' + output: 'trivy-report.txt' + + # Send Email Report + #- name: Email Trivy Report + #uses: dawidd6/action-send-mail@v3 + #with: + #server_address: smtp.gmail.com + #server_port: 587 + #username: ${{ secrets.MAIL_USERNAME }} + #password: ${{ secrets.MAIL_PASSWORD }} + #subject: "Trivy Report - ${{ github.repository }} (${{ github.ref_name }})" + #body: "Attached Trivy scan report for image built from ${{ github.ref_name }}." + #to: ashishrlad@gmail.com + #from: ${{ secrets.MAIL_USERNAME }} + #attachments: trivy-report.txt + + # docker push image to dockerhub + - name: Docker Push to docker hub Repository' + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker push ${IMAGE_NAME} + + deploy-MS1-main: + if: github.ref == 'refs/heads/main' + needs: microservice-one-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + environment: production # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-one + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + cat manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-one/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS1-prod: + if: github.ref == 'refs/heads/prod' + needs: microservice-one-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + environment: prod # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-one + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + cat manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-one/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS1-uat: + if: github.ref == 'refs/heads/uat' + needs: microservice-one-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + environment: uat # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-one + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + cat manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-one/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS1-dev: + if: github.ref == 'refs/heads/dev' + needs: microservice-one-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-one:${{ github.ref_name }}-${{ github.run_id }} + environment: dev # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-one + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + cat manifest-repo/microservice-one/manifest-repo/microservice-one/${{ github.ref_name }}/microservice-one-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-one/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + microservice-two-job-ci: + needs: check_changes + if: needs.check_changes.outputs.microservice_two_changed == 'true' + runs-on: ubuntu-latest + env: + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + steps: + - name: Checkout only microservice-two + uses: actions/checkout@v4 + with: + repository: ashishrlad/simple-java-project + token: ${{ secrets.GITHUB_TOKEN }} + path: . + sparse-checkout: microservice-two/ + sparse-checkout-cone-mode: true + fetch-depth: 1 + ssh-strict: true + ssh-user: git + persist-credentials: true + clean: true + fetch-tags: false + show-progress: true + lfs: false + submodules: false + set-safe-directory: true + + # SonarQube Scan + #- name: SonarQube Scan + #run: | + #mvn clean verify sonar:sonar \ + #-Dsonar.projectKey=${{ vars.PROJECT_KEY }} \ + #-Dsonar.projectName=${{ vars.PROJECT_NAME }} \ + #-Dsonar.host.url=http://13.233.71.33:9000 \ + #-Dsonar.token=${{ secrets.SONAR_TOKEN }} + + # Build Java with Maven in container + - name: Build with Maven + run: | + cd microservice-two/ + docker run --rm \ + -v ${{ github.workspace }}:/app \ + -w /app \ + maven:3.9.4-eclipse-temurin-17 \ + mvn clean package + + # Docker Build + - name: Build Docker Image + run: | + IMAGE_NAME=${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV + docker build -t $IMAGE_NAME . + + # Trivy Security Scan + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: '${{ env.IMAGE_NAME }}' + format: 'table' + exit-code: '0' + ignore-unfixed: true + severity: 'CRITICAL,HIGH' + output: 'trivy-report.txt' + + # Send Email Report + #- name: Email Trivy Report + #uses: dawidd6/action-send-mail@v3 + #with: + #server_address: smtp.gmail.com + #server_port: 587 + #username: ${{ secrets.MAIL_USERNAME }} + #password: ${{ secrets.MAIL_PASSWORD }} + #subject: "Trivy Report - ${{ github.repository }} (${{ github.ref_name }})" + #body: "Attached Trivy scan report for image built from ${{ github.ref_name }}." + #to: ashishrlad@gmail.com + #from: ${{ secrets.MAIL_USERNAME }} + #attachments: trivy-report.txt + + # docker push image to dockerhub + - name: Docker Push to docker hub Repository' + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker push ${IMAGE_NAME} + + deploy-MS2-main: + if: github.ref == 'refs/heads/main' + needs: microservice-two-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + environment: main # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-two + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + cat manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-two/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS2-prod: + if: github.ref == 'refs/heads/prod' + needs: microservice-two-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + environment: prod # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-two + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + cat manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-two/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS2-uat: + if: github.ref == 'refs/heads/uat' + needs: microservice-two-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + environment: uat # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-two + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + cat manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-two/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force + + deploy-MS2-dev: + if: github.ref == 'refs/heads/dev' + needs: microservice-two-job-ci + runs-on: ubuntu-latest + env: + CHANGED_FOLDER: ${{ needs.check_changes.outputs.changed_folder }} + IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/microservice-two:${{ github.ref_name }}-${{ github.run_id }} + environment: dev # This enforces manual approval + steps: + - name: Docker pull + run: | + echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin + docker pull $IMAGE_NAME + - name: Checkout menifeast repository + uses: actions/checkout@v4 + with: + repository: ashishrlad/config_repo_samplejava + token: ${{ secrets.GH_PAT_DEST_REPO1 }} + path: manifest-repo/microservice-two + persist-credentials: true + - name: "Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + git config --global user.name "ashishrlad" + git config --global user.email "ashishrlad@gmail.com" + sed -i "s|image:.*|image: ${IMAGE_NAME}|" manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + cat manifest-repo/microservice-two/manifest-repo/microservice-two/${{ github.ref_name }}/microservice-two-deployment.yml + - name: "Push Updated Image Tag for ${{ github.ref_name }} git branch" + run: | + cd manifest-repo/microservice-two/manifest-repo/ + git remote set-url origin https://x-access-token:${{ secrets.GH_PAT_DEST_REPO1 }}@github.com/ashishrlad/config_repo_samplejava.git + git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} + git config --global init.defaultBranch ${{ github.ref_name }} + git add . + git commit -m "Updated image tag in ${{ github.ref_name }} manifeastfile" + git push origin ${{ github.ref_name }} --force \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..25cce237 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM eclipse-temurin:17 + +# Create working directory +WORKDIR /app + +# Copy WAR file to working directory +COPY target/works-with-heroku-1.0.war app.war + +# Download Jetty runner +RUN curl -Lo jetty-runner.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-runner/9.3.3.v20150827/jetty-runner-9.3.3.v20150827.jar + +# Expose default Jetty port +EXPOSE 80 + +# Run Jetty with WAR file +ENTRYPOINT ["java", "-jar", "jetty-runner.jar", "app.war"] diff --git a/microservice-one/.gitignore b/microservice-one/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/microservice-one/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/microservice-one/Dockerfile b/microservice-one/Dockerfile new file mode 100644 index 00000000..25cce237 --- /dev/null +++ b/microservice-one/Dockerfile @@ -0,0 +1,16 @@ +FROM eclipse-temurin:17 + +# Create working directory +WORKDIR /app + +# Copy WAR file to working directory +COPY target/works-with-heroku-1.0.war app.war + +# Download Jetty runner +RUN curl -Lo jetty-runner.jar https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-runner/9.3.3.v20150827/jetty-runner-9.3.3.v20150827.jar + +# Expose default Jetty port +EXPOSE 80 + +# Run Jetty with WAR file +ENTRYPOINT ["java", "-jar", "jetty-runner.jar", "app.war"] diff --git a/microservice-one/Procfile b/microservice-one/Procfile new file mode 100644 index 00000000..e69342e0 --- /dev/null +++ b/microservice-one/Procfile @@ -0,0 +1 @@ +web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war diff --git a/microservice-one/README.md b/microservice-one/README.md new file mode 100644 index 00000000..fd0fd7b4 --- /dev/null +++ b/microservice-one/README.md @@ -0,0 +1,2 @@ +# Simple Java Project +This is a demo project that you can use with [Buddy Continuous Deployment](https://buddy.works). diff --git a/microservice-one/pom.xml b/microservice-one/pom.xml new file mode 100644 index 00000000..33942381 --- /dev/null +++ b/microservice-one/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + works.buddy.samples + works-with-heroku + 1.0 + war + + + + javax.servlet + servlet-api + 2.5 + provided + + + junit + junit + 4.13.2 + test + + + org.mockito + mockito-inline + 5.2.0 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + microservice-one/src/main/webapp + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + package + + copy + + + + + org.eclipse.jetty + jetty-runner + 9.3.3.v20150827 + jetty-runner.jar + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + + + diff --git a/microservice-one/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java b/microservice-one/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java new file mode 100644 index 00000000..8bf44228 --- /dev/null +++ b/microservice-one/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java @@ -0,0 +1,19 @@ +package works.buddy.samples; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +public class WorksWithHerokuServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + response.setStatus(404); + PrintWriter writer = response.getWriter(); + writer.print("Buddy Works with Heroku"); + writer.close(); + } +} diff --git a/microservice-one/src/main/webapp/WEB-INF/web.xml b/microservice-one/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..a68ccf59 --- /dev/null +++ b/microservice-one/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,20 @@ + + + + Works with Heroku + + + WorksWithHerokuServlet + works.buddy.samples.WorksWithHerokuServlet + + + + WorksWithHerokuServlet + / + + + diff --git a/microservice-one/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java b/microservice-one/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java new file mode 100644 index 00000000..e50b3137 --- /dev/null +++ b/microservice-one/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java @@ -0,0 +1,41 @@ +package works.buddy.samples; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +public class WorksWithHerokuServletTest { + + private WorksWithHerokuServlet servlet; + + @Mock + private HttpServletRequest request; + + @Mock + private HttpServletResponse response; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + servlet = new WorksWithHerokuServlet(); + } + + @Test + public void testDoGet() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(out); + when(response.getWriter()).thenReturn(writer); + + servlet.doGet(request, response); + assertEquals("Buddy Works with Heroku", new String( out.toByteArray(), "UTF-8")); + } +} \ No newline at end of file diff --git a/microservice-one/target/classes/works/buddy/samples/WorksWithHerokuServlet.class b/microservice-one/target/classes/works/buddy/samples/WorksWithHerokuServlet.class new file mode 100644 index 00000000..820ce3ff Binary files /dev/null and b/microservice-one/target/classes/works/buddy/samples/WorksWithHerokuServlet.class differ diff --git a/microservice-one/target/dependency/jetty-runner.jar b/microservice-one/target/dependency/jetty-runner.jar new file mode 100644 index 00000000..ad9a3915 Binary files /dev/null and b/microservice-one/target/dependency/jetty-runner.jar differ diff --git a/microservice-one/target/maven-archiver/pom.properties b/microservice-one/target/maven-archiver/pom.properties new file mode 100644 index 00000000..86e5fd06 --- /dev/null +++ b/microservice-one/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=works-with-heroku +groupId=works.buddy.samples +version=1.0 diff --git a/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..fb32e789 --- /dev/null +++ b/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +works/buddy/samples/WorksWithHerokuServlet.class diff --git a/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..295140ad --- /dev/null +++ b/microservice-one/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/ashishlad/Documents/simple-java-project/microservice-one/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java diff --git a/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..13ffe358 --- /dev/null +++ b/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +works/buddy/samples/WorksWithHerokuServletTest.class diff --git a/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..79ca6d30 --- /dev/null +++ b/microservice-one/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/ashishlad/Documents/simple-java-project/microservice-one/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java diff --git a/microservice-one/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml b/microservice-one/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml new file mode 100644 index 00000000..2d59bdac --- /dev/null +++ b/microservice-one/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/microservice-one/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt b/microservice-one/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt new file mode 100644 index 00000000..55ab665c --- /dev/null +++ b/microservice-one/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: works.buddy.samples.WorksWithHerokuServletTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.180 s -- in works.buddy.samples.WorksWithHerokuServletTest diff --git a/microservice-one/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class b/microservice-one/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class new file mode 100644 index 00000000..2f857d2e Binary files /dev/null and b/microservice-one/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class differ diff --git a/microservice-one/target/works-with-heroku-1.0.war b/microservice-one/target/works-with-heroku-1.0.war new file mode 100644 index 00000000..b6a2c473 Binary files /dev/null and b/microservice-one/target/works-with-heroku-1.0.war differ diff --git a/microservice-one/target/works-with-heroku-1.0/WEB-INF/WEB-INF/web.xml b/microservice-one/target/works-with-heroku-1.0/WEB-INF/WEB-INF/web.xml new file mode 100644 index 00000000..dd0495c9 --- /dev/null +++ b/microservice-one/target/works-with-heroku-1.0/WEB-INF/WEB-INF/web.xml @@ -0,0 +1,20 @@ + + + + Works with Heroku + + + WorksWithHerokuServlet + works.buddy.samples.WorksWithHerokuServlet + + + + WorksWithHerokuServlet + / + + + diff --git a/microservice-one/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class b/microservice-one/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class new file mode 100644 index 00000000..820ce3ff Binary files /dev/null and b/microservice-one/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class differ diff --git a/microservice-one/target/works-with-heroku-1.0/WEB-INF/web.xml b/microservice-one/target/works-with-heroku-1.0/WEB-INF/web.xml new file mode 100644 index 00000000..09fd5916 --- /dev/null +++ b/microservice-one/target/works-with-heroku-1.0/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + Works with Heroku + + + WorksWithHerokuServlet + works.buddy.samples.WorksWithHerokuServlet + + + + WorksWithHerokuServlet + / + + + + + + diff --git a/microservice-two/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java b/microservice-two/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java new file mode 100644 index 00000000..8bf44228 --- /dev/null +++ b/microservice-two/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java @@ -0,0 +1,19 @@ +package works.buddy.samples; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +public class WorksWithHerokuServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("text/plain"); + response.setStatus(404); + PrintWriter writer = response.getWriter(); + writer.print("Buddy Works with Heroku"); + writer.close(); + } +} diff --git a/microservice-two/src/main/webapp/WEB-INF/web.xml b/microservice-two/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..e336ff6b --- /dev/null +++ b/microservice-two/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + Works with Heroku + + + WorksWithHerokuServlet + works.buddy.samples.WorksWithHerokuServlet + + + + WorksWithHerokuServlet + / + + + diff --git a/microservice-two/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java b/microservice-two/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java new file mode 100644 index 00000000..e50b3137 --- /dev/null +++ b/microservice-two/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java @@ -0,0 +1,41 @@ +package works.buddy.samples; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +public class WorksWithHerokuServletTest { + + private WorksWithHerokuServlet servlet; + + @Mock + private HttpServletRequest request; + + @Mock + private HttpServletResponse response; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + servlet = new WorksWithHerokuServlet(); + } + + @Test + public void testDoGet() throws Exception { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(out); + when(response.getWriter()).thenReturn(writer); + + servlet.doGet(request, response); + assertEquals("Buddy Works with Heroku", new String( out.toByteArray(), "UTF-8")); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 19f98e41..2f405b68 100644 --- a/pom.xml +++ b/pom.xml @@ -1,55 +1,94 @@ - - - 4.0.0 - works.buddy.samples - works-with-heroku - 1.0 - war - - - javax.servlet - servlet-api - 2.5 - provided - - - junit - junit - 4.12 - test - - - org.mockito - mockito-all - 1.10.19 - test - - + + + 4.0.0 + works.buddy.samples + works-with-heroku + 1.0 + war + + + + javax.servlet + servlet-api + 2.5 + provided + + + junit + junit + 4.13.2 + test + + + org.mockito + mockito-inline + 5.2.0 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-war-plugin + 3.4.0 + + src/main/webapp + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + package + + copy + + + + + org.eclipse.jetty + jetty-runner + 9.3.3.v20150827 + jetty-runner.jar + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.3 - - - package - copy - - - - org.eclipse.jetty - jetty-runner - 9.3.3.v20150827 - jetty-runner.jar - - - - - - - - diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 1c789e35..e336ff6b 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -14,5 +14,5 @@ WorksWithHerokuServlet / - + diff --git a/target/classes/works/buddy/samples/WorksWithHerokuServlet.class b/target/classes/works/buddy/samples/WorksWithHerokuServlet.class new file mode 100644 index 00000000..e35dd438 Binary files /dev/null and b/target/classes/works/buddy/samples/WorksWithHerokuServlet.class differ diff --git a/target/dependency/jetty-runner.jar b/target/dependency/jetty-runner.jar new file mode 100644 index 00000000..ad9a3915 Binary files /dev/null and b/target/dependency/jetty-runner.jar differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 00000000..86e5fd06 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=works-with-heroku +groupId=works.buddy.samples +version=1.0 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..fb32e789 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +works/buddy/samples/WorksWithHerokuServlet.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..8ad0c9fd --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/ashishlad/Documents/simple-java-project/src/main/java/works/buddy/samples/WorksWithHerokuServlet.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..13ffe358 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +works/buddy/samples/WorksWithHerokuServletTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..79fceb0c --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +/home/ashishlad/Documents/simple-java-project/src/test/java/works/buddy/samples/WorksWithHerokuServletTest.java diff --git a/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml b/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml new file mode 100644 index 00000000..60625bda --- /dev/null +++ b/target/surefire-reports/TEST-works.buddy.samples.WorksWithHerokuServletTest.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt b/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt new file mode 100644 index 00000000..dc51f900 --- /dev/null +++ b/target/surefire-reports/works.buddy.samples.WorksWithHerokuServletTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: works.buddy.samples.WorksWithHerokuServletTest +------------------------------------------------------------------------------- +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.327 s -- in works.buddy.samples.WorksWithHerokuServletTest diff --git a/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class b/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class new file mode 100644 index 00000000..dc52fc01 Binary files /dev/null and b/target/test-classes/works/buddy/samples/WorksWithHerokuServletTest.class differ diff --git a/target/works-with-heroku-1.0.war b/target/works-with-heroku-1.0.war new file mode 100644 index 00000000..b433361b Binary files /dev/null and b/target/works-with-heroku-1.0.war differ diff --git a/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class b/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class new file mode 100644 index 00000000..820ce3ff Binary files /dev/null and b/target/works-with-heroku-1.0/WEB-INF/classes/works/buddy/samples/WorksWithHerokuServlet.class differ diff --git a/target/works-with-heroku-1.0/WEB-INF/web.xml b/target/works-with-heroku-1.0/WEB-INF/web.xml new file mode 100644 index 00000000..dd0495c9 --- /dev/null +++ b/target/works-with-heroku-1.0/WEB-INF/web.xml @@ -0,0 +1,20 @@ + + + + Works with Heroku + + + WorksWithHerokuServlet + works.buddy.samples.WorksWithHerokuServlet + + + + WorksWithHerokuServlet + / + + +