Dockerfile,添加一个hello world。

This commit is contained in:
洛洛希雅Lolosia 2024-04-25 23:23:34 +08:00
parent 92c44ecc26
commit 3a0c4d02ed
6 changed files with 88 additions and 30 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
#制定java镜像的版本
FROM java:17
#声明作者
LABEL org.opencontainers.image.authors="Lolosia"
#进入到镜像内app目录下面类似cd
WORKDIR /app/
#复制fat.jar到镜像内app目录下
ADD ./build/libs/*-fat.jar /app/
RUN mv *-fat.jar app.jar
#对外暴露的端口
EXPOSE 58801
#程序启动脚本
CMD java -jar app.jar

42
docker_shell.sh Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
declare name='lolosia-backend'
echo '停止容器:' ${name}
docker stop ${name}
echo '删除容器:' ${name}
docker rm ${name}
decare imageId=$(docker images -q --filter "reference=$name")
# 判断旧镜像是否存在
if [ -n "$imageId" ];then
decare imageId2=$(docker images -q --filter "reference=$name:old")
# 判断之前是否还有其他的旧镜像
if [ -n "$imageId2" ];then
# 删除这个旧镜像
docker rmi "$imageId2"
fi
# 修改旧镜像的名字为 名字:old
docker tag "$imageId" "$name:old"
fi
echo "构建新版镜像: $name..."
docker build -t "$name" .
if [ -n "$imageId" ];then
#删除旧的镜像
echo "删除镜像: $name:old"
docker rmi "$imageId"
fi
echo "启动新版容器: $name..."
mkdir -p /home/lolosia-web/work
docker run -p 58801:58801 -d --restart=always -v -v /home/lolosia-web/work:/app/work --name ${name} ${name}

View File

@ -3,12 +3,15 @@ package top.lolosia.web.controller
import top.lolosia.web.service.HomeService import top.lolosia.web.service.HomeService
import top.lolosia.web.util.bundle.Bundle import top.lolosia.web.util.bundle.Bundle
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.io.buffer.DefaultDataBufferFactory
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.server.reactive.ServerHttpRequest import org.springframework.http.server.reactive.ServerHttpRequest
import org.springframework.http.server.reactive.ServerHttpResponse import org.springframework.http.server.reactive.ServerHttpResponse
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono
import java.net.URI import java.net.URI
@RestController @RestController
@ -17,10 +20,19 @@ class HomeController {
@Autowired @Autowired
lateinit var service: HomeService lateinit var service: HomeService
@GetMapping("/") @GetMapping(path = ["/", "/api/"])
fun home(resp: ServerHttpResponse) { fun home(resp: ServerHttpResponse): Mono<Void> {
resp.statusCode = HttpStatus.FOUND // resp.statusCode = HttpStatus.FOUND
resp.headers.location = URI.create("/oAuth/") // resp.headers.location = URI.create("/oAuth/")
resp.statusCode = HttpStatus.OK
resp.headers.contentType = MediaType.parseMediaType("text/plain;charset=UTF-8")
return resp.writeWith(
Mono.just(
DefaultDataBufferFactory.sharedInstance.wrap(
"你好这里是Lolosia的后端".toByteArray(Charsets.UTF_8)
)
)
)
} }
private val ServerHttpRequest.sub: String private val ServerHttpRequest.sub: String

View File

@ -14,14 +14,14 @@ import jakarta.persistence.Entity
import jakarta.persistence.Table import jakarta.persistence.Table
import jakarta.persistence.Id import jakarta.persistence.Id
@DbName("session") @DbName("db")
@Entity @Entity
@Table(name = "Sessions") @Table(name = "Sessions")
class SessionEntity : Model("session") { class SessionEntity : Model("db") {
companion object : ModelCompanion { companion object : ModelCompanion {
@JvmStatic @JvmStatic
override val database get() = DB.byName("session") override val database get() = DB.byName("db")
} }
@Id @Id

View File

@ -12,12 +12,12 @@ import java.sql.Timestamp
import java.util.UUID import java.util.UUID
import jakarta.persistence.MappedSuperclass import jakarta.persistence.MappedSuperclass
@DbName("system") @DbName("db")
@MappedSuperclass @MappedSuperclass
abstract class SystemModel : Model("system") { abstract class SystemModel : Model("db") {
companion object : ModelCompanion { companion object : ModelCompanion {
@JvmStatic @JvmStatic
override val database get() = DB.byName("system") override val database get() = DB.byName("db")
} }
var createdBy: UUID? = null var createdBy: UUID? = null

View File

@ -1,27 +1,12 @@
datasource: datasource:
db: db:
username: "root" username: ""
password: "123456" password: ""
driver: "org.sqlite.JDBC" driver: "org.mariadb.jdbc.Driver"
url: "jdbc:sqlite:work/database/db.sqlite" url: "jdbc:mariadb://172.17.0.1:3306/lolosia?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8"
decision:
username: "root"
password: "123456"
driver: "org.sqlite.JDBC"
url: "jdbc:sqlite:work/database/decision.sqlite"
session:
username: "root"
password: "123456"
driver: "org.sqlite.JDBC"
url: "jdbc:sqlite:work/database/session.sqlite"
system:
username: "root"
password: "123456"
driver: "org.sqlite.JDBC"
url: "jdbc:sqlite:work/database/system.sqlite"
server: server:
port: 8002 port: 58801
spring: spring:
devtools: devtools: