From 3c058ebd95a73b13f5f411bf242f5e607087a3dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= <xpokorn8@fi.muni.cz>
Date: Mon, 10 Apr 2023 14:50:49 +0200
Subject: [PATCH] Pipeline testing per module + deployment

---
 README.md                                     | 33 ++++++++--
 application/docker-compose.yml                | 30 +++++++++
 application/module-certificate/Dockerfile     |  3 +
 application/module-exercise/Dockerfile        |  3 +
 application/module-language-school/Dockerfile |  3 +
 application/module-mail/Dockerfile            |  3 +
 application/pipeline.yml                      | 65 ++++++++++++++++---
 application/podman-compose.yml                | 30 +++++++++
 8 files changed, 156 insertions(+), 14 deletions(-)
 create mode 100644 application/docker-compose.yml
 create mode 100644 application/module-certificate/Dockerfile
 create mode 100644 application/module-exercise/Dockerfile
 create mode 100644 application/module-language-school/Dockerfile
 create mode 100644 application/module-mail/Dockerfile
 create mode 100644 application/podman-compose.yml

diff --git a/README.md b/README.md
index 3a2ad124..b1befef9 100644
--- a/README.md
+++ b/README.md
@@ -11,14 +11,37 @@
     - Martin GargaloviÄŤ *@xgargal*
     - Jan PokornĂ˝ *@xpokorn8*
     - Ester Vilímková - _Project Leader_ *@xvilimk*
+
+
 - **Assigment**:
     - Create a system for language school lecture management. Each lecture can occur on a given day and time and is related to some course. The course is defined by its (unique) name, language and proficiency level. However, each lecture will be independent. That means that each lecture can have a different topic. Different lecturers can give it, and an arbitrary number of students can enrol. Each lecturer will have a name, surname, and record of taught languages. In addition, the lecturer will indicate that they are a native speaker. Exercises can be prepared for each course to allow the students to learn the language. Each student can pick the exercises depending on the levels of difficulty.
 
-- **Running the modules**:
-    - ```cd ./application```
-    - ```mvn clean install```
-    - ```cd ./module-*```
-    - ```mvn spring-boot:run```
+
+- **Running the modules using docker-compose**:
+
+    ```console
+    cd ./application
+    mvn clean install
+    docker-compose build --parallel
+    docker-compose up
+    ```
+
+- **Running the modules using podman-compose**:
+    ~~~console
+    cd ./application
+    mvn clean install
+    podman-compose build --parallel
+    podman-compose up
+    ~~~
+
+- **Running the modules using docker**:
+    ~~~console
+   sudo docker run -d -p 5001:5001 xpokorn8/sprachschulsystem:certificate &&
+   sudo docker run -d -p 5002:5002 xpokorn8/sprachschulsystem:exercise &&
+   sudo docker run -d -p 5000:5000 xpokorn8/sprachschulsystem:language-school &&
+   sudo docker run -d -p 5003:5003 xpokorn8/sprachschulsystem:mail
+    ~~~
+
 
 # Project Description
 
diff --git a/application/docker-compose.yml b/application/docker-compose.yml
new file mode 100644
index 00000000..41a6a0d3
--- /dev/null
+++ b/application/docker-compose.yml
@@ -0,0 +1,30 @@
+version: '3'
+
+services:
+  certificate:
+    build: ./module-certificate
+    container_name: certificate
+    image: xpokorn8/sprachschulsystem:certificate
+    ports:
+      - "5001:5001"
+
+  exercise:
+    build: ./module-exercise
+    container_name: exercise
+    image: xpokorn8/sprachschulsystem:exercise
+    ports:
+      - "5002:5002"
+
+  language-school:
+    build: ./module-language-school
+    container_name: language-school
+    image: xpokorn8/sprachschulsystem:language-school
+    ports:
+      - "5000:5000"
+
+  mail:
+    build: ./module-mail
+    container_name: mail
+    image: xpokorn8/sprachschulsystem:mail
+    ports:
+      - "5003:5003"
\ No newline at end of file
diff --git a/application/module-certificate/Dockerfile b/application/module-certificate/Dockerfile
new file mode 100644
index 00000000..21e346d9
--- /dev/null
+++ b/application/module-certificate/Dockerfile
@@ -0,0 +1,3 @@
+FROM docker.io/library/eclipse-temurin:17-jre-focal
+COPY ./target/module-certificate-0.0.1-SNAPSHOT.jar /app.jar
+ENTRYPOINT ["java", "-jar", "/app.jar"]
diff --git a/application/module-exercise/Dockerfile b/application/module-exercise/Dockerfile
new file mode 100644
index 00000000..8e31eb6c
--- /dev/null
+++ b/application/module-exercise/Dockerfile
@@ -0,0 +1,3 @@
+FROM docker.io/library/eclipse-temurin:17-jre-focal
+COPY ./target/module-exercise-0.0.1-SNAPSHOT.jar /app.jar
+ENTRYPOINT ["java", "-jar", "/app.jar"]
diff --git a/application/module-language-school/Dockerfile b/application/module-language-school/Dockerfile
new file mode 100644
index 00000000..f2be765c
--- /dev/null
+++ b/application/module-language-school/Dockerfile
@@ -0,0 +1,3 @@
+FROM docker.io/library/eclipse-temurin:17-jre-focal
+COPY ./target/module-language-school-0.0.1-SNAPSHOT.jar /app.jar
+ENTRYPOINT ["java", "-jar", "/app.jar"]
diff --git a/application/module-mail/Dockerfile b/application/module-mail/Dockerfile
new file mode 100644
index 00000000..2e3cde27
--- /dev/null
+++ b/application/module-mail/Dockerfile
@@ -0,0 +1,3 @@
+FROM docker.io/library/eclipse-temurin:17-jre-focal
+COPY ./target/module-mail-0.0.1-SNAPSHOT.jar /app.jar
+ENTRYPOINT ["java", "-jar", "/app.jar"]
diff --git a/application/pipeline.yml b/application/pipeline.yml
index 2b29b6dd..58a8f7ff 100644
--- a/application/pipeline.yml
+++ b/application/pipeline.yml
@@ -1,7 +1,9 @@
 # This file specifies GitLab CI/CD pipeline, see https://docs.gitlab.com/ee/ci/
 
 stages:
