From 358dcd6211d14f30d06f4fb7e041722c72f10328 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:25:27 +0530 Subject: [PATCH 01/14] Delete bin directory --- bin/build | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100755 bin/build diff --git a/bin/build b/bin/build deleted file mode 100755 index b5ca59a5..00000000 --- a/bin/build +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -exu - -# brew install maven # for macosx -mvn package # creates target/demo.war -# Move the artifact into pkg so we do not have to send the whole target file -# to the docker build context. We will dockerignore target because it contains -# other build files that bloats the upload context sent to docker. -mkdir -p pkg -mv target/demo.war pkg/demo.war - -docker build -t demo-java . From f1c8f5b9fb2c66f4025c084cc67bfee83088c53e Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:25:48 +0530 Subject: [PATCH 02/14] Delete .dockerignore --- .dockerignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 0fa92a0d..00000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.ufo From fc118091a04dfa7e6963a3ef4d0d9e7f219c5033 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:26:09 +0530 Subject: [PATCH 03/14] Delete README.md --- README.md | 90 ------------------------------------------------------- 1 file changed, 90 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index d5a751a3..00000000 --- a/README.md +++ /dev/null @@ -1,90 +0,0 @@ -# Demo Java Web App - -[![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com) - -Simple java project demos how to build a war file to be deployed on a Tomcat server. - -## Build - -The build script uses `mvn package` to produce a demo.war file and then bundles it with a Docker image that runs Tomcat. Usage: - - bin/build - -## What happened - -* mvn package was ran and the `target/demo.war` was moved into `pkg/demo.war` -* a docker image was built which copied the `pkg/demo.war` to `/usr/local/tomcat/webapps/demo.war`. Check out the [Dockerfile](Dockerfile) for details. - -Here's an example of some things to check after running the build script: - - $ ls pkg/demo.war - pkg/demo.war - $ docker images - REPOSITORY TAG IMAGE ID CREATED SIZE - demo-java latest 88092dfb7325 6 minutes ago 591MB - tomcat 8.5 a92c139758db 2 weeks ago 558MB - $ - -## Source Url Mapping - -The app is a small demo of a java servlet app. Here's the source code to url mapping: - -Source | Url ---- | --- -src/main/java/Hello.java | localhost:8080/demo/Hello -src/main/webapp/index.jsp | localhost:8080/demo/index.jsp - -## Run - -Here are the summarized commands to run and test that Tomcat is serving the war file: - - docker run --rm -p 8080:8080 -d demo-java - docker exec -ti $(docker ps -ql) bash - curl localhost:8080/demo/Hello - curl localhost:8080/demo/index.jsp - exit - docker stop $(docker ps -ql) - -Then you can hit the the [HOSTNAME]:8080/demo/Hello and to verify that Tomcat is servering the demo.war file. You should see an html page that says "Hello World". The output should look similar: - - $ docker run --rm -p 8080:8080 -d demo-java - 2ba7323481fa5c4068b90f2edf38555d9551303e9c2e4c27137ab0545688555b - $ docker exec -ti $(docker ps -ql) bash - root@2ba7323481fa:/usr/local/tomcat# curl localhost:8080/demo/Hello -

Hello World Hello.java

- root@2ba7323481fa:/usr/local/tomcat# curl localhost:8080/demo/index.jsp - - -

Hello World index.jsp!

