summaryrefslogtreecommitdiff
path: root/microservices/02-api-gateway/linux/deb/package
diff options
context:
space:
mode:
Diffstat (limited to 'microservices/02-api-gateway/linux/deb/package')
-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
10 files changed, 204 insertions, 0 deletions
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