+  - build
   - test
+  - deploy
 
 variables:
   # variable read by Maven for JVM options, see https://maven.apache.org/configure.html#maven_opts-environment-variable
@@ -9,19 +11,64 @@ variables:
   # our own variable for repeated options
   MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version "
 
-test:
+# name of Docker image in which the script commands are executed
+image: maven:latest
+
+cache:
+  paths:
+    - .m2/repository
+
+build:
+  stage: build
+  tags:
+    - shared-fi
+  image: maven:latest
+  script:
+    - 'cd "$CI_PROJECT_DIR/application"'
+    - 'mvn $MAVEN_CLI_OPTS clean install -DskipTests'
+
+test-certificate:
   stage: test
   tags:
     - shared-fi
-  # name of Docker image in which the script commands are executed
   image: maven:latest
-  # script is a list of linux shell commands
   script:
-    # run maven build
     - 'cd "$CI_PROJECT_DIR/application"'
-    - 'mvn $MAVEN_CLI_OPTS clean install'
-  cache:
-    # caches maven repo between runs
-    paths:
-      - .m2/repository
+    - 'mvn $MAVEN_CLI_OPTS -am -pl module-certificate test'
 
+test-exercise:
+  stage: test
+  tags:
+    - shared-fi
+  image: maven:latest
+  script:
+    - 'cd "$CI_PROJECT_DIR/application"'
+    - 'mvn $MAVEN_CLI_OPTS -am -pl module-exercise test'
+
+test-language-school:
+  stage: test
+  tags:
+    - shared-fi
+  image: maven:latest
+  script:
+    - 'cd "$CI_PROJECT_DIR/application"'
+    - 'mvn $MAVEN_CLI_OPTS -am -pl module-language-school test'
+
+test-mail:
+  stage: test
+  tags:
+    - shared-fi
+  image: maven:latest
+  script:
+    - 'cd "$CI_PROJECT_DIR/application"'
+    - 'mvn $MAVEN_CLI_OPTS -am -pl module-mail test'
+
+deploy:
+  when: manual
+  stage: deploy
+  script:
+    - 'cd "$CI_PROJECT_DIR/application"'
+    - 'mvn $MAVEN_CLI_OPTS install -DskipTests'
+    - 'docker-compose build --parallel'
+    - 'docker login -u $DOCKER_PRIVATE_LOGIN -p $DOCKER_PRIVATE_PASSWORD'
+    - 'docker-compose push'
diff --git a/application/podman-compose.yml b/application/podman-compose.yml
new file mode 100644
index 00000000..41a6a0d3
--- /dev/null
+++ b/application/podman-compose.yml
@@ -0,0 +1,30 @@
+version: '3'
+
+services:
+  certificate:
+    build: ./module-certificate
+    container_name: certificate
+    image: xpokorn8/sprachschulsystem:certificate
+    ports:
+      - "5001:5001"
+
+  exercise:
+    build: ./module-exercise
+    container_name: exercise
+    image: xpokorn8/sprachschulsystem:exercise
+    ports:
+      - "5002:5002"
+
+  language-school:
+    build: ./module-language-school
+    container_name: language-school
+    image: xpokorn8/sprachschulsystem:language-school
+    ports:
+      - "5000:5000"
+
+  mail:
+    build: ./module-mail
+    container_name: mail
+    image: xpokorn8/sprachschulsystem:mail
+    ports:
+      - "5003:5003"
\ No newline at end of file
-- 
GitLab