diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 0fa92a0d..00000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -target -.ufo diff --git a/.github/workflows b/.github/workflows new file mode 100644 index 00000000..3fdb0ea4 --- /dev/null +++ b/.github/workflows @@ -0,0 +1,17 @@ +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 "🔎 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 }}." + 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"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..506d0847 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,30 @@ +pipeline { + agent { + docker { + image 'maven:3.8.1-adoptopenjdk-11' + args '-v /root/.m2:/root/.m2' + } + } + stages { + stage('Build') { + steps { + sh 'mvn clean package' + } + + post { + success { + // we only worry about archiving the jar file if the build steps are successful + archiveArtifacts(artifacts: '**/target/*.war', allowEmptyArchive: true) + } + } + } + stage('test'){ + steps{ + sh 'mvn clean test' + } + } + + + + } +} 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` 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 .