Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
egcodes committed Apr 22, 2024
1 parent 595d0a3 commit 1f5cd57
Show file tree
Hide file tree
Showing 39 changed files with 483 additions and 173 deletions.
4 changes: 2 additions & 2 deletions Dockerfile-app
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:21-jdk
MAINTAINER egcodes
COPY target/hsw-1.0.0.jar ./
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Djava.security.egd=file:/dev/./urandom","-jar","/hsw-1.0.0.jar"]
COPY target/hsw-0.7.2.jar ./
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Djava.security.egd=file:/dev/./urandom","-jar","/hsw-0.7.2.jar"]
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# HSW BE Service

Site: https://www.hackerupdates.com

<img src="images/architecture.png">

## Used libraries
Expand All @@ -7,7 +11,7 @@
* spring-boot-starter-security
* spring-boot-starter-cache
* spring-boot-starter-test
* springfox-swagger-ui
* springdoc-openapi
* mapstruct
* h2
* Lombok
Expand Down Expand Up @@ -47,3 +51,7 @@ $ kubectl apply -f kube-postgres.yaml
$ kubectl apply -f kube-hsw.yaml
$ kubectl apply -f kube-nginx.yaml
```

## Screenshots
<img src="images/web-dark.png" width="600">
<img src="images/web-light.png" width="600">
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ services:
- web_network
depends_on:
- hsw-service
redis-service:
image: redis:latest
networks:
- db_network
postgres-service:
image: postgres:latest
volumes:
Expand Down
Binary file added images/web-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/web-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion kube-hsw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,32 @@ apiVersion: v1
kind: Service
metadata:
name: hsw-service
labels:
app: hsw
spec:
selector:
app: hsw
ports:
- protocol: TCP
name: http-traffic
port: 8080
targetPort: 8080

---

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: hsw-service-monitor
spec:
selector:
matchLabels:
app: hsw
endpoints:
- port: http-traffic
path: "/api/actuator/prometheus"

---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -48,10 +64,16 @@ spec:
spec:
containers:
- name: hsw
image: hsw:latest
image: hsw:0.7.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /api/actuator/health
port: 8080
initialDelaySeconds: 25
periodSeconds: 5
initContainers:
- name: init-container
image: busybox:latest
Expand Down
10 changes: 8 additions & 2 deletions kube-nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
replicas: 2
selector:
matchLabels:
app: nginx
Expand All @@ -32,11 +32,17 @@ spec:
spec:
containers:
- name: nginx
image: nginx-hsw:latest
image: nginx-hsw:0.7.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
- containerPort: 443
readinessProbe:
httpGet:
path: /ready
port: 80
initialDelaySeconds: 3
periodSeconds: 3
initContainers:
- name: init-container
image: busybox:latest
Expand Down
20 changes: 19 additions & 1 deletion kube-postgres-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ spec:
- ReadWriteMany
resources:
requests:
storage: 25Gi
storage: 25Gi

---

apiVersion: v1
kind: PersistentVolume
metadata:
name: postgres-volume
labels:
type: local
app: postgres
spec:
storageClassName: manual
capacity:
storage: 25Gi
accessModes:
- ReadWriteMany
hostPath:
path: /data/postgresql
2 changes: 1 addition & 1 deletion kube-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kind: Deployment
metadata:
name: postgres
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app: postgres
Expand Down
31 changes: 31 additions & 0 deletions kube-redis-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: redis-volume-claim
labels:
app: redis
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi

---

apiVersion: v1
kind: PersistentVolume
metadata:
name: redis-volume
labels:
type: local
app: redis
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data/redis
41 changes: 41 additions & 0 deletions kube-redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
type: NodePort
ports:
- protocol: TCP
port: 6379
targetPort: 6379

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:latest
ports:
- containerPort: 6379
volumeMounts:
- name: redisdata
mountPath: /data
volumes:
- name: redisdata
persistentVolumeClaim:
claimName: redis-volume-claim
9 changes: 8 additions & 1 deletion nginx/hackerupdates.com.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,12 @@ server {
proxy_pass http://hsw-service:8080;
}


location /api/actuator {
deny all;
return 403;
}
location /api/swagger-ui/ {
deny all;
return 403;
}
}
33 changes: 23 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.hackerupdates</groupId>
<artifactId>hsw</artifactId>
<version>1.0.0</version>
<version>0.7.2</version>
<name>hsw</name>
<description>HackerUpdates</description>

Expand All @@ -39,12 +39,30 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand All @@ -57,14 +75,9 @@
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/hackerupdates/hsw/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableScheduling
@EnableAsync
@EnableTransactionManagement
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
//@EnableScheduling
//@EnableCaching
//@EnableAsync
//@EnableTransactionManagement
@SpringBootApplication
public class Application {

public static void main(String[] args) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/hackerupdates/hsw/config/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hackerupdates.hsw.config;

import com.hackerupdates.hsw.constants.Constant;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CacheConfig {

@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager(Constant.CACHE_NAME_FOR_TOKEN);
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/hackerupdates/hsw/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hackerupdates.hsw.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import java.time.Duration;

@Configuration
public class RedisConfig {

@Bean
public RedisTemplate<String, Object> redisTemplate(
RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
return template;
}
}
Loading

0 comments on commit 1f5cd57

Please sign in to comment.