summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmicroservices/01-oauth2-server/build.sh8
-rw-r--r--microservices/01-oauth2-server/linux/deb/.gitignore1
-rw-r--r--microservices/01-oauth2-server/linux/deb/README59
-rwxr-xr-xmicroservices/01-oauth2-server/linux/deb/build.sh36
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/DEBIAN/conffiles3
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/DEBIAN/control8
-rwxr-xr-xmicroservices/01-oauth2-server/linux/deb/package/DEBIAN/postinst59
-rwxr-xr-xmicroservices/01-oauth2-server/linux/deb/package/DEBIAN/postrm14
-rwxr-xr-xmicroservices/01-oauth2-server/linux/deb/package/DEBIAN/preinst8
-rwxr-xr-xmicroservices/01-oauth2-server/linux/deb/package/DEBIAN/prerm9
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/application.yaml40
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/environment.env2
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/etc/nginx/sites-available/fs-auth-server.dev.ceit.pdn.ac.lk61
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/etc/systemd/system/ceit-fs-auth-server.service12
-rw-r--r--microservices/01-oauth2-server/linux/deb/package/opt/ceit/ceit-fs-auth-server/app/.gitignore1
-rw-r--r--microservices/01-oauth2-server/src/test/java/com/example/oauth2server/Oauth2ServerApplicationTests.java13
-rwxr-xr-xmicroservices/02-api-gateway/build.sh8
-rw-r--r--microservices/02-api-gateway/linux/deb/.gitignore1
-rw-r--r--microservices/02-api-gateway/linux/deb/README59
-rwxr-xr-xmicroservices/02-api-gateway/linux/deb/build.sh36
-rw-r--r--microservices/02-api-gateway/linux/deb/package/DEBIAN/conffiles2
-rw-r--r--microservices/02-api-gateway/linux/deb/package/DEBIAN/control8
-rwxr-xr-xmicroservices/02-api-gateway/linux/deb/package/DEBIAN/postinst59
-rwxr-xr-xmicroservices/02-api-gateway/linux/deb/package/DEBIAN/postrm14
-rwxr-xr-xmicroservices/02-api-gateway/linux/deb/package/DEBIAN/preinst8
-rwxr-xr-xmicroservices/02-api-gateway/linux/deb/package/DEBIAN/prerm9
-rw-r--r--microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/application.yaml89
-rw-r--r--microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/environment.env2
-rw-r--r--microservices/02-api-gateway/linux/deb/package/etc/systemd/system/ceit-fs-api-gateway.service12
-rw-r--r--microservices/02-api-gateway/linux/deb/package/opt/ceit/ceit-fs-api-gateway/app/.gitignore1
-rw-r--r--microservices/02-api-gateway/src/test/java/com/example/apigateway/ApiGatewayApplicationTests.java13
-rwxr-xr-xmicroservices/03-resource-server/build.sh8
-rw-r--r--microservices/03-resource-server/linux/deb/.gitignore1
-rw-r--r--microservices/03-resource-server/linux/deb/README59
-rwxr-xr-xmicroservices/03-resource-server/linux/deb/build.sh36
-rw-r--r--microservices/03-resource-server/linux/deb/package/DEBIAN/conffiles2
-rw-r--r--microservices/03-resource-server/linux/deb/package/DEBIAN/control8
-rwxr-xr-xmicroservices/03-resource-server/linux/deb/package/DEBIAN/postinst59
-rwxr-xr-xmicroservices/03-resource-server/linux/deb/package/DEBIAN/postrm14
-rwxr-xr-xmicroservices/03-resource-server/linux/deb/package/DEBIAN/preinst8
-rwxr-xr-xmicroservices/03-resource-server/linux/deb/package/DEBIAN/prerm9
-rw-r--r--microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/application.yaml40
-rw-r--r--microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/environment.env2
-rw-r--r--microservices/03-resource-server/linux/deb/package/etc/systemd/system/ceit-fs-resource-server.service12
-rw-r--r--microservices/03-resource-server/linux/deb/package/opt/ceit/ceit-fs-resource-server/app/.gitignore1
-rw-r--r--microservices/03-resource-server/src/test/java/com/example/resourceserver/ResourceServerApplicationTests.java13
-rwxr-xr-xmicroservices/04-react-app/build.sh6
-rw-r--r--microservices/04-react-app/linux/etc/nginx/sites-available/fs-react-app.dev.ceit.pdn.ac.lk74
-rw-r--r--microservices/04-react-app/package-lock.json4
-rw-r--r--microservices/04-react-app/package.json2
-rwxr-xr-xmicroservices/build-all.sh7
51 files changed, 978 insertions, 42 deletions
diff --git a/microservices/01-oauth2-server/build.sh b/microservices/01-oauth2-server/build.sh
new file mode 100755
index 0000000..ce7143a
--- /dev/null
+++ b/microservices/01-oauth2-server/build.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+./mvnw clean package
+
+cp target/oauth2-server-0.0.1-SNAPSHOT.jar linux/deb/package/opt/ceit/ceit-fs-auth-server/app/ceit-fs-auth-server.jar
+
+cd linux/deb
+./build.sh
diff --git a/microservices/01-oauth2-server/linux/deb/.gitignore b/microservices/01-oauth2-server/linux/deb/.gitignore
new file mode 100644
index 0000000..c00df13
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/.gitignore
@@ -0,0 +1 @@
+*.deb
diff --git a/microservices/01-oauth2-server/linux/deb/README b/microservices/01-oauth2-server/linux/deb/README
new file mode 100644
index 0000000..a9b2810
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/README
@@ -0,0 +1,59 @@
+This directory contains everything to build a deb package that bundles a Spring Boot app that starts a web server.
+
+####
+
+Executable scripts:
+
+ create-new-project.sh - This script can be used to create a new deb package project similar to this project that uses a different name (than ceit-fs-auth-server). Output will be placed inside 'out' directory.
+
+ build.sh - This script builds the deb package. If the above script is used, go to the corresponding directory inside out directory to find a copy of this build.sh script.
+
+####
+
+To create a new deb package project that uses 'mycompany-myapp' as the name, run the following command:
+
+ ./create-new-project.sh mycompany mycompany-myapp
+
+ The newly generated project files will be found inside the out directory.
+
+####
+
+To build, run the following command:
+
+ ./build.sh
+
+ Note that the Spring Boot application has not been bundled with this. You need to build it seperately and put it in the correct directory (run build.sh for further details).
+
+####
+
+To install the build deb package run the following commands replacing the package.deb with the correct name of the deb file.
+
+ cp package.deb /tmp
+ cd /tmp
+ apt install ./package.deb
+
+The above "apt install" will download dependencies if needed. Otherwise, dpkg command can just be used to install or upgrade the package:
+
+ dpkg -i package.deb
+
+After installing the package, update the configuration file /etc/ceit-fs-auth-server/application.yaml .
+
+Enable service to start at boot time:
+
+ systemctl enable ceit-fs-auth-server
+
+Start service:
+
+ systemctl start ceit-fs-auth-server
+
+View service log:
+
+ journalctl -u ceit-fs-auth-server -f
+
+ (Press CTRL+C to terminate log viewing)
+
+Access the service:
+
+ http://server-ip-or-hostname:8085/
+
+ (Instead of 8085, use the port configured in application.yaml file)
diff --git a/microservices/01-oauth2-server/linux/deb/build.sh b/microservices/01-oauth2-server/linux/deb/build.sh
new file mode 100755
index 0000000..994b132
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Define a function that sends messages to stderr.
+errcho() {
+ echo "$@" 1>&2;
+}
+
+# Check if fakeroot command is available
+if ! command -v fakeroot > /dev/null 2>&1; then
+ errcho "[ERROR] fakeroot command not found. Install the fakeroot package.";
+ exit 1
+fi
+
+# Check if dpkg-deb command is available
+if ! command -v dpkg-deb > /dev/null 2>&1; then
+ errcho "[ERROR] dpkg-deb command not found. dpkg package contains it. Are you not running this script on a Debian based system?";
+ exit 1
+fi
+
+# Get the directory of this script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# Check if the spring boot jar is in the correct location
+if [ ! -f $DIR/package/opt/ceit/ceit-fs-auth-server/app/ceit-fs-auth-server.jar ]; then
+ errcho "[ERROR] Jar file missing: package/opt/ceit/ceit-fs-auth-server/app/ceit-fs-auth-server.jar"
+ errcho "[ERROR] Run this build script only after placing the jar file in that location."
+ exit 1
+fi
+
+# Remove the deb files found inside DIR. Don't prompt the user before deleting.
+if ls $DIR/*.deb 1> /dev/null 2>&1; then
+ rm $DIR/*.deb
+fi
+
+# Build the deb package
+fakeroot dpkg-deb --build $DIR/package $DIR
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/conffiles b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/conffiles
new file mode 100644
index 0000000..a52c085
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/conffiles
@@ -0,0 +1,3 @@
+/etc/ceit-fs-auth-server/application.yaml
+/etc/ceit-fs-auth-server/environment.env
+/etc/nginx/sites-available/fs-auth-server.dev.ceit.pdn.ac.lk
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/control b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/control
new file mode 100644
index 0000000..9239fb0
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: ceit-fs-auth-server
+Version: 1.0.0-1
+Section: httpd
+Priority: optional
+Architecture: all
+Depends: openjdk-25-jre | temurin-25-jre | openjdk-25-jdk | temurin-25-jdk
+Maintainer: Kamal Wickramanayake <info@software.lk>
+Description: A demo Debian package that bundles a Spring Boot application.
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postinst b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postinst
new file mode 100755
index 0000000..74509f4
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postinst
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Stop on error
+set -e
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+
+ # Create a system user
+ # -r: System user
+ # -s /sbin/nologin: Prevent the user from logging into the system interactively
+ # -d /var/lib/ceit-fs-auth-server: Set home directory of user
+ # ceit-fs-auth-server: Username
+ useradd -r -s /sbin/nologin -d /var/lib/ceit-fs-auth-server ceit-fs-auth-server || true
+
+fi
+
+# Set directory ownership and permissions - Application jar file not to be read by other system users
+chown -R root:ceit-fs-auth-server /opt/ceit/ceit-fs-auth-server
+chmod 755 /opt/ceit
+chmod 750 /opt/ceit/ceit-fs-auth-server
+chmod 750 /opt/ceit/ceit-fs-auth-server/app
+chmod 640 /opt/ceit/ceit-fs-auth-server/app/ceit-fs-auth-server.jar
+
+# Set directory ownership and permissions - Config files not to be read by other system users
+chown -R root:ceit-fs-auth-server /etc/ceit-fs-auth-server
+chmod 750 /etc/ceit-fs-auth-server
+chmod 640 /etc/ceit-fs-auth-server/application.yaml
+chmod 640 /etc/ceit-fs-auth-server/environment.env
+
+if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
+ if [ -d /run/systemd/system ]; then
+ # Reload systemd service configurations
+ systemctl daemon-reload > /dev/null || true
+
+ if [ -n "$2" ]; then
+ # Upgrade
+ # Restart service
+ if systemctl is-enabled ceit-fs-auth-server > /dev/null; then
+ systemctl start ceit-fs-auth-server
+ fi
+ else
+ # First install (not upgrade)
+ # Enable service to start at boot time
+ systemctl enable ceit-fs-auth-server
+ # Start service
+ systemctl start ceit-fs-auth-server
+ fi
+ fi
+fi
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+ echo "[INFO] ceit-fs-auth-server service installed."
+ echo "[INFO] Update /etc/ceit-fs-auth-server/application.yaml to update the configuration."
+ echo "[INFO] By default, TCP port 8085 is used by the installed server."
+ echo "[INFO] To allow access from remote systems, you may have to enable firewall for example by running:"
+ echo "[INFO] ufw allow 8085/tcp"
+fi
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postrm b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postrm
new file mode 100755
index 0000000..261f7af
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/postrm
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -e
+
+# Check if the package is being purged (erased entirely including configs)
+if [ -z "$DPKG_ROOT" ] && [ "$1" = "purge" ] ; then
+ update-rc.d ceit-fs-auth-server remove >/dev/null
+ deluser --quiet ceit-fs-auth-server || true
+fi
+
+# Reload systemd service configuration files.
+systemctl daemon-reload
+
+# postrm script must exit with 0
+exit 0
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/preinst b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/preinst
new file mode 100755
index 0000000..61c2587
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/preinst
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+# Put commands that should execute before the pckage is installed.
+
+# Example: Just print a message
+echo "preinst script running..."
diff --git a/microservices/01-oauth2-server/linux/deb/package/DEBIAN/prerm b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/prerm
new file mode 100755
index 0000000..cd4bf94
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/DEBIAN/prerm
@@ -0,0 +1,9 @@
+#!/bin/bash
+set -e
+
+# Stop service before files are removed
+systemctl stop ceit-fs-auth-server || true
+
+# prerm script must exit with 0
+exit 0
+
diff --git a/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/application.yaml b/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/application.yaml
new file mode 100644
index 0000000..0ce4a3d
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/application.yaml
@@ -0,0 +1,40 @@
+server:
+ port: 8051
+ address: 127.0.0.1
+ forward-headers-strategy: native
+
+#logging:
+# level:
+# org.springframework.security: trace
+
+spring:
+ application:
+ name: oauth2-server
+ security:
+ oauth2:
+ authorizationserver:
+ client:
+ oidc-client:
+ registration:
+ client-id: "api-gateway"
+ client-secret: "{noop}apiGatewayPassword1234"
+ client-authentication-methods:
+ - "client_secret_basic"
+ authorization-grant-types:
+ - "authorization_code"
+ - "refresh_token"
+ redirect-uris:
+ - "https://fs-react-app.dev.ceit.pdn.ac.lk/bff/login/oauth2/code/api-gateway"
+ post-logout-redirect-uris:
+ - "https://fs-react-app.dev.ceit.pdn.ac.lk/"
+ scopes:
+ - "openid"
+ - "profile"
+ require-authorization-consent: false
+
+app:
+ users:
+ - username: admin
+ password: "{noop}abc123"
+ - username: user1
+ password: "{noop}abc123"
diff --git a/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/environment.env b/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/environment.env
new file mode 100644
index 0000000..5423533
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/etc/ceit-fs-auth-server/environment.env
@@ -0,0 +1,2 @@
+# Which Spring profile should be active?
+#SPRING_PROFILES_ACTIVE=prod
diff --git a/microservices/01-oauth2-server/linux/deb/package/etc/nginx/sites-available/fs-auth-server.dev.ceit.pdn.ac.lk b/microservices/01-oauth2-server/linux/deb/package/etc/nginx/sites-available/fs-auth-server.dev.ceit.pdn.ac.lk
new file mode 100644
index 0000000..73c5b50
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/etc/nginx/sites-available/fs-auth-server.dev.ceit.pdn.ac.lk
@@ -0,0 +1,61 @@
+server {
+ listen 81;
+ listen [::]:81;
+
+ server_name fs-auth-server.dev.ceit.pdn.ac.lk ;
+
+ root /home/ceit_fs_auth_server/public_web;
+ index index.html;
+
+ access_log /var/log/nginx/fs-auth-server.dev.ceit.pdn.ac.lk_access.log;
+ error_log /var/log/nginx/fs-auth-server.dev.ceit.pdn.ac.lk_error.log;
+
+ location / {
+ try_files $uri $uri/ =404;
+ }
+
+ location /.well-known/ {
+ alias /home/ceit_fs_auth_server/well-known/;
+ }
+
+ location /.well-known/acme-challenge {
+ alias /var/lib/letsencrypt/.well-known/acme-challenge/;
+ }
+
+ # Block access to "hidden" files and directories whose names begin with a
+ # period. This includes directories used by version control systems such
+ # as Subversion or Git to store control files.
+ location ~ (^|/)\.(?!well-known).* {
+ return 403;
+ }
+}
+
+server {
+ listen 443 ssl;
+ listen [::]:443 ssl;
+
+ server_name fs-auth-server.dev.ceit.pdn.ac.lk ;
+
+ location / {
+ proxy_pass http://127.0.0.1:8051;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto https;
+ proxy_set_header X-Forwarded-Port 443;
+ proxy_set_header Host $host;
+ }
+
+ #
+ # To create a self signed certificate, run the below command
+ #
+ # openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/fs-auth-server.dev.ceit.pdn.ac.lk/server.key -out /etc/nginx/ssl/fs-auth-server.dev.ceit.pdn.ac.lk/server.crt
+ #
+ # Or non-intractively
+ #
+ # openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=AB/ST=ABC/L=ABCD/O=ABCDE/CN=fs-auth-server.dev.ceit.pdn.ac.lk" -keyout /etc/nginx/ssl/fs-auth-server.dev.ceit.pdn.ac.lk/server.key -out /etc/nginx/ssl/fs-auth-server.dev.ceit.pdn.ac.lk/server.crt
+ ssl_certificate /etc/letsencrypt/live/fs-auth-server.dev.ceit.pdn.ac.lk/fullchain.pem; # managed by Certbot
+ ssl_certificate_key /etc/letsencrypt/live/fs-auth-server.dev.ceit.pdn.ac.lk/privkey.pem; # managed by Certbot
+
+ ssl_dhparam /etc/nginx/ssl/dhparams.pem;
+
+}
diff --git a/microservices/01-oauth2-server/linux/deb/package/etc/systemd/system/ceit-fs-auth-server.service b/microservices/01-oauth2-server/linux/deb/package/etc/systemd/system/ceit-fs-auth-server.service
new file mode 100644
index 0000000..a26e76b
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/etc/systemd/system/ceit-fs-auth-server.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=ceit-fs-auth-server
+
+[Service]
+User=ceit-fs-auth-server
+EnvironmentFile=/etc/ceit-fs-auth-server/environment.env
+ExecStart=/usr/bin/java -Dspring.config.import=optional:file:/etc/ceit-fs-auth-server/application.yaml -jar /opt/ceit/ceit-fs-auth-server/app/ceit-fs-auth-server.jar
+Restart=always
+RestartSec=30
+
+[Install]
+WantedBy=multi-user.target
diff --git a/microservices/01-oauth2-server/linux/deb/package/opt/ceit/ceit-fs-auth-server/app/.gitignore b/microservices/01-oauth2-server/linux/deb/package/opt/ceit/ceit-fs-auth-server/app/.gitignore
new file mode 100644
index 0000000..d392f0e
--- /dev/null
+++ b/microservices/01-oauth2-server/linux/deb/package/opt/ceit/ceit-fs-auth-server/app/.gitignore
@@ -0,0 +1 @@
+*.jar
diff --git a/microservices/01-oauth2-server/src/test/java/com/example/oauth2server/Oauth2ServerApplicationTests.java b/microservices/01-oauth2-server/src/test/java/com/example/oauth2server/Oauth2ServerApplicationTests.java
deleted file mode 100644
index 507215a..0000000
--- a/microservices/01-oauth2-server/src/test/java/com/example/oauth2server/Oauth2ServerApplicationTests.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.example.oauth2server;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class Oauth2ServerApplicationTests {
-
- @Test
- void contextLoads() {
- }
-
-}
diff --git a/microservices/02-api-gateway/build.sh b/microservices/02-api-gateway/build.sh
new file mode 100755
index 0000000..de31e9e
--- /dev/null
+++ b/microservices/02-api-gateway/build.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+./mvnw clean package
+
+cp target/api-gateway-0.0.1-SNAPSHOT.jar linux/deb/package/opt/ceit/ceit-fs-api-gateway/app/ceit-fs-api-gateway.jar
+
+cd linux/deb
+./build.sh
diff --git a/microservices/02-api-gateway/linux/deb/.gitignore b/microservices/02-api-gateway/linux/deb/.gitignore
new file mode 100644
index 0000000..c00df13
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/.gitignore
@@ -0,0 +1 @@
+*.deb
diff --git a/microservices/02-api-gateway/linux/deb/README b/microservices/02-api-gateway/linux/deb/README
new file mode 100644
index 0000000..4197c21
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/README
@@ -0,0 +1,59 @@
+This directory contains everything to build a deb package that bundles a Spring Boot app that starts a web server.
+
+####
+
+Executable scripts:
+
+ create-new-project.sh - This script can be used to create a new deb package project similar to this project that uses a different name (than ceit-fs-api-gateway). Output will be placed inside 'out' directory.
+
+ build.sh - This script builds the deb package. If the above script is used, go to the corresponding directory inside out directory to find a copy of this build.sh script.
+
+####
+
+To create a new deb package project that uses 'mycompany-myapp' as the name, run the following command:
+
+ ./create-new-project.sh mycompany mycompany-myapp
+
+ The newly generated project files will be found inside the out directory.
+
+####
+
+To build, run the following command:
+
+ ./build.sh
+
+ Note that the Spring Boot application has not been bundled with this. You need to build it seperately and put it in the correct directory (run build.sh for further details).
+
+####
+
+To install the build deb package run the following commands replacing the package.deb with the correct name of the deb file.
+
+ cp package.deb /tmp
+ cd /tmp
+ apt install ./package.deb
+
+The above "apt install" will download dependencies if needed. Otherwise, dpkg command can just be used to install or upgrade the package:
+
+ dpkg -i package.deb
+
+After installing the package, update the configuration file /etc/ceit-fs-api-gateway/application.yaml .
+
+Enable service to start at boot time:
+
+ systemctl enable ceit-fs-api-gateway
+
+Start service:
+
+ systemctl start ceit-fs-api-gateway
+
+View service log:
+
+ journalctl -u ceit-fs-api-gateway -f
+
+ (Press CTRL+C to terminate log viewing)
+
+Access the service:
+
+ http://server-ip-or-hostname:8085/
+
+ (Instead of 8085, use the port configured in application.yaml file)
diff --git a/microservices/02-api-gateway/linux/deb/build.sh b/microservices/02-api-gateway/linux/deb/build.sh
new file mode 100755
index 0000000..cb56e7d
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Define a function that sends messages to stderr.
+errcho() {
+ echo "$@" 1>&2;
+}
+
+# Check if fakeroot command is available
+if ! command -v fakeroot > /dev/null 2>&1; then
+ errcho "[ERROR] fakeroot command not found. Install the fakeroot package.";
+ exit 1
+fi
+
+# Check if dpkg-deb command is available
+if ! command -v dpkg-deb > /dev/null 2>&1; then
+ errcho "[ERROR] dpkg-deb command not found. dpkg package contains it. Are you not running this script on a Debian based system?";
+ exit 1
+fi
+
+# Get the directory of this script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# Check if the spring boot jar is in the correct location
+if [ ! -f $DIR/package/opt/ceit/ceit-fs-api-gateway/app/ceit-fs-api-gateway.jar ]; then
+ errcho "[ERROR] Jar file missing: package/opt/ceit/ceit-fs-api-gateway/app/ceit-fs-api-gateway.jar"
+ errcho "[ERROR] Run this build script only after placing the jar file in that location."
+ exit 1
+fi
+
+# Remove the deb files found inside DIR. Don't prompt the user before deleting.
+if ls $DIR/*.deb 1> /dev/null 2>&1; then
+ rm $DIR/*.deb
+fi
+
+# Build the deb package
+fakeroot dpkg-deb --build $DIR/package $DIR
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/conffiles b/microservices/02-api-gateway/linux/deb/package/DEBIAN/conffiles
new file mode 100644
index 0000000..1b6fce0
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/conffiles
@@ -0,0 +1,2 @@
+/etc/ceit-fs-api-gateway/application.yaml
+/etc/ceit-fs-api-gateway/environment.env
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/control b/microservices/02-api-gateway/linux/deb/package/DEBIAN/control
new file mode 100644
index 0000000..f15d954
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: ceit-fs-api-gateway
+Version: 1.0.0-1
+Section: httpd
+Priority: optional
+Architecture: all
+Depends: openjdk-25-jre | temurin-25-jre | openjdk-25-jdk | temurin-25-jdk
+Maintainer: Kamal Wickramanayake <info@software.lk>
+Description: A demo Debian package that bundles a Spring Boot application.
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/postinst b/microservices/02-api-gateway/linux/deb/package/DEBIAN/postinst
new file mode 100755
index 0000000..6223444
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/postinst
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Stop on error
+set -e
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+
+ # Create a system user
+ # -r: System user
+ # -s /sbin/nologin: Prevent the user from logging into the system interactively
+ # -d /var/lib/ceit-fs-api-gateway: Set home directory of user
+ # ceit-fs-api-gateway: Username
+ useradd -r -s /sbin/nologin -d /var/lib/ceit-fs-api-gateway ceit-fs-api-gateway || true
+
+fi
+
+# Set directory ownership and permissions - Application jar file not to be read by other system users
+chown -R root:ceit-fs-api-gateway /opt/ceit/ceit-fs-api-gateway
+chmod 755 /opt/ceit
+chmod 750 /opt/ceit/ceit-fs-api-gateway
+chmod 750 /opt/ceit/ceit-fs-api-gateway/app
+chmod 640 /opt/ceit/ceit-fs-api-gateway/app/ceit-fs-api-gateway.jar
+
+# Set directory ownership and permissions - Config files not to be read by other system users
+chown -R root:ceit-fs-api-gateway /etc/ceit-fs-api-gateway
+chmod 750 /etc/ceit-fs-api-gateway
+chmod 640 /etc/ceit-fs-api-gateway/application.yaml
+chmod 640 /etc/ceit-fs-api-gateway/environment.env
+
+if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
+ if [ -d /run/systemd/system ]; then
+ # Reload systemd service configurations
+ systemctl daemon-reload > /dev/null || true
+
+ if [ -n "$2" ]; then
+ # Upgrade
+ # Restart service
+ if systemctl is-enabled ceit-fs-api-gateway > /dev/null; then
+ systemctl start ceit-fs-api-gateway
+ fi
+ else
+ # First install (not upgrade)
+ # Enable service to start at boot time
+ systemctl enable ceit-fs-api-gateway
+ # Start service
+ systemctl start ceit-fs-api-gateway
+ fi
+ fi
+fi
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+ echo "[INFO] ceit-fs-api-gateway service installed."
+ echo "[INFO] Update /etc/ceit-fs-api-gateway/application.yaml to update the configuration."
+ echo "[INFO] By default, TCP port 8085 is used by the installed server."
+ echo "[INFO] To allow access from remote systems, you may have to enable firewall for example by running:"
+ echo "[INFO] ufw allow 8085/tcp"
+fi
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/postrm b/microservices/02-api-gateway/linux/deb/package/DEBIAN/postrm
new file mode 100755
index 0000000..c2d202c
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/postrm
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -e
+
+# Check if the package is being purged (erased entirely including configs)
+if [ -z "$DPKG_ROOT" ] && [ "$1" = "purge" ] ; then
+ update-rc.d ceit-fs-api-gateway remove >/dev/null
+ deluser --quiet ceit-fs-api-gateway || true
+fi
+
+# Reload systemd service configuration files.
+systemctl daemon-reload
+
+# postrm script must exit with 0
+exit 0
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/preinst b/microservices/02-api-gateway/linux/deb/package/DEBIAN/preinst
new file mode 100755
index 0000000..61c2587
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/preinst
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+# Put commands that should execute before the pckage is installed.
+
+# Example: Just print a message
+echo "preinst script running..."
diff --git a/microservices/02-api-gateway/linux/deb/package/DEBIAN/prerm b/microservices/02-api-gateway/linux/deb/package/DEBIAN/prerm
new file mode 100755
index 0000000..002d5be
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/DEBIAN/prerm
@@ -0,0 +1,9 @@
+#!/bin/bash
+set -e
+
+# Stop service before files are removed
+systemctl stop ceit-fs-api-gateway || true
+
+# prerm script must exit with 0
+exit 0
+
diff --git a/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/application.yaml b/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/application.yaml
new file mode 100644
index 0000000..2747d3b
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/application.yaml
@@ -0,0 +1,89 @@
+server:
+ port: 8050
+ address: 127.0.0.1
+
+app:
+ userRolesUrl: "http://localhost:8052/myservices/api/security/users/{username}/roles"
+
+# logging:
+# level:
+# org.springframework.security: trace
+
+spring:
+ application:
+ name: api-gateway
+
+ cloud:
+ gateway:
+ server:
+ webflux:
+ globalcors:
+ cors-configurations:
+ '[/**]':
+ allowedOrigins:
+ - "https://fs-react-app.dev.ceit.pdn.ac.lk"
+ allowedMethods: "*"
+ allowedHeaders: "*"
+ allowCredentials: true
+ routes:
+ # Frontend tries to access this URL when the login link is clicked.
+ # If user is not logged in, user will be redirected to OAuth2 server.
+ # If logged in, frontend will be reloaded.
+ - id: frontend
+ uri: no://op # CRITICAL: Prevents forwarding to a backend server
+ predicates:
+ - Path=/ui
+ filters:
+ - RedirectTo=302, https://fs-react-app.dev.ceit.pdn.ac.lk/
+ # Forward requests to backend service (OAuth2 resource server)
+ - id: backend-service
+ uri: http://localhost:8052
+ predicates:
+ - Path=/api/**
+ filters:
+ # 1. ALWAYS strip incoming spoof headers from the public web first
+ - RemoveRequestHeader=X-User-Id
+ - RemoveRequestHeader=X-User-Name
+ - RemoveRequestHeader=X-User-Roles
+ - RemoveRequestHeader=Authorization
+ - PrefixPath=/myservices
+ - TokenRelay # Add oauth (or jwt) token to request header before forwarding
+
+ security:
+ oauth2:
+ client:
+ provider:
+ platform-auth-server:
+ issuer-uri: https://fs-auth-server.dev.ceit.pdn.ac.lk
+ registration:
+ api-gateway:
+ provider: platform-auth-server
+ client-id: api-gateway
+ client-secret: "apiGatewayPassword1234"
+ client-authentication-method: client_secret_basic
+ authorization-grant-type: authorization_code
+ redirect-uri: https://fs-react-app.dev.ceit.pdn.ac.lk/bff/login/oauth2/code/api-gateway
+ scope:
+ - openid
+ - profile
+com:
+ c4-soft:
+ springaddons:
+ oidc:
+ ops:
+ - iss: https://fs-auth-server.dev.ceit.pdn.ac.lk
+ client:
+ client-uri: https://fs-react-app.dev.ceit.pdn.ac.lk
+ login-uri: /bff/oauth2/authorization/api-gateway
+ security-matchers:
+ - /**
+ permit-all:
+ - /login/**
+ - /oauth2/**
+ - /
+ - /api/**
+ csrf: cookie-accessible-from-js
+ oauth2-redirections:
+ rp-initiated-logout: ACCEPTED
+ post-logout-redirect-host: https://fs-react-app.dev.ceit.pdn.ac.lk
+ post-logout-redirect-path: /
diff --git a/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/environment.env b/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/environment.env
new file mode 100644
index 0000000..5423533
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/etc/ceit-fs-api-gateway/environment.env
@@ -0,0 +1,2 @@
+# Which Spring profile should be active?
+#SPRING_PROFILES_ACTIVE=prod
diff --git a/microservices/02-api-gateway/linux/deb/package/etc/systemd/system/ceit-fs-api-gateway.service b/microservices/02-api-gateway/linux/deb/package/etc/systemd/system/ceit-fs-api-gateway.service
new file mode 100644
index 0000000..5a2cc54
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/etc/systemd/system/ceit-fs-api-gateway.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=ceit-fs-api-gateway
+
+[Service]
+User=ceit-fs-api-gateway
+EnvironmentFile=/etc/ceit-fs-api-gateway/environment.env
+ExecStart=/usr/bin/java -Dspring.config.import=optional:file:/etc/ceit-fs-api-gateway/application.yaml -jar /opt/ceit/ceit-fs-api-gateway/app/ceit-fs-api-gateway.jar
+Restart=always
+RestartSec=30
+
+[Install]
+WantedBy=multi-user.target
diff --git a/microservices/02-api-gateway/linux/deb/package/opt/ceit/ceit-fs-api-gateway/app/.gitignore b/microservices/02-api-gateway/linux/deb/package/opt/ceit/ceit-fs-api-gateway/app/.gitignore
new file mode 100644
index 0000000..d392f0e
--- /dev/null
+++ b/microservices/02-api-gateway/linux/deb/package/opt/ceit/ceit-fs-api-gateway/app/.gitignore
@@ -0,0 +1 @@
+*.jar
diff --git a/microservices/02-api-gateway/src/test/java/com/example/apigateway/ApiGatewayApplicationTests.java b/microservices/02-api-gateway/src/test/java/com/example/apigateway/ApiGatewayApplicationTests.java
deleted file mode 100644
index 8a7cdc7..0000000
--- a/microservices/02-api-gateway/src/test/java/com/example/apigateway/ApiGatewayApplicationTests.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.example.apigateway;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class ApiGatewayApplicationTests {
-
- @Test
- void contextLoads() {
- }
-
-}
diff --git a/microservices/03-resource-server/build.sh b/microservices/03-resource-server/build.sh
new file mode 100755
index 0000000..7c9680e
--- /dev/null
+++ b/microservices/03-resource-server/build.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+./mvnw clean package
+
+cp target/resource-server-0.0.1-SNAPSHOT.jar linux/deb/package/opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar
+
+cd linux/deb
+./build.sh
diff --git a/microservices/03-resource-server/linux/deb/.gitignore b/microservices/03-resource-server/linux/deb/.gitignore
new file mode 100644
index 0000000..c00df13
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/.gitignore
@@ -0,0 +1 @@
+*.deb
diff --git a/microservices/03-resource-server/linux/deb/README b/microservices/03-resource-server/linux/deb/README
new file mode 100644
index 0000000..cc66dd8
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/README
@@ -0,0 +1,59 @@
+This directory contains everything to build a deb package that bundles a Spring Boot app that starts a web server.
+
+####
+
+Executable scripts:
+
+ create-new-project.sh - This script can be used to create a new deb package project similar to this project that uses a different name (than ceit-fs-resource-server). Output will be placed inside 'out' directory.
+
+ build.sh - This script builds the deb package. If the above script is used, go to the corresponding directory inside out directory to find a copy of this build.sh script.
+
+####
+
+To create a new deb package project that uses 'mycompany-myapp' as the name, run the following command:
+
+ ./create-new-project.sh mycompany mycompany-myapp
+
+ The newly generated project files will be found inside the out directory.
+
+####
+
+To build, run the following command:
+
+ ./build.sh
+
+ Note that the Spring Boot application has not been bundled with this. You need to build it seperately and put it in the correct directory (run build.sh for further details).
+
+####
+
+To install the build deb package run the following commands replacing the package.deb with the correct name of the deb file.
+
+ cp package.deb /tmp
+ cd /tmp
+ apt install ./package.deb
+
+The above "apt install" will download dependencies if needed. Otherwise, dpkg command can just be used to install or upgrade the package:
+
+ dpkg -i package.deb
+
+After installing the package, update the configuration file /etc/ceit-fs-resource-server/application.yaml .
+
+Enable service to start at boot time:
+
+ systemctl enable ceit-fs-resource-server
+
+Start service:
+
+ systemctl start ceit-fs-resource-server
+
+View service log:
+
+ journalctl -u ceit-fs-resource-server -f
+
+ (Press CTRL+C to terminate log viewing)
+
+Access the service:
+
+ http://server-ip-or-hostname:8085/
+
+ (Instead of 8085, use the port configured in application.yaml file)
diff --git a/microservices/03-resource-server/linux/deb/build.sh b/microservices/03-resource-server/linux/deb/build.sh
new file mode 100755
index 0000000..a121d2e
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+# Define a function that sends messages to stderr.
+errcho() {
+ echo "$@" 1>&2;
+}
+
+# Check if fakeroot command is available
+if ! command -v fakeroot > /dev/null 2>&1; then
+ errcho "[ERROR] fakeroot command not found. Install the fakeroot package.";
+ exit 1
+fi
+
+# Check if dpkg-deb command is available
+if ! command -v dpkg-deb > /dev/null 2>&1; then
+ errcho "[ERROR] dpkg-deb command not found. dpkg package contains it. Are you not running this script on a Debian based system?";
+ exit 1
+fi
+
+# Get the directory of this script
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+# Check if the spring boot jar is in the correct location
+if [ ! -f $DIR/package/opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar ]; then
+ errcho "[ERROR] Jar file missing: package/opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar"
+ errcho "[ERROR] Run this build script only after placing the jar file in that location."
+ exit 1
+fi
+
+# Remove the deb files found inside DIR. Don't prompt the user before deleting.
+if ls $DIR/*.deb 1> /dev/null 2>&1; then
+ rm $DIR/*.deb
+fi
+
+# Build the deb package
+fakeroot dpkg-deb --build $DIR/package $DIR
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/conffiles b/microservices/03-resource-server/linux/deb/package/DEBIAN/conffiles
new file mode 100644
index 0000000..a7f5a82
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/conffiles
@@ -0,0 +1,2 @@
+/etc/ceit-fs-resource-server/application.yaml
+/etc/ceit-fs-resource-server/environment.env
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/control b/microservices/03-resource-server/linux/deb/package/DEBIAN/control
new file mode 100644
index 0000000..e3d6afe
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/control
@@ -0,0 +1,8 @@
+Package: ceit-fs-resource-server
+Version: 1.0.0-1
+Section: httpd
+Priority: optional
+Architecture: all
+Depends: openjdk-25-jre | temurin-25-jre | openjdk-25-jdk | temurin-25-jdk
+Maintainer: Kamal Wickramanayake <info@software.lk>
+Description: A demo Debian package that bundles a Spring Boot application.
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/postinst b/microservices/03-resource-server/linux/deb/package/DEBIAN/postinst
new file mode 100755
index 0000000..247d430
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/postinst
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+# Stop on error
+set -e
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+
+ # Create a system user
+ # -r: System user
+ # -s /sbin/nologin: Prevent the user from logging into the system interactively
+ # -d /var/lib/ceit-fs-resource-server: Set home directory of user
+ # ceit-fs-resource-server: Username
+ useradd -r -s /sbin/nologin -d /var/lib/ceit-fs-resource-server ceit-fs-resource-server || true
+
+fi
+
+# Set directory ownership and permissions - Application jar file not to be read by other system users
+chown -R root:ceit-fs-resource-server /opt/ceit/ceit-fs-resource-server
+chmod 755 /opt/ceit
+chmod 750 /opt/ceit/ceit-fs-resource-server
+chmod 750 /opt/ceit/ceit-fs-resource-server/app
+chmod 640 /opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar
+
+# Set directory ownership and permissions - Config files not to be read by other system users
+chown -R root:ceit-fs-resource-server /etc/ceit-fs-resource-server
+chmod 750 /etc/ceit-fs-resource-server
+chmod 640 /etc/ceit-fs-resource-server/application.yaml
+chmod 640 /etc/ceit-fs-resource-server/environment.env
+
+if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
+ if [ -d /run/systemd/system ]; then
+ # Reload systemd service configurations
+ systemctl daemon-reload > /dev/null || true
+
+ if [ -n "$2" ]; then
+ # Upgrade
+ # Restart service
+ if systemctl is-enabled ceit-fs-resource-server > /dev/null; then
+ systemctl start ceit-fs-resource-server
+ fi
+ else
+ # First install (not upgrade)
+ # Enable service to start at boot time
+ systemctl enable ceit-fs-resource-server
+ # Start service
+ systemctl start ceit-fs-resource-server
+ fi
+ fi
+fi
+
+if [ "$1" == "configure" ] && [ -z "$2" ]; then
+ # Code here executes only during package install (but not during upgrade)
+ echo "[INFO] ceit-fs-resource-server service installed."
+ echo "[INFO] Update /etc/ceit-fs-resource-server/application.yaml to update the configuration."
+ echo "[INFO] By default, TCP port 8085 is used by the installed server."
+ echo "[INFO] To allow access from remote systems, you may have to enable firewall for example by running:"
+ echo "[INFO] ufw allow 8085/tcp"
+fi
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/postrm b/microservices/03-resource-server/linux/deb/package/DEBIAN/postrm
new file mode 100755
index 0000000..1883418
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/postrm
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -e
+
+# Check if the package is being purged (erased entirely including configs)
+if [ -z "$DPKG_ROOT" ] && [ "$1" = "purge" ] ; then
+ update-rc.d ceit-fs-resource-server remove >/dev/null
+ deluser --quiet ceit-fs-resource-server || true
+fi
+
+# Reload systemd service configuration files.
+systemctl daemon-reload
+
+# postrm script must exit with 0
+exit 0
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/preinst b/microservices/03-resource-server/linux/deb/package/DEBIAN/preinst
new file mode 100755
index 0000000..61c2587
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/preinst
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+# Put commands that should execute before the pckage is installed.
+
+# Example: Just print a message
+echo "preinst script running..."
diff --git a/microservices/03-resource-server/linux/deb/package/DEBIAN/prerm b/microservices/03-resource-server/linux/deb/package/DEBIAN/prerm
new file mode 100755
index 0000000..e662818
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/DEBIAN/prerm
@@ -0,0 +1,9 @@
+#!/bin/bash
+set -e
+
+# Stop service before files are removed
+systemctl stop ceit-fs-resource-server || true
+
+# prerm script must exit with 0
+exit 0
+
diff --git a/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/application.yaml b/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/application.yaml
new file mode 100644
index 0000000..5a1c9df
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/application.yaml
@@ -0,0 +1,40 @@
+server:
+ port: 8052
+ address: 127.0.0.1
+ servlet:
+ context-path: /myservices
+
+# logging:
+# level:
+# org.springframework.security: trace
+
+spring:
+ application:
+ name: resource-server
+
+ security:
+ oauth2:
+ resourceserver:
+ jwt:
+ issuer-uri: https://fs-auth-server.dev.ceit.pdn.ac.lk
+
+ datasource:
+ url: jdbc:h2:mem:testdb
+ driver-class-name: org.h2.Driver
+ username: sa
+ password: password
+ h2:
+ console:
+ enabled: false
+ path: /h2-console # H2 Console: http://localhost:8052/myservices/h2-console
+ jpa:
+ # database-platform: org.hibernate.dialect.H2Dialect
+ hibernate:
+ ddl-auto: update
+ show-sql: false
+ defer-datasource-initialization: true # schema.sql and data.sql are executed after Hibernate/JPA auto-creates database tables.
+
+ # Always execute initialization scripts (resources/schema.sql, resources/data.sql) on startup
+ sql:
+ init:
+ mode: always
diff --git a/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/environment.env b/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/environment.env
new file mode 100644
index 0000000..5423533
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/etc/ceit-fs-resource-server/environment.env
@@ -0,0 +1,2 @@
+# Which Spring profile should be active?
+#SPRING_PROFILES_ACTIVE=prod
diff --git a/microservices/03-resource-server/linux/deb/package/etc/systemd/system/ceit-fs-resource-server.service b/microservices/03-resource-server/linux/deb/package/etc/systemd/system/ceit-fs-resource-server.service
new file mode 100644
index 0000000..0bb7388
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/etc/systemd/system/ceit-fs-resource-server.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=ceit-fs-resource-server
+
+[Service]
+User=ceit-fs-resource-server
+EnvironmentFile=/etc/ceit-fs-resource-server/environment.env
+ExecStart=/usr/bin/java -Dspring.config.import=optional:file:/etc/ceit-fs-resource-server/application.yaml -jar /opt/ceit/ceit-fs-resource-server/app/ceit-fs-resource-server.jar
+Restart=always
+RestartSec=30
+
+[Install]
+WantedBy=multi-user.target
diff --git a/microservices/03-resource-server/linux/deb/package/opt/ceit/ceit-fs-resource-server/app/.gitignore b/microservices/03-resource-server/linux/deb/package/opt/ceit/ceit-fs-resource-server/app/.gitignore
new file mode 100644
index 0000000..d392f0e
--- /dev/null
+++ b/microservices/03-resource-server/linux/deb/package/opt/ceit/ceit-fs-resource-server/app/.gitignore
@@ -0,0 +1 @@
+*.jar
diff --git a/microservices/03-resource-server/src/test/java/com/example/resourceserver/ResourceServerApplicationTests.java b/microservices/03-resource-server/src/test/java/com/example/resourceserver/ResourceServerApplicationTests.java
deleted file mode 100644
index a787fbe..0000000
--- a/microservices/03-resource-server/src/test/java/com/example/resourceserver/ResourceServerApplicationTests.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.example.resourceserver;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class ResourceServerApplicationTests {
-
- @Test
- void contextLoads() {
- }
-
-}
diff --git a/microservices/04-react-app/build.sh b/microservices/04-react-app/build.sh
new file mode 100755
index 0000000..9424fc4
--- /dev/null
+++ b/microservices/04-react-app/build.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+npm install
+npm run build
+
+echo dist directory contains the React application.
diff --git a/microservices/04-react-app/linux/etc/nginx/sites-available/fs-react-app.dev.ceit.pdn.ac.lk b/microservices/04-react-app/linux/etc/nginx/sites-available/fs-react-app.dev.ceit.pdn.ac.lk
new file mode 100644
index 0000000..4aed161
--- /dev/null
+++ b/microservices/04-react-app/linux/etc/nginx/sites-available/fs-react-app.dev.ceit.pdn.ac.lk
@@ -0,0 +1,74 @@
+server {
+ listen 81;
+ listen [::]:81;
+
+ server_name fs-react-app.dev.ceit.pdn.ac.lk ;
+
+ root /home/ceit_fs_react_app/public_web;
+ index index.html;
+
+ access_log /var/log/nginx/fs-react-app.dev.ceit.pdn.ac.lk_access.log;
+ error_log /var/log/nginx/fs-react-app.dev.ceit.pdn.ac.lk_error.log;
+
+ location / {
+ # First attempt to serve request as file, then
+ # as directory, then fall back to displaying /index.html
+ try_files $uri $uri/ /index.html;
+ }
+
+ location /.well-known/ {
+ alias /home/ceit_fs_react_app/well-known/;
+ }
+
+ location /.well-known/acme-challenge {
+ alias /var/lib/letsencrypt/.well-known/acme-challenge/;
+ }
+
+ # Block access to "hidden" files and directories whose names begin with a
+ # period. This includes directories used by version control systems such
+ # as Subversion or Git to store control files.
+ location ~ (^|/)\.(?!well-known).* {
+ return 403;
+ }
+}
+
+server {
+ listen 443 ssl;
+ listen [::]:443 ssl;
+
+ server_name fs-react-app.dev.ceit.pdn.ac.lk ;
+
+ root /home/ceit_fs_react_app/public_web;
+ index index.html;
+
+ # Forward requests to API gateway
+ location /bff/ {
+ proxy_pass http://127.0.0.1:8050/;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_set_header X-Forwarded-Port $server_port;
+ proxy_set_header Host $host;
+ }
+
+ # Serve React application files
+ location / {
+ # First attempt to serve request as file, then
+ # as directory, then fall back to displaying /index.html
+ try_files $uri $uri/ /index.html;
+ }
+
+ #
+ # To create a self signed certificate, run the below command
+ #
+ # openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/fs-react-app.dev.ceit.pdn.ac.lk/server.key -out /etc/nginx/ssl/fs-react-app.dev.ceit.pdn.ac.lk/server.crt
+ #
+ # Or non-intractively
+ #
+ # openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=AB/ST=ABC/L=ABCD/O=ABCDE/CN=fs-react-app.dev.ceit.pdn.ac.lk" -keyout /etc/nginx/ssl/fs-react-app.dev.ceit.pdn.ac.lk/server.key -out /etc/nginx/ssl/fs-react-app.dev.ceit.pdn.ac.lk/server.crt
+ ssl_certificate /etc/letsencrypt/live/fs-react-app.dev.ceit.pdn.ac.lk/fullchain.pem; # managed by Certbot
+ ssl_certificate_key /etc/letsencrypt/live/fs-react-app.dev.ceit.pdn.ac.lk/privkey.pem; # managed by Certbot
+
+ ssl_dhparam /etc/nginx/ssl/dhparams.pem;
+
+}
diff --git a/microservices/04-react-app/package-lock.json b/microservices/04-react-app/package-lock.json
index 7df3b15..14401cf 100644
--- a/microservices/04-react-app/package-lock.json
+++ b/microservices/04-react-app/package-lock.json
@@ -1,11 +1,11 @@
{
- "name": "05-useeffect",
+ "name": "react-app",
"version": "0.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
- "name": "05-useeffect",
+ "name": "react-app",
"version": "0.0.0",
"dependencies": {
"axios": "^1.18.1",
diff --git a/microservices/04-react-app/package.json b/microservices/04-react-app/package.json
index 2ee96da..262e08a 100644
--- a/microservices/04-react-app/package.json
+++ b/microservices/04-react-app/package.json
@@ -1,5 +1,5 @@
{
- "name": "05-useeffect",
+ "name": "react-app",
"private": true,
"version": "0.0.0",
"type": "module",
diff --git a/microservices/build-all.sh b/microservices/build-all.sh
new file mode 100755
index 0000000..24d49a7
--- /dev/null
+++ b/microservices/build-all.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+echo Building all the projects...
+
+for d in */; do
+ (cd "$d" && ./build.sh)
+done