diff --git a/ohtu_demo5/.gitlab-ci.yml b/ohtu_demo5/.gitlab-ci.yml new file mode 100755 index 0000000000000000000000000000000000000000..28f23cca7a177930f9bfc27e9555f6e1e6b344ff --- /dev/null +++ b/ohtu_demo5/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: openjdk:latest + +build: + stage: build + script: + - javac SiteGen.java + +test: + stage: test + script: + - javac -cp "./junit-platform-console-standalone-1.8.1.jar" SiteGenTest.java SiteGen.java + - java -jar junit-platform-console-standalone-1.8.1.jar -cp "." -c SiteGenTest + +pages: + stage: deploy + script: + - javac SiteGen.java + - java SiteGen + artifacts: + paths: + - public + only: + - main \ No newline at end of file diff --git a/ohtu_demo5/README.md b/ohtu_demo5/README.md new file mode 100755 index 0000000000000000000000000000000000000000..129963a34b1829747d229c046ae8f13e9dd9bfc0 --- /dev/null +++ b/ohtu_demo5/README.md @@ -0,0 +1,2 @@ +# ohtu_demo5 + diff --git a/ohtu_demo5/cicd-test-main/.gitlab-ci.yml b/ohtu_demo5/cicd-test-main/.gitlab-ci.yml new file mode 100755 index 0000000000000000000000000000000000000000..da3137b2d3461e0aa17e267848c6cdeece1b0bcc --- /dev/null +++ b/ohtu_demo5/cicd-test-main/.gitlab-ci.yml @@ -0,0 +1,23 @@ +image: openjdk:latest + +build: + stage: build + script: + - javac SiteGen.java + +test: + stage: test + script: + - javac -cp "./junit-platform-console-standalone-1.8.1.jar" SiteGenTest.java SiteGen.java + - java -jar junit-platform-console-standalone-1.8.1.jar -cp "." -c SiteGenTest + +pages: + stage: deploy + script: + - javac SiteGen.java + - java SiteGen + artifacts: + paths: + - public + only: + - main diff --git a/ohtu_demo5/cicd-test-main/README.md b/ohtu_demo5/cicd-test-main/README.md new file mode 100755 index 0000000000000000000000000000000000000000..7b6fb2eb6057fbdbb5b2bf5da14045245514f059 --- /dev/null +++ b/ohtu_demo5/cicd-test-main/README.md @@ -0,0 +1,19 @@ +# DEVOPS demonstration + +Build your own CI/CD pipeline to the Gitlab environment through following steps: + +- Create new project to either UTU gitlab https://gitlab.utu.fi/ or Gitlab.com ​​https://gitlab.com/users/sign_in if you don’t have an UTU account +- Use the project template as a basis for your project +- The CI/CD pipeline should fail at the testing phase; read the console logs for all the phases and see what goes wrong +- Create new branch to investigate the situation; verify that the pipeline still fails +- Fix the situation by modifying the Java source code file based on the unit testing report found from the CI/CD console log +- When the testing phase goes green, merge the branch to the main branch +- The resulting web page generated by the Java application should now be deployed to the Gitlab Pages; Access the web pages via Gitlab setting and give public access to the resulting web site +- Read through the .gitlab-ci.yml file and try to understand what each line does +- Prepare to demonstrate you CI/CD pipeline and explain how it works + +Note: Each step can be done using the Gitlab online tools and editors + + + + diff --git a/ohtu_demo5/cicd-test-main/SiteGen.java b/ohtu_demo5/cicd-test-main/SiteGen.java new file mode 100755 index 0000000000000000000000000000000000000000..9d777ae3773c6731075973995e40fd6af3b46cae --- /dev/null +++ b/ohtu_demo5/cicd-test-main/SiteGen.java @@ -0,0 +1,27 @@ +import java.nio.file.*; +import java.util.*; +import java.util.stream.*; + +class SiteGen { + static String siteTitle = "My favorite movies"; + + static List movieList = List.of( + "Star Wars", + "Star Trek", + "Battlestar Galactica" + ); + + static String htmlString = + "" + + "" + siteTitle + "" + + "" + + "

" + siteTitle + "

" + + "" + + "" + + ""; + + public static void main(String args[]) throws Exception { + Files.createDirectory(Paths.get("public/")); + Files.write(Paths.get("public/index.html"), htmlString.getBytes()); + } +} diff --git a/ohtu_demo5/cicd-test-main/SiteGenTest.java b/ohtu_demo5/cicd-test-main/SiteGenTest.java new file mode 100755 index 0000000000000000000000000000000000000000..4e7dc08b6c45a7e435a591852efb8c9a736a25dd --- /dev/null +++ b/ohtu_demo5/cicd-test-main/SiteGenTest.java @@ -0,0 +1,13 @@ +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class SiteGenTest { + + @Test + public void testHtmlString() { + String correctHtml = "My favorite movies

My favorite movies

"; + Assertions.assertEquals(correctHtml, SiteGen.htmlString); + } + +} + diff --git a/ohtu_demo5/cicd-test-main/junit-platform-console-standalone-1.8.1.jar b/ohtu_demo5/cicd-test-main/junit-platform-console-standalone-1.8.1.jar new file mode 100755 index 0000000000000000000000000000000000000000..7a904901b242d782feec6ba9f62f16d8a2cd2038 Binary files /dev/null and b/ohtu_demo5/cicd-test-main/junit-platform-console-standalone-1.8.1.jar differ