mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-02-08 09:51:56 +08:00
Compare commits
3 Commits
908dcf8043
...
9065558c5d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9065558c5d | ||
|
|
8c096cba8d | ||
|
|
6150fecef9 |
103
Jenkinsfile-online
Normal file
103
Jenkinsfile-online
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
node {
|
||||||
|
label 'maven'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters {
|
||||||
|
string(name:'TAG_NAME',defaultValue: '',description:'')
|
||||||
|
}
|
||||||
|
|
||||||
|
environment {
|
||||||
|
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
|
||||||
|
GITHUB_CREDENTIAL_ID = 'github-id'
|
||||||
|
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
|
||||||
|
REGISTRY = 'docker.io'
|
||||||
|
DOCKERHUB_NAMESPACE = 'docker_username'
|
||||||
|
GITHUB_ACCOUNT = 'kubesphere'
|
||||||
|
APP_NAME = 'devops-java-sample'
|
||||||
|
}
|
||||||
|
|
||||||
|
stages {
|
||||||
|
stage ('checkout scm') {
|
||||||
|
steps {
|
||||||
|
checkout(scm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage ('unit test') {
|
||||||
|
steps {
|
||||||
|
container ('maven') {
|
||||||
|
sh 'mvn clean -gs `pwd`/configuration/settings.xml test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage ('build & push') {
|
||||||
|
steps {
|
||||||
|
container ('maven') {
|
||||||
|
sh 'mvn -Dmaven.test.skip=true -gs `pwd`/configuration/settings.xml clean package'
|
||||||
|
sh 'docker build -f Dockerfile-online -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER .'
|
||||||
|
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$DOCKER_CREDENTIAL_ID" ,)]) {
|
||||||
|
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
|
||||||
|
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('push latest'){
|
||||||
|
when{
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
|
steps{
|
||||||
|
container ('maven') {
|
||||||
|
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
|
||||||
|
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('deploy to dev') {
|
||||||
|
when{
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
input(id: 'deploy-to-dev', message: 'deploy to dev?')
|
||||||
|
kubernetesDeploy(configs: 'deploy/dev-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('push with tag'){
|
||||||
|
when{
|
||||||
|
expression{
|
||||||
|
return params.TAG_NAME =~ /v.*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
container ('maven') {
|
||||||
|
input(id: 'release-image-with-tag', message: 'release image with tag?')
|
||||||
|
withCredentials([usernamePassword(credentialsId: "$GITHUB_CREDENTIAL_ID", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
|
||||||
|
sh 'git config --global user.email "kubesphere@yunify.com" '
|
||||||
|
sh 'git config --global user.name "kubesphere" '
|
||||||
|
sh 'git tag -a $TAG_NAME -m "$TAG_NAME" '
|
||||||
|
sh 'git push http://$GIT_USERNAME:$GIT_PASSWORD@github.com/$GITHUB_ACCOUNT/devops-java-sample.git --tags --ipv4'
|
||||||
|
}
|
||||||
|
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
|
||||||
|
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:$TAG_NAME '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('deploy to production') {
|
||||||
|
when{
|
||||||
|
expression{
|
||||||
|
return params.TAG_NAME =~ /v.*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
input(id: 'deploy-to-production', message: 'deploy to production?')
|
||||||
|
kubernetesDeploy(configs: 'deploy/prod-ol/**', enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
|||||||
import com.ruoyi.common.core.annotation.Excel;
|
import com.ruoyi.common.core.annotation.Excel;
|
||||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||||
import com.ruoyi.common.core.annotation.Excel.Type;
|
import com.ruoyi.common.core.annotation.Excel.Type;
|
||||||
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.annotation.Excels;
|
import com.ruoyi.common.core.annotation.Excels;
|
||||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||||
import com.ruoyi.common.core.xss.Xss;
|
import com.ruoyi.common.core.xss.Xss;
|
||||||
@@ -116,7 +117,7 @@ public class SysUser extends BaseEntity
|
|||||||
|
|
||||||
public static boolean isAdmin(Long userId)
|
public static boolean isAdmin(Long userId)
|
||||||
{
|
{
|
||||||
return userId != null && 1L == userId;
|
return UserConstants.isAdmin(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getDeptId()
|
public Long getDeptId()
|
||||||
|
|||||||
@@ -80,4 +80,9 @@ public class UserConstants
|
|||||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||||
|
|
||||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||||
|
|
||||||
|
public static boolean isAdmin(Long userId)
|
||||||
|
{
|
||||||
|
return userId != null && 1L == userId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- RuoYi Common Security -->
|
<!-- RuoYi Common Core -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-security</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|||||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
import com.ruoyi.common.core.constant.UserConstants;
|
||||||
|
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||||
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
import com.ruoyi.common.sensitive.annotation.Sensitive;
|
||||||
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
import com.ruoyi.common.sensitive.enums.DesensitizedType;
|
||||||
import com.ruoyi.system.api.model.LoginUser;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据脱敏序列化过滤
|
* 数据脱敏序列化过滤
|
||||||
@@ -55,9 +55,9 @@ public class SensitiveJsonSerializer extends JsonSerializer<String> implements C
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LoginUser securityUser = SecurityUtils.getLoginUser();
|
Long userId = SecurityContextHolder.getUserId();
|
||||||
// 管理员不脱敏
|
// 管理员不脱敏
|
||||||
return !securityUser.getSysUser().isAdmin();
|
return !UserConstants.isAdmin(userId);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user