Skip to content

Commit

Permalink
Merge pull request #118 from AnataAria/vinh
Browse files Browse the repository at this point in the history
Vinh/reactive Ci/CD
  • Loading branch information
PoserDungeon2003 authored Nov 14, 2023
2 parents babd9fd + 25839d2 commit b5a42d4
Show file tree
Hide file tree
Showing 28 changed files with 492 additions and 309 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ build/


## Node JS
package-lock.json
.env
package-lock.json
44 changes: 28 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ pipeline {
environment {
DOCKER_IMAGE = 'anataarisa/ademy'
DOCKER_COMPOSE_NAME = 'ademy-dev-application'
DOCKER_COMPOSE_DEV_FILE = 'docker-compose.dev.yaml'
DOCKER_COMPOSE_QA_FILE = 'docker-compose.qa.yaml'
DOCKER_COMPOSE_PROD_FILE = 'docker-compose.prod.yaml'
DOCKER_IMAGE_BACKEND_API = 'api-backend-server-qa'
DOCKER_IMAGE_FRONTEND_SERVER = 'svelte-frontend-server-qa'
}
tools {
maven 'Arisa CI/CD Maven'
Expand All @@ -17,28 +20,37 @@ pipeline {
}
stage('Clean Docker Enviroments'){
steps{
sh 'docker compose -f ' + DOCKER_COMPOSE_DEV_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' down --rmi all -v'
sh 'docker compose -f ' + DOCKER_COMPOSE_QA_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' down --rmi all -v'
}
}
// stage('Source Testing'){
// steps{
// dir('./api/drawingcouseselling'){
// sh 'mvn test -Pdev'
// }
// // dir('./frontend/my-app'){
// // sh 'pnpm i'
// // sh 'pnpm dev'
// // }
// }
// }
stage('Build docker-compose dev and push images'){
stage('Build docker-compose qa enviroment and push images to docker-hub'){
steps{
withDockerRegistry(credentialsId: 'Arisa Docker Hub Account', url: 'https://index.docker.io/v1/'){
sh 'docker compose -f ' + DOCKER_COMPOSE_DEV_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' build'
sh 'docker compose -f ' + DOCKER_COMPOSE_DEV_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' up -d'
sh 'docker compose -f ' + DOCKER_COMPOSE_QA_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' build'
sh 'docker compose -f ' + DOCKER_COMPOSE_QA_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' up -d'
sh 'docker tag ' + DOCKER_IMAGE_BACKEND_API + ':latest anataarisa/' + DOCKER_IMAGE_BACKEND_API + ':latest'
sh 'docker tag ' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest anataarisa/' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest'
sh 'docker push anataarisa/' + DOCKER_IMAGE_BACKEND_API + ':latest'
sh 'docker push anataarisa/' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest'
sh 'docker rmi anataarisa/api-backend-server-qa:latest anataarisa/svelte-frontend-server-qa:latest'
}
}
}
// stage('Build docker-compose prod and push images for prod deployment'){
// steps{
// withDockerRegistry(credentialsId: 'Arisa Docker Hub Account', url: 'https://index.docker.io/v1/'){
// sh 'docker compose -f ' + DOCKER_COMPOSE_PROD_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' build'
// sh 'docker compose -f ' + DOCKER_COMPOSE_PROD_FILE + ' -p ' + DOCKER_COMPOSE_NAME + ' push'
// // Tag the images with 'latest' before pushing
// sh 'docker tag ' + DOCKER_IMAGE_BACKEND_API + ':latest ' + DOCKER_IMAGE_BACKEND_API + ':latest'
// sh 'docker tag ' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest ' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest'

// // Push the images with the 'latest' tag
// sh 'docker push ' + DOCKER_IMAGE_BACKEND_API + ':latest'
// sh 'docker push ' + DOCKER_IMAGE_FRONTEND_SERVER + ':latest'
// }
// }
// }
}

post {
Expand Down
4 changes: 3 additions & 1 deletion api/drawingcouseselling/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM maven:3.8.5-openjdk-17
LABEL authors="AnataArisa"
WORKDIR /api-backend
ARG API_ENV
COPY . .
RUN mvn clean install -Pdev
ENV SPRING_PROFILES_ACTIVE=${API_ENV}
RUN mvn clean install
ENTRYPOINT ["java", "-jar", "./target/drawingcouseselling-0.1.jar"]
5 changes: 2 additions & 3 deletions api/drawingcouseselling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
<debug.port>5005</debug.port>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
Expand All @@ -243,9 +242,9 @@
</properties>
</profile>
<profile>
<id>qa</id>
<id>staging</id>
<properties>
<activatedProperties>qa</activatedProperties>
<activatedProperties>staging</activatedProperties>
</properties>
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
public CorsFilter corsFilter() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true);
corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
corsConfiguration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://anataarisa.hopto.org:3000"));
corsConfiguration.setAllowedHeaders(Arrays.asList("Origin", "Access-Control-Allow-Origin", "Content-Type",
"Accept", "Authorization", "Origin, Accept", "X-Requested-With",
"Access-Control-Request-Method", "Access-Control-Request-Headers"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public record CourseContentDto(BigDecimal id,
@NotBlank(message = "Description can't be empty")
@NotNull(message = "Description can't be empty")
String description,
@Pattern(regexp = "^(https?://)?(www\\.)?youtube\\.com/watch\\?v=[a-zA-Z0-9_-]+.*$", message = "Invalid YouTube link")
@Pattern(regexp = "^(https?://)?(www\\.)?(youtube\\.com/watch\\?v=|youtu\\.be/|youtube\\.com/embed/)[a-zA-Z0-9_-]+.*$", message = "Invalid YouTube link")
@NotBlank(message = "The youtube link must not be empty")
String videoLink,
ECourseContentType courseType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CourseContentEditDto(BigDecimal id,
String title,
@NotBlank(message = "Description can't be empty")
String description,
@Pattern(regexp = "^(https?://)?(www\\.)?youtube\\.com/watch\\?v=[a-zA-Z0-9_-]+.*$", message = "Invalid YouTube link")
@Pattern(regexp = "^(https?://)?(www\\.)?(youtube\\.com/watch\\?v=|youtu\\.be/|youtube\\.com/embed/)[a-zA-Z0-9_-]+.*$", message = "Invalid YouTube link")
@NotBlank(message = "The youtube link must not be empty")
String videoLink) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public record CustomerDto(BigDecimal customerID,
EGender gender,
@Email(message = "Please enter a valid email address")
@NotBlank(message = "Email can't be empty")
String email, Date joinDate) {
String email,
Date joinDate,
String avatarLink
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public CustomerDto convertEntityToDto(Customer data) {
.birthDate(data.getBirthDate())
.gender(data.getGender())
.email(data.getAccount().getEmail())
.avatarLink(getPath())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface CourseContentCompletionRepository extends JpaRepository<CourseC
"INNER JOIN course_content c2 ON c3.courseContent.id = c2.id" +
" INNER JOIN section s ON c2.section.id = s.id" +
" INNER JOIN course c ON c.id = s.course.id " +
" WHERE c.id = :courseID AND c3.customer.id = :customerID")
" WHERE c.id = :courseID AND c3.customer.id = :customerID AND c3.isDone = true")
public Collection<CourseContentCompletion> getCourseContentCompletionByCustomerID(@Param(value = "customerID") BigDecimal customerID, @Param(value = "courseID") BigDecimal courseID);

@Query("SELECT COUNT(c3) FROM course_content_completion c3 WHERE c3.courseContent.id = :courseSectionID")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Optional<CustomerDto> searchCustomerByEmailDto(String customerEmailDto) {
.gender(data.getGender())
.email(customerEmailDto)
.joinDate(accountService.checkAccountByEmail(customerEmailDto).getCreateDate())
.avatarLink(data.getPath())
.build();
}
assert customerDto != null;
Expand Down
81 changes: 81 additions & 0 deletions api/drawingcouseselling/src/main/resources/application-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
aws:
access:
key:
id: AKIA2EWSF45CBHDRXQJK
s3:
region: ap-southeast-1
bucket:
name: ademyimage
secret:
access:
key: tN7GXYsy2zZHqb1znrfCf/hmNXzdFuRN9MSPdG2P

spring:
datasource:
url: jdbc:mariadb://${DB_HOST:anataarisa.hopto.org}:${DB_PORT:3306}/ademy
# url: jdbc:mariadb://localhost:3307/ademy
username: ${DB_USERNAME:pim}
password: ${DB_PASSWORD:Vinh12345.}
driver-class-name: org.mariadb.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
sql:
init:
encoding: utf-8
# session:
# store-type=jdbc:
mail:
host: smtp.gmail.com
port: 587
username: [email protected]
password: ztgzeyizzyicozuc
properties:
mail:
smtp:
auth: true
starttls:
enable: true
security:
oauth2:
client:
registration:
google:
client-id: 509336143279-ng2g9fdpg8pkt1j3jlj24au6l96hk0qn.apps.googleusercontent.com
client-secret: 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

server:
servlet:
context-path: /api/v1
port: 9090
error:
include-message: always


logging:
level:
org:
springframework:
security: TRACE
hibernate:
type: trace
orm:
jdbc:
bind: trace

jwt-key:
secret-key: ${JWT_KEY:49906c40c2bd2ce2a35571ebf991e74573d0e5cc5db9e032a7b1c5af42c8b038}

paypal:
client:
secret: EHGsrSIQG-aODbOaHmd5YnhCLNS3Zq3x3einniprXjRkABpA-U0UEXy9w_hp-YElLEwsQv6tmQNJ4ZVS
app: AWbOtZPREQ6DxSCza2yGZT82kQTW9T17r8xezCuKARBoBM5jli0FdOPrdRVkytKLdeaaFaiM6k-tHlr6
mode: sandbox


frontend:
url: http://anataarisa.hopto.org:3000/

api:
base:
url: http://anataarisa.hopto.org:7070/api/v1/
Empty file.
7 changes: 6 additions & 1 deletion docker-compose.dev.yaml → docker-compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
build:
context: "./api/drawingcouseselling/"
dockerfile: Dockerfile
args:
- API_ENV=dev
ports:
- "7070:9090"
networks:
Expand All @@ -50,6 +52,8 @@ services:
build:
context: "./frontend/my-app/"
dockerfile: Dockerfile
args:
- ENV_DP=development
ports:
- "3000:3000"
networks:
Expand All @@ -58,5 +62,6 @@ services:
depends_on:
api-backend:
condition: service_healthy

networks:
dev-network:
dev-network:
44 changes: 44 additions & 0 deletions docker-compose.qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3.8'
services:
api-backend:
image: api-backend-server-qa
container_name: api-backend-server-qa
build:
context: "./api/drawingcouseselling/"
dockerfile: Dockerfile
args:
- API_ENV=staging
ports:
- "7070:9090"
networks:
- dev-network
environment:
DB_HOST: anataarisa.hopto.org
DB_PORT: 3306
DB_USERNAME: pim
DB_PASSWORD: Vinh12345.
restart: always
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9090/api/v1/courses"]
interval: 30s
timeout: 10s
retries: 3

front-end:
image: svelte-frontend-server-qa
container_name: svelte-frontend-server-qa
build:
context: "./frontend/my-app/"
dockerfile: Dockerfile
args:
- ENV_DP=testing
ports:
- "3000:3000"
networks:
- dev-network
restart: always
depends_on:
api-backend:
condition: service_healthy
networks:
dev-network:
3 changes: 0 additions & 3 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
.vscode/
Expand Down
4 changes: 4 additions & 0 deletions frontend/my-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Public
PUBLIC_API_BASE_URL_DEV=http://localhost:7070/api/v1/
PUBLIC_API_BASE_URL_PROD=http://anataarisa.hopto.org:7070/api/v1/
PUBLIC_API_BASE_URL_QA=http://anataarisa.hopto.org:7070/api/v1/
5 changes: 4 additions & 1 deletion frontend/my-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM node:latest
WORKDIR /svelte-frontend
ARG ENV_DP
ENV NODE_ENV=${ENV_DP}
RUN npm install -g pnpm
RUN npm i vite
COPY package*.json .
RUN pnpm i
COPY . .
EXPOSE 3000
EXPOSE 24678
ENTRYPOINT [ "pnpm", "dev" ]
RUN pnpm build
ENTRYPOINT [ "node", "build" ]
2 changes: 1 addition & 1 deletion frontend/my-app/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<title>Ademy</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
<script src="https://cdn.tiny.cloud/1/7gq4en8n7fdu1f8nqawf1uqup1tx0smi6v7dc3v1tf3dnhwa/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
<script src="https://cdn.tiny.cloud/1/rin7yni45fy4pbp6hub9mnmcpi5wrhapvxjyll03gr68j3og/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>

%sveltekit.head%
</head>
Expand Down
Loading

0 comments on commit b5a42d4

Please sign in to comment.