- - - root@2ba7323481fa:/usr/local/tomcat# exit - exit - $ docker stop $(docker ps -ql) - 2ba7323481fa - $ docker ps -a - CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES - $ - -## Usage with UFO - -The ufo branch of this project provides an additional demo that takes the war artifact, builds a Docker image and deploys it to ECS. For details please check out that branch: [ufo](https://github.com/tongueroo/demo-java/tree/ufo). For more details on ufo check out the [official ufo docs](http://ufoships.com/). - -## Initial Generation - -Here are some notes on the initial generation of the project. The initial files and project structure was generated with the `mvn archetype:generate` command. Note, you do not have to run the command it is just noted here for posterity. More info: [Creating a webapp](https://maven.apache.org/plugins-archives/maven-archetype-plugin-1.0-alpha-7/examples/webapp.html) and [Introduction to the Standard Directory Layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html). - -Change were made like adding a simple [Hello.java](src/main/java/Hello.java) Serlvet class. - -The original command was: - - mvn archetype:generate \ - -DinteractiveMode=false \ - -DgroupId=com.domain \ - -DartifactId=demo \ - -DarchetypeArtifactId=maven-archetype-webapp - -## Dependencies - -* docker: `brew install docker` -* maven: `brew install maven` From 8b06336c770059c1d6089cf8bf70626a1824b1f4 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:26:54 +0530 Subject: [PATCH 04/14] Delete Dockerfile --- Dockerfile | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 9c40fcde..00000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM tomcat:8.5 -MAINTAINER Tung Nguyen - -# Debugging tools: A few ways to handle debugging tools. -# Trade off is a slightly more complex volume mount vs keeping the image size down. -RUN apt-get update && \ - apt-get install -y \ - net-tools \ - tree \ - vim && \ - rm -rf /var/lib/apt/lists/* && apt-get clean && apt-get purge - -RUN echo "export JAVA_OPTS=\"-Dapp.env=staging\"" > /usr/local/tomcat/bin/setenv.sh -COPY pkg/demo.war /usr/local/tomcat/webapps/demo.war - -EXPOSE 8080 -CMD ["catalina.sh", "run"] From 794987a87958cf6d05c2665a5e52713209bd6212 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:37:58 +0530 Subject: [PATCH 05/14] Create Jenkinsfile --- Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..7d9716bb --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,10 @@ +pipeline { + agent { docker { image 'maven:3.3.3' } } + stages { + stage('build') { + steps { + sh 'mvn --version' + } + } + } +} From cbbedb8f3892a859df2394f072fc5cf0cf4a5ec1 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:51:58 +0530 Subject: [PATCH 06/14] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7d9716bb..f84e8b7d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,5 @@ pipeline { - agent { docker { image 'maven:3.3.3' } } + agent any stages { stage('build') { steps { From 3ed7ce45917c2c62f35416539bab8ec2e556c33d Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:55:21 +0530 Subject: [PATCH 07/14] Update Jenkinsfile --- Jenkinsfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f84e8b7d..edd0c9c9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,14 @@ pipeline { - agent any + agent { + docker { + image 'maven:3.8.1-adoptopenjdk-11' + args '-v /root/.m2:/root/.m2' + } + } stages { - stage('build') { + stage('Build') { steps { - sh 'mvn --version' + sh 'mvn -B -DskipTests clean package' } } } From 879781f96ba935dd220f39eab6d769c2819e2282 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 13:59:33 +0530 Subject: [PATCH 08/14] Update Jenkinsfile --- Jenkinsfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index edd0c9c9..7d9716bb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,9 @@ pipeline { - agent { - docker { - image 'maven:3.8.1-adoptopenjdk-11' - args '-v /root/.m2:/root/.m2' - } - } + agent { docker { image 'maven:3.3.3' } } stages { - stage('Build') { + stage('build') { steps { - sh 'mvn -B -DskipTests clean package' + sh 'mvn --version' } } } From f99a5057853ee2caea65e39ee3cdfd25d521b1fa Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:00:35 +0530 Subject: [PATCH 09/14] Update Jenkinsfile --- Jenkinsfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7d9716bb..edd0c9c9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,14 @@ pipeline { - agent { docker { image 'maven:3.3.3' } } + agent { + docker { + image 'maven:3.8.1-adoptopenjdk-11' + args '-v /root/.m2:/root/.m2' + } + } stages { - stage('build') { + stage('Build') { steps { - sh 'mvn --version' + sh 'mvn -B -DskipTests clean package' } } } From bdb973f26925295d46f2e43ec92106d65d7645e0 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:00:14 +0530 Subject: [PATCH 10/14] Update Jenkinsfile --- Jenkinsfile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index edd0c9c9..8dea22ec 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,8 +8,23 @@ pipeline { stages { stage('Build') { steps { - sh 'mvn -B -DskipTests clean package' + sh 'mvn clean package' } } + post { + success { + // we only worry about archiving the jar file if the build steps are successful + archiveArtifacts(artifacts: '**/target/*.jar', allowEmptyArchive: true) + } + } + + stage('test'){ + steps{ + sh 'mvn clean test' + } + } + + + } } From ca71365909b82c1a723a45e4110b13521a72d0a6 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:00:57 +0530 Subject: [PATCH 11/14] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8dea22ec..8d6d9d18 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,14 +10,14 @@ pipeline { steps { sh 'mvn clean package' } - } + post { success { // we only worry about archiving the jar file if the build steps are successful archiveArtifacts(artifacts: '**/target/*.jar', allowEmptyArchive: true) } } - + } stage('test'){ steps{ sh 'mvn clean test' From 2484f6a87ef503e957c2fc547eee546239e8df4d Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:02:13 +0530 Subject: [PATCH 12/14] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8d6d9d18..506d0847 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { post { success { // we only worry about archiving the jar file if the build steps are successful - archiveArtifacts(artifacts: '**/target/*.jar', allowEmptyArchive: true) + archiveArtifacts(artifacts: '**/target/*.war', allowEmptyArchive: true) } } } From ee4f1a1d736ae33edd049c3cc9b53f2f1c00aed8 Mon Sep 17 00:00:00 2001 From: vaishrevankar Date: Thu, 14 Jul 2022 14:35:44 +0530 Subject: [PATCH 13/14] added .github folder --- .github/workflows | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows diff --git a/.github/workflows b/.github/workflows new file mode 100644 index 00000000..956b2d89 --- /dev/null +++ b/.github/workflows @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + From 0edb7a4392e35ba32b1a5674063feba21182b932 Mon Sep 17 00:00:00 2001 From: vaishrevankar <55649564+vaishrevankar@users.noreply.github.com> Date: Thu, 14 Jul 2022 14:37:57 +0530 Subject: [PATCH 14/14] Update workflows --- .github/workflows | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows b/.github/workflows index 956b2d89..3fdb0ea4 100644 --- a/.github/workflows +++ b/.github/workflows @@ -5,7 +5,6 @@ jobs: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - name: Check out repository code uses: actions/checkout@v3