Merge branch 'dev'
This commit is contained in:
commit
f31a3f2238
|
@ -0,0 +1,49 @@
|
||||||
|
# 定义CI/CD流水线的阶段
|
||||||
|
stages:
|
||||||
|
- build # 第一阶段:构建应用程序
|
||||||
|
- build-docker # 第二阶段:构建Docker镜像
|
||||||
|
- deploy # 第三阶段:部署应用程序
|
||||||
|
|
||||||
|
# 定义全局变量
|
||||||
|
variables:
|
||||||
|
CONTAINER_NAME: "bunny-auth-server" # Docker容器名称
|
||||||
|
DOCKER_TAG: "4.0.0" # Docker镜像标签版本
|
||||||
|
|
||||||
|
# 构建任务
|
||||||
|
build-job:
|
||||||
|
stage: build # 指定此任务属于build阶段
|
||||||
|
script:
|
||||||
|
# 打印编译开始信息
|
||||||
|
- echo "Compiling the code..."
|
||||||
|
# 使用Maven编译Java项目,跳过测试
|
||||||
|
- mvn clean package -DskipTests
|
||||||
|
# 打印编译完成信息
|
||||||
|
- echo "Compile complete."
|
||||||
|
# 从Docker Hub拉取OpenJDK基础镜像
|
||||||
|
- docker pull openjdk:24-ea-17-jdk-oraclelinux9
|
||||||
|
# 打印拉取完成信息
|
||||||
|
- echo "docker pull complete."
|
||||||
|
# 使用Dockerfile构建Docker镜像,并打上标签
|
||||||
|
- docker build -f Dockerfile -t $CONTAINER_NAME:$DOCKER_TAG .
|
||||||
|
# 打印构建成功信息
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
# 部署任务
|
||||||
|
deploy-job:
|
||||||
|
stage: deploy # 指定此任务属于deploy阶段
|
||||||
|
environment: production # 指定部署环境为production
|
||||||
|
script:
|
||||||
|
# 打印部署开始信息
|
||||||
|
- echo "Deploying application..."
|
||||||
|
# 停止正在运行的容器(如果存在),|| true确保命令失败不会中断脚本
|
||||||
|
- docker stop $CONTAINER_NAME || true
|
||||||
|
# 删除容器(如果存在)
|
||||||
|
- docker rm $CONTAINER_NAME || true
|
||||||
|
# 运行新的Docker容器
|
||||||
|
# -d: 后台运行
|
||||||
|
# -p: 端口映射(7070和8000)
|
||||||
|
# --name: 容器名称
|
||||||
|
# --restart always: 总是自动重启
|
||||||
|
- docker run -d -p 7070:7070 -p 8000:8000 --name $CONTAINER_NAME --restart always $CONTAINER_NAME:$DOCKER_TAG
|
||||||
|
# 打印部署成功信息
|
||||||
|
- echo "Application successfully deployed."
|
|
@ -0,0 +1,256 @@
|
||||||
|
# Gitlab安装
|
||||||
|
|
||||||
|
完全笔记《安装GitLabel》 :https://www.yuque.com/bunny-6ixda/bgxtva/wtw4x4r8kbvxwgac?singleDoc#
|
||||||
|
|
||||||
|
## Docker安装
|
||||||
|
|
||||||
|
- docker镜像:
|
||||||
|
|
||||||
|
- https://hub.docker.com/r/gitlab/gitlab-ee/tags?name=17.9.6
|
||||||
|
- https://hub.docker.com/r/gitlab/gitlab-runner/tags?name=17.11.0
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get remove docker docker-engine docker.io containerd runc
|
||||||
|
sudo apt update
|
||||||
|
sudo apt upgrade
|
||||||
|
sudo apt-get install ca-certificates curl gnupg lsb-release
|
||||||
|
# 添加Docker官方GPG密钥
|
||||||
|
sudo curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
|
||||||
|
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
|
# 安装docker
|
||||||
|
sudo apt-get install docker-ce docker-ce-cli containerd.io
|
||||||
|
# 默认情况下,只有root用户和docker组的用户才能运行Docker命令。我们可以将当前用户添加到docker组,以避免每次使用Docker时都需要使用sudo,设置完成后退出当前用户之后再进入既可
|
||||||
|
sudo usermod -aG docker $USER
|
||||||
|
# 运行docker
|
||||||
|
sudo systemctl start docker
|
||||||
|
# 安装工具
|
||||||
|
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
|
||||||
|
# 重启docker
|
||||||
|
sudo service docker restart
|
||||||
|
# 重启终端生效
|
||||||
|
exit
|
||||||
|
```
|
||||||
|
|
||||||
|
配置镜像源
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 创建目录
|
||||||
|
sudo mkdir -p /etc/docker
|
||||||
|
# 写入配置文件
|
||||||
|
sudo tee /etc/docker/daemon.json <<-'EOF'
|
||||||
|
{
|
||||||
|
"registry-mirrors": [
|
||||||
|
"https://docker-0.unsee.tech",
|
||||||
|
"https://docker-cf.registry.cyou",
|
||||||
|
"https://docker.1panel.live"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 重启docker服务
|
||||||
|
sudo systemctl daemon-reload && sudo systemctl restart docker
|
||||||
|
```
|
||||||
|
|
||||||
|
## 环境搭建
|
||||||
|
|
||||||
|
### 安装JDK21
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装JDK21
|
||||||
|
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
|
||||||
|
sudo dpkg -i jdk-21_linux-x64_bin.deb
|
||||||
|
java --version
|
||||||
|
```
|
||||||
|
|
||||||
|
### Maven 3.8.8安装
|
||||||
|
|
||||||
|
#### 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装maven
|
||||||
|
wget https://archive.apache.org/dist/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz
|
||||||
|
sudo mkdir -p /opt/maven
|
||||||
|
sudo tar -xzf apache-maven-3.8.8-bin.tar.gz -C /opt/maven
|
||||||
|
sudo mv /opt/maven/apache-maven-3.8.8 /opt/maven/maven-3.8.8
|
||||||
|
|
||||||
|
# 修改镜像配置
|
||||||
|
cd /opt/maven/maven-3.8.8/conf
|
||||||
|
# 赋予权限修改
|
||||||
|
sudo chmod 666 settings.xml
|
||||||
|
|
||||||
|
# 编写配置
|
||||||
|
sudo vim /etc/profile
|
||||||
|
|
||||||
|
# 添加以下内容
|
||||||
|
# export PATH=$PATH:/opt/maven/maven-3.8.8/bin
|
||||||
|
|
||||||
|
# 刷新配置
|
||||||
|
source /etc/profile
|
||||||
|
mvn -V
|
||||||
|
```
|
||||||
|
|
||||||
|
#### maven的镜像
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<mirror>
|
||||||
|
<id>aliyun</id>
|
||||||
|
<name>Aliyun Maven Mirror</name>
|
||||||
|
<url>https://maven.aliyun.com/repository/public</url>
|
||||||
|
<mirrorOf>central</mirrorOf>
|
||||||
|
</mirror>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安装Gitlab
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/focal/main/g/gitlab-ce/gitlab-ce_18.0.0-ce.0_amd64.deb
|
||||||
|
|
||||||
|
# dpkg
|
||||||
|
sudo dpkg -i gitlab-ce_18.0.0-ce.0_amd64.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
### 编辑配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 编辑站点
|
||||||
|
sudo vim /etc/gitlab/gitlab.rb
|
||||||
|
```
|
||||||
|
|
||||||
|
修改下面内容
|
||||||
|
|
||||||
|
```bash
|
||||||
|
external_url 'http://192.168.95.134:3001'
|
||||||
|
```
|
||||||
|
|
||||||
|
应用配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 应用配置
|
||||||
|
sudo gitlab-ctl reconfigure
|
||||||
|
```
|
||||||
|
|
||||||
|
### 常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 服务控制
|
||||||
|
sudo gitlab-ctl start
|
||||||
|
sudo gitlab-ctl status
|
||||||
|
sudo gitlab-ctl stop
|
||||||
|
|
||||||
|
# 应用配置
|
||||||
|
sudo gitlab-ctl reconfigure
|
||||||
|
|
||||||
|
# 重启
|
||||||
|
sudo gitlab-ctl restart
|
||||||
|
```
|
||||||
|
|
||||||
|
### 查看密码
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 24 小时后自动删除
|
||||||
|
sudo cat /etc/gitlab/initial_root_password
|
||||||
|
```
|
||||||
|
|
||||||
|
## 安装Gitlab-Runner
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 需要 gitlab-runner-helper-images
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner-helper-images/gitlab-runner-helper-images_18.0.1-1_all.deb
|
||||||
|
sudo dpkg -i gitlab-runner-helper-images_18.0.1-1_all.deb
|
||||||
|
|
||||||
|
# 之后安装 gitlab-runner
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner/gitlab-runner_18.0.1-1_amd64.deb
|
||||||
|
sudo dpkg -i gitlab-runner_18.0.1-1_amd64.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
### 先下载后安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner-helper-images/gitlab-runner-helper-images_18.0.1-1_all.deb
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner/gitlab-runner_18.0.1-1_amd64.deb
|
||||||
|
|
||||||
|
# dpkg
|
||||||
|
sudo dpkg -i gitlab-runner-helper-images_18.0.1-1_all.deb
|
||||||
|
sudo dpkg -i gitlab-runner_18.0.1-1_amd64.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
### 配置Gitlab-Runner用户
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> 如果有需要清理缓存:`sudo rm -rf /opt/maven/maven-3.8.8/conf/builds/**`**
|
||||||
|
>
|
||||||
|
> gitlab-ce:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/focal/main/g/gitlab-ce/
|
||||||
|
>
|
||||||
|
> gitlab-runner-helper-images:https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner-helper-images/
|
||||||
|
>
|
||||||
|
> gitlab-runner:https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/ubuntu/pool/focal/main/g/gitlab-runner/
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo gitlab-runner uninstall
|
||||||
|
sudo gitlab-runner install --working-directory /home/gitlab-runner --user root
|
||||||
|
sudo systemctl restart gitlab-runner
|
||||||
|
```
|
||||||
|
|
||||||
|
### 检查 GitLab Runner 配置
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo vim /etc/gitlab-runner/config.toml
|
||||||
|
```
|
||||||
|
|
||||||
|
修改文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
[[runners]]
|
||||||
|
name = "my-runner"
|
||||||
|
executor = "shell"
|
||||||
|
shell = "bash"
|
||||||
|
user = "gitlab-runner" # 确保用户有权限
|
||||||
|
working_directory = "/home/gitlab-runner"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 检查 Maven 安装目录权限
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo chmod 777 -R /opt/maven/maven-3.8.8
|
||||||
|
sudo chmod 777 -R /opt/maven/maven-3.8.8/
|
||||||
|
sudo chown -R gitlab-runner:gitlab-runner /opt/maven/maven-3.8.8/
|
||||||
|
```
|
||||||
|
|
||||||
|
## CI/CD脚本示例
|
||||||
|
|
||||||
|
如果构建出现`pending`情况大部分情况下,是文件写错了,要么是`Gitlab-Runner`标签没写对
|
||||||
|
|
||||||
|
```yml
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- build-docker
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
variables:
|
||||||
|
CONTAINER_NAME: "bunny-auth-server"
|
||||||
|
DOCKER_TAG: "4.0.0"
|
||||||
|
|
||||||
|
build-job:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- echo "Compiling the code..."
|
||||||
|
- mvn clean package -DskipTests
|
||||||
|
- echo "Compile complete."
|
||||||
|
- docker pull openjdk:24-ea-17-jdk-oraclelinux9
|
||||||
|
- echo "docker pull complete."
|
||||||
|
- docker build -f Dockerfile -t $CONTAINER_NAME:$DOCKER_TAG .
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
deploy-job:
|
||||||
|
stage: deploy
|
||||||
|
environment: production
|
||||||
|
script:
|
||||||
|
- echo "Deploying application..."
|
||||||
|
- docker stop $CONTAINER_NAME || true
|
||||||
|
- docker rm $CONTAINER_NAME || true
|
||||||
|
- docker run -d -p 7070:7070 -p 8000:8000 --name $CONTAINER_NAME --restart always $CONTAINER_NAME:$DOCKER_TAG
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
```
|
|
@ -7,7 +7,7 @@
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>auh-api</artifactId>
|
<artifactId>auth-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>auh-api</name>
|
<name>auh-api</name>
|
|
@ -24,7 +24,7 @@ public class IndexController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "生成验证码", description = "生成验证码")
|
@Operation(summary = "生成验证码", description = "生成验证码")
|
||||||
@GetMapping("public/check-code")
|
@GetMapping("/api/image/public/check-code")
|
||||||
public ResponseEntity<byte[]> checkCode() {
|
public ResponseEntity<byte[]> checkCode() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.IMAGE_JPEG);
|
headers.setContentType(MediaType.IMAGE_JPEG);
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
@ -88,7 +88,7 @@
|
||||||
<div class="carousel slide" id="carouselExampleIndicators">
|
<div class="carousel slide" id="carouselExampleIndicators">
|
||||||
<div class="carousel-inner">
|
<div class="carousel-inner">
|
||||||
<div class="carousel-item active">
|
<div class="carousel-item active">
|
||||||
<img alt="验证码图片" class="d-block w-50" src="/public/checkCode" style="margin: 0 auto">
|
<img alt="验证码图片" class="d-block w-50" src="/api/image/public/check-code" style="margin: 0 auto">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
2
pom.xml
2
pom.xml
|
@ -19,7 +19,7 @@
|
||||||
<module>service</module>
|
<module>service</module>
|
||||||
<module>dao</module>
|
<module>dao</module>
|
||||||
<module>auth-core</module>
|
<module>auth-core</module>
|
||||||
<module>auh-api</module>
|
<module>auth-api</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class LoginContext {
|
||||||
this.strategies = strategies;
|
this.strategies = strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行登录策略
|
* 执行登录策略
|
||||||
* 根据情况判断 type 是否为空
|
* 根据情况判断 type 是否为空
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
|
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.util.matcher.RegexRequestMatcher;
|
import org.springframework.security.web.util.matcher.RegexRequestMatcher;
|
||||||
|
|
||||||
|
@ -46,7 +47,10 @@ public class WebSecurityConfig {
|
||||||
// 跨域访问权限,如果需要可以关闭后自己配置跨域访问
|
// 跨域访问权限,如果需要可以关闭后自己配置跨域访问
|
||||||
.cors(AbstractHttpConfigurer::disable)
|
.cors(AbstractHttpConfigurer::disable)
|
||||||
// 前后端分离不需要---因为是无状态的
|
// 前后端分离不需要---因为是无状态的
|
||||||
.sessionManagement(AbstractHttpConfigurer::disable)
|
// .sessionManagement(AbstractHttpConfigurer::disable)
|
||||||
|
.sessionManagement(session ->
|
||||||
|
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
|
)
|
||||||
// 前后端分离不需要---记住我
|
// 前后端分离不需要---记住我
|
||||||
.rememberMe(AbstractHttpConfigurer::disable)
|
.rememberMe(AbstractHttpConfigurer::disable)
|
||||||
.authorizeHttpRequests(authorize -> authorize
|
.authorizeHttpRequests(authorize -> authorize
|
||||||
|
|
Loading…
Reference in New Issue