Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker complement #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.jar
*.jar
.npm/*
2 changes: 1 addition & 1 deletion back-end
Submodule back-end updated 31 files
+20 −9 .github/workflows/gradle.yml
+15 −0 bin/main/com/github/gkdrateit/Main.kt
+25 −0 bin/main/com/github/gkdrateit/config/Config.kt
+52 −0 bin/main/com/github/gkdrateit/database/Course.kt
+21 −0 bin/main/com/github/gkdrateit/database/DbAdapter.kt
+76 −0 bin/main/com/github/gkdrateit/database/Review.kt
+31 −0 bin/main/com/github/gkdrateit/database/Teacher.kt
+39 −0 bin/main/com/github/gkdrateit/database/User.kt
+183 −0 bin/main/com/github/gkdrateit/service/ApiBase.kt
+55 −0 bin/main/com/github/gkdrateit/service/ApiServer.kt
+113 −0 bin/main/com/github/gkdrateit/service/CourseController.kt
+97 −0 bin/main/com/github/gkdrateit/service/EmailVerificationController.kt
+48 −0 bin/main/com/github/gkdrateit/service/Login.kt
+117 −0 bin/main/com/github/gkdrateit/service/ReviewController.kt
+67 −0 bin/main/com/github/gkdrateit/service/TeacherController.kt
+99 −0 bin/main/com/github/gkdrateit/service/UserController.kt
+58 −0 bin/test/com/github/gkdrateit/service/GeneralApiTest.kt
+69 −0 bin/test/com/github/gkdrateit/service/course/CourseCreate.kt
+75 −0 bin/test/com/github/gkdrateit/service/course/CourseRead.kt
+24 −0 bin/test/com/github/gkdrateit/service/course/TestBase.kt
+71 −0 bin/test/com/github/gkdrateit/service/review/ReviewCreate.kt
+75 −0 bin/test/com/github/gkdrateit/service/review/ReviewDelete.kt
+63 −0 bin/test/com/github/gkdrateit/service/review/ReviewRead.kt
+53 −0 bin/test/com/github/gkdrateit/service/review/TestBase.kt
+58 −0 bin/test/com/github/gkdrateit/service/teacher/TeacherCreate.kt
+49 −0 bin/test/com/github/gkdrateit/service/teacher/TeacherRead.kt
+68 −0 bin/test/com/github/gkdrateit/service/user/UserCreate.kt
+55 −0 bin/test/com/github/gkdrateit/service/user/UserRead.kt
+9 −0 build.gradle.kts
+4 −2 src/main/kotlin/com/github/gkdrateit/database/Review.kt
+15 −7 src/main/kotlin/com/github/gkdrateit/service/ReviewController.kt
17 changes: 9 additions & 8 deletions deploy/back-only/db-init/db-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CREATE TABLE Courses (
c_semester varchar(10) NOT NULL, -- "spring", "fall", "summer", "both"
c_credit decimal(4,2) NOT NULL,
c_degree int NOT NULL, -- 0,
c_category varchar(15) NOT NULL, -- "public", "specialized"
c_status int NOT NULL, -- 0 = "unverified", 1 = "verified"

PRIMARY KEY(c_course_id),
Expand Down Expand Up @@ -81,14 +82,14 @@ VALUES ('莱布尼茨第 128 代传人', '[email protected]');
INSERT INTO teachers (c_teacher_name, c_teacher_email)
VALUES ('等于是', '[email protected]');

INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_status)
VALUES ('B0911011Y', '02', '操作系统研讨课', 4, 'autumn', 2.0, 0, 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_status)
VALUES ('B0912024Y', null, '计算机网络', 1, 'autumn', 3.0, 0, 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_status)
VALUES ('B0911002Y', '01', '数据结构', 2, 'spring', 3.0, 0, 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_status)
VALUES ('B????????', null, '一个未审核通过的课程', 1, 'spring', 3.0, 0, 0);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_category, c_status)
VALUES ('B0911011Y', '02', '操作系统研讨课', 4, 'autumn', 2.0, 0, 'specialized', 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_category, c_status)
VALUES ('B0912024Y', null, '计算机网络', 1, 'autumn', 3.0, 0, 'specialized', 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_category, c_status)
VALUES ('B0911002Y', '01', '数据结构', 2, 'spring', 3.0, 0, 'specialized', 1);
INSERT INTO courses (c_course_code, c_course_code_seq, c_course_name, c_teacher_id, c_semester, c_credit, c_degree, c_category, c_status)
VALUES ('B????????', null, '一个未审核通过的课程', 1, 'spring', 3.0, 0, 'specialized', 0);

INSERT INTO reviews (r_course_id, r_user_id, r_create_time, r_last_update_time, r_overall_rec, r_rate_quality,
r_rate_difficulty, r_rate_workload, r_comment_text, r_my_grade, r_my_major)
Expand Down
3 changes: 2 additions & 1 deletion deploy/back-only/docker-compose.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ services:
environment:
- POSTGRES_PASSWORD=112233445566
- POSTGRES_DB=gkd_rate_it_test
command: [ "postgres" ]
command: [ "postgres" ]

84 changes: 84 additions & 0 deletions deploy/back-only/proxy/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name rateit.com;

add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'token,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,XRequested-With';


location ~ /back/ {
proxy_pass http://127.0.0.1:8080;
}
location ~ /front/ {
proxy_pass http://127.0.0.1:3000;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root html;
# }

}


# HTTPS server

# server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# proxy_pass http://127.0.0.1:8081;
# }
# }

}
14 changes: 10 additions & 4 deletions deploy/back-only/run.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
$Self = Split-Path -Parent $MyInvocation.MyCommand.Source
# Write-Output $Self
$Workspace = $(Get-Item $Self).Parent.Parent.FullName

$Workspace = $(Get-Item $Self).Parent.Parent
Push-Location $Workspace\back-end

Push-Location $Workspace/back-end
./gradlew.bat wrapper

./gradlew.bat wrapper && ./gradlew.bat shadowJar
if ($?)
{
./gradlew.bat shadowJar
}

Pop-Location

Expand All @@ -18,8 +22,10 @@ $ComposeYml = (Get-Content $Self/docker-compose.template).
replace("__WEB_SRC", "$Self\\app").
replace("__JAR_NAME", "$JarName").
replace( "__DB_INIT", "$Self\\db-init")
replace( "__NGINX_CONF", "$Self\\proxy\\nginx.conf")
# Write-Output $ComposeYml
$TmpFile = New-TemporaryFile
$ComposeYml | Out-File -Path $TmpFile.FullName
# Write-Output $TmpFile
$ComposeYml | Out-File $TmpFile.FullName
docker.exe compose --file $TmpFile.FullName up
docker.exe compose --file $TmpFile.FullName rm -fsv
24 changes: 23 additions & 1 deletion deploy/back-only/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ workspace=$(dirname $(dirname $self))

pushd $workspace/back-end


./gradlew wrapper && \
./gradlew shadowJar

Expand All @@ -15,7 +16,28 @@ cp $workspace/back-end/build/libs/*-shadow.jar $self/app

jar_name=$(ls $self/app | grep jar)

compose_yml=$(cat $self/docker-compose.template | sed "s|__WEB_SRC|$self/app|" | sed "s/__JAR_NAME/$jar_name/" | sed "s|__DB_INIT|$self/db-init|")
compose_yml=$(cat $self/docker-compose.template | sed "s|__WEB_SRC|$self/app|" | sed "s/__JAR_NAME/$jar_name/" | sed "s|__DB_INIT|$self/db-init|"| sed "s|__NGINX_CONF|$self/proxy/nginx.conf|")

echo "$compose_yml" | docker compose --file /dev/stdin up
echo "$compose_yml" | docker compose --file /dev/stdin rm -fsv

# nginx:
# image: nginx
# volumes:
# - type: bind
# source: __NGINX_CONF
# target: /etc/nginx/
# command: [ "nginx" ]

# web:
# image: openjdk:17-slim-bullseye
# ports:
# - "8080:8080"
# depends_on:
# - database
# working_dir: /app
# volumes:
# - type: bind
# source: __WEB_SRC
# target: /app
# command: [ "java", "-jar", "__JAR_NAME" ]
11 changes: 11 additions & 0 deletions deploy/complete/app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"port": 8080,
"signSecret": "test_secret_gkd_rate_it",
"maintainerEmailAddr": "???",
"maintainerEmailPassword": "???",
"maintainerEmailSmtpHostName": "smtp-mail.outlook.com",
"maintainerEmailSmtpHostPort": 587,
"databaseURL": "jdbc:postgresql://database:5432/gkd_rate_it_test",
"databaseUser": "postgres",
"databasePassword": "112233445566"
}
36 changes: 36 additions & 0 deletions deploy/complete/build_from_src.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$Self = Split-Path -Parent $MyInvocation.MyCommand.Source
# Write-Output $Self
$Workspace = $(Get-Item $Self).Parent.Parent.FullName

Push-Location $Workspace\front-end
npm ci --cache .npm
if ($?){
npm run build
}
Pop-Location

# Push-Location $Workspace\back-end

# ./gradlew.bat wrapper

# if ($?){
# ./gradlew.bat shadowJar
# }

# Pop-Location

# Copy-Item $Workspace\\back-end\\build\\libs\\*-shadow.jar $Self\\app

# $JarName = (Get-ChildItem -Path $Self\app\* -Include "*.jar")[0].Name
# # Write-Output $JarName

# $ComposeYml = (Get-Content $Self/docker-compose.template).
# replace("__WEB_SRC", "$Self\\app").
# replace("__JAR_NAME", "$JarName").
# replace( "__DB_INIT", "$Self\\db-init")
# # Write-Output $ComposeYml
# $TmpFile = New-TemporaryFile
# # Write-Output $TmpFile
# $ComposeYml | Out-File $TmpFile.FullName
# docker.exe compose --file $TmpFile.FullName up
# docker.exe compose --file $TmpFile.FullName rm -fsv
25 changes: 19 additions & 6 deletions deploy/complete/build_from_src.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ self="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
workspace=$(dirname $(dirname $self))
# echo $workspace

# nohup $workspace/deploy/back-only/run.sh &

cd $workspace/front-end && \
npm ci && \
npm run build
# cd $workspace/back-end && \
# ./gradlew wrapper && \
# ./gradlew shadowJar

cd $workspace/back-end && \
./gradlew wrapper && \
./gradlew shadowJar
# cp $workspace/back-end/build/libs/*-shadow.jar $self/app

# cd $workspace/front-end && \
# # npm ci --cache .npm && \
# npm run build
# # npm run preview
# # npm run dev

jar_name=$(ls $self/app | grep jar)

compose_yml=$(cat $self/docker-compose.template | sed "s|__WEB_SRC|$self/app|" | sed "s/__JAR_NAME/$jar_name/" | sed "s|__DB_INIT|$self/db-init|"| sed "s|__DIST_SRC|$workspace/front-end/dist|"| sed "s|__NGINX_CONF|$self/proxy/nginx.conf|")

# echo "$compose_yml"
echo "$compose_yml" | docker compose --file /dev/stdin up
# echo "$compose_yml" | docker compose --file /dev/stdin rm -fsv

Loading