From 2a638562701664f78cc373d8b3d1fbd6ce375d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20P=C3=B3=C5=82torak?= Date: Sun, 16 Jul 2023 20:04:09 +0200 Subject: [PATCH 1/2] Added kubernetes config based on docker compose file --- docker-compose.yml | 2 +- kubernetes/backend-deployment.yml | 24 +++++++++++++++++ kubernetes/backend-service.yml | 11 ++++++++ kubernetes/frontend-deployment.yml | 19 ++++++++++++++ kubernetes/frontend-service.yml | 11 ++++++++ kubernetes/postgres-deployment.yml | 26 +++++++++++++++++++ kubernetes/postgres-service.yml | 11 ++++++++ social-app-backend/docker-compose.yml | 2 +- .../admin/AdminController.java | 2 -- .../socialappbackend/auth/AuthController.java | 4 --- .../config/oauth/OAuthFailureHandler.java | 2 ++ .../config/oauth/OAuthSuccessHandler.java | 1 - .../config/oauth/OidcService.java | 2 ++ .../socialappbackend/home/HomeController.java | 2 -- .../search/SearchController.java | 2 -- social-app-frontend/docker-compose.yml | 2 +- 16 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 kubernetes/backend-deployment.yml create mode 100644 kubernetes/backend-service.yml create mode 100644 kubernetes/frontend-deployment.yml create mode 100644 kubernetes/frontend-service.yml create mode 100644 kubernetes/postgres-deployment.yml create mode 100644 kubernetes/postgres-service.yml diff --git a/docker-compose.yml b/docker-compose.yml index d74e992..522bda4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3" +version: "3.1" services: maildev: diff --git a/kubernetes/backend-deployment.yml b/kubernetes/backend-deployment.yml new file mode 100644 index 0000000..2715da5 --- /dev/null +++ b/kubernetes/backend-deployment.yml @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: backend + template: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: social-app-backend + ports: + - containerPort: 8080 + env: + - name: SPRING_DATASOURCE_URL + value: jdbc:postgresql://postgres:5432/socialapp + dependsOn: + - name: postgres diff --git a/kubernetes/backend-service.yml b/kubernetes/backend-service.yml new file mode 100644 index 0000000..f63ae08 --- /dev/null +++ b/kubernetes/backend-service.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: backend-service +spec: + selector: + app: backend + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 diff --git a/kubernetes/frontend-deployment.yml b/kubernetes/frontend-deployment.yml new file mode 100644 index 0000000..29e40cb --- /dev/null +++ b/kubernetes/frontend-deployment.yml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: frontend + template: + metadata: + labels: + app: frontend + spec: + containers: + - name: frontend + image: social-app-frontend + ports: + - containerPort: 80 diff --git a/kubernetes/frontend-service.yml b/kubernetes/frontend-service.yml new file mode 100644 index 0000000..0b9f9d5 --- /dev/null +++ b/kubernetes/frontend-service.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: frontend-service +spec: + selector: + app: frontend + ports: + - protocol: TCP + port: 80 + targetPort: 80 diff --git a/kubernetes/postgres-deployment.yml b/kubernetes/postgres-deployment.yml new file mode 100644 index 0000000..5b44ea8 --- /dev/null +++ b/kubernetes/postgres-deployment.yml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: social-app-postgres + ports: + - containerPort: 5432 + env: + - name: POSTGRES_DB + value: socialapp + - name: POSTGRES_USER + value: postgres + - name: POSTGRES_PASSWORD + value: none diff --git a/kubernetes/postgres-service.yml b/kubernetes/postgres-service.yml new file mode 100644 index 0000000..4d03ca0 --- /dev/null +++ b/kubernetes/postgres-service.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-service +spec: + selector: + app: postgres + ports: + - protocol: TCP + port: 5432 + targetPort: 5432 diff --git a/social-app-backend/docker-compose.yml b/social-app-backend/docker-compose.yml index a028f7a..57f8308 100644 --- a/social-app-backend/docker-compose.yml +++ b/social-app-backend/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3" +version: "3.1" services: maildev: diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/admin/AdminController.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/admin/AdminController.java index 985a61e..aec1227 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/admin/AdminController.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/admin/AdminController.java @@ -1,7 +1,6 @@ package razepl.dev.socialappbackend.admin; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import razepl.dev.socialappbackend.admin.interfaces.IAdminController; @@ -16,7 +15,6 @@ import static razepl.dev.socialappbackend.admin.Constants.ADMIN_MAPPING; import static razepl.dev.socialappbackend.admin.Constants.ENDPOINT_MATCHER; -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping(value = ADMIN_MAPPING) diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/auth/AuthController.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/auth/AuthController.java index d4ac2df..f37f401 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/auth/AuthController.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/auth/AuthController.java @@ -4,14 +4,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import razepl.dev.socialappbackend.auth.apicalls.*; import razepl.dev.socialappbackend.auth.interfaces.AuthInterface; import razepl.dev.socialappbackend.auth.interfaces.AuthServiceInterface; -import razepl.dev.socialappbackend.config.oauth.constants.RedirectUrls; import static razepl.dev.socialappbackend.auth.constants.AuthMappings.*; @@ -19,7 +16,6 @@ * Class to control auth endpoints. * It implements {@link AuthInterface}. */ -@Slf4j @RequiredArgsConstructor @RestController @RequestMapping(value = AUTH_MAPPING) diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthFailureHandler.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthFailureHandler.java index 327f84a..3613826 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthFailureHandler.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthFailureHandler.java @@ -23,6 +23,8 @@ public final void onAuthenticationFailure(HttpServletRequest request, AuthenticationException exception) throws IOException { String redirectUrl = frontendUrl + RedirectUrls.FAILURE_URL; + log.error("OAuth failure login. Redirecting to : {}", redirectUrl); + getRedirectStrategy().sendRedirect(request, response, redirectUrl); } } diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthSuccessHandler.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthSuccessHandler.java index 8f29d90..52f66b7 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthSuccessHandler.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OAuthSuccessHandler.java @@ -39,7 +39,6 @@ public final void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { log.error("Principal : {}", authentication.getPrincipal()); - log.error("Credentials : {}", authentication.getCredentials()); StringBuilder redirectBuilder = new StringBuilder(200); diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OidcService.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OidcService.java index 3ef3a40..efb9f12 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OidcService.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/config/oauth/OidcService.java @@ -19,6 +19,8 @@ public class OidcService extends OidcUserService { public final OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException { OidcUser oidcUser = super.loadUser(userRequest); + log.info("Loading OIDC user."); + return oauthUserProcessor.processOAuthUserRegistration(userRequest, oidcUser); } } diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/home/HomeController.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/home/HomeController.java index 052cd8e..2ca716d 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/home/HomeController.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/home/HomeController.java @@ -2,7 +2,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import razepl.dev.socialappbackend.entities.user.User; @@ -17,7 +16,6 @@ /** * Controller for /api/home endpoints. */ -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping(value = HOME_MAPPING) diff --git a/social-app-backend/src/main/java/razepl/dev/socialappbackend/search/SearchController.java b/social-app-backend/src/main/java/razepl/dev/socialappbackend/search/SearchController.java index 2ae6ba1..297b6f6 100644 --- a/social-app-backend/src/main/java/razepl/dev/socialappbackend/search/SearchController.java +++ b/social-app-backend/src/main/java/razepl/dev/socialappbackend/search/SearchController.java @@ -2,7 +2,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,7 +20,6 @@ /** * Controller for /api/search endpoints */ -@Slf4j @RestController @RequiredArgsConstructor @RequestMapping(value = SEARCH_SITE_MAPPING) diff --git a/social-app-frontend/docker-compose.yml b/social-app-frontend/docker-compose.yml index ae111a4..7fbdc64 100644 --- a/social-app-frontend/docker-compose.yml +++ b/social-app-frontend/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3" +version: "3.1" services: frontend: From 08e97a0115ab45047affe1b32b704517d7b4f1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20P=C3=B3=C5=82torak?= Date: Sun, 16 Jul 2023 20:09:26 +0200 Subject: [PATCH 2/2] Added missing envs and yml configs --- README.md | 2 ++ kubernetes/backend-deployment.yml | 17 +++++++++++++++-- kubernetes/maildev-deployment.yml | 20 ++++++++++++++++++++ kubernetes/maildev-service.yml | 14 ++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 kubernetes/maildev-deployment.yml create mode 100644 kubernetes/maildev-service.yml diff --git a/README.md b/README.md index fb22722..405c5c7 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ I used various technologies which I will list below. * makefile, * docker, +* kubernetes, +* minikube, * postman. ## Installation of docker diff --git a/kubernetes/backend-deployment.yml b/kubernetes/backend-deployment.yml index 2715da5..2219d5b 100644 --- a/kubernetes/backend-deployment.yml +++ b/kubernetes/backend-deployment.yml @@ -19,6 +19,19 @@ spec: - containerPort: 8080 env: - name: SPRING_DATASOURCE_URL - value: jdbc:postgresql://postgres:5432/socialapp + value: jdbc:postgresql://postgres-service:5432/socialapp + - name: GOOGLE_CLIENT_ID + value: YourId + - name: GOOGLE_CLIENT_SECRET + value: YourSecret + - name: GITHUB_CLIENT_ID + value: YourID + - name: GITHUB_CLIENT_SECRET + value: YourSecret + - name: FRONTEND_URL + value: http://frontend-service:80 + - name: MAIL_HOST + value: maildev-service dependsOn: - - name: postgres + - name: postgres-service + - name: maildev-service diff --git a/kubernetes/maildev-deployment.yml b/kubernetes/maildev-deployment.yml new file mode 100644 index 0000000..f9ec6b5 --- /dev/null +++ b/kubernetes/maildev-deployment.yml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: maildev-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: maildev + template: + metadata: + labels: + app: maildev + spec: + containers: + - name: maildev + image: maildev/maildev + ports: + - containerPort: 1080 + - containerPort: 1025 diff --git a/kubernetes/maildev-service.yml b/kubernetes/maildev-service.yml new file mode 100644 index 0000000..7fc943d --- /dev/null +++ b/kubernetes/maildev-service.yml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: maildev-service +spec: + selector: + app: maildev + ports: + - protocol: TCP + port: 1080 + targetPort: 1080 + - protocol: TCP + port: 1025 + targetPort: 1025