美文网首页
Contrast 部署到web-sphere Liberty

Contrast 部署到web-sphere Liberty

作者: 小明今晚加班 | 来源:发表于2019-08-27 20:54 被阅读0次

思路:将Contrast配置到liberty上,希望当liberty运行的时候,开启Contrast;首先在项目的build.gradle中添加Contrast的必要依赖;然后将项目打成war;接下来在自定义目录/mydocker中创建Dockerfile文件并编辑;将项目war包拷贝到自定义目录/mydocker中,将Contrast.xxx.jar拷贝到/mydocker目录中;最后构建image。

  1. build.gradle配置文件内容如下,
apply plugin: 'application'
apply plugin: 'war'
apply plugin: 'liberty'
apply plugin: 'docker'

group = 'com.cczhao'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.6.3'
        
        classpath('se.transmode.gradle:gradle-docker:1.2')
    }
}

//configure Contrast
configurations {
    contrastAgent
}
repositories {
    mavenCentral()
}

def contrast_version = "3.6.3.8220"

dependencies {
    //Contrast configuration
    contrastAgent "com.contrastsecurity:contrast-agent:${contrast_version}"
    
    libertyRuntime group:'io.openliberty', name:'openliberty-runtime', version:'[17.0.0.4,)'
    
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.7.RELEASE'
    //testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testCompile group:'junit', name:'junit', version:'4.12'
}

application {
    mainClassName = "com.ihep.ac.TestcontrastApplication"
}

jar{
    baseName='gradle-docker-contrast'
    version='0.1.0'
}

ext {
    appName = project.name
    testServerHttpPort = 9080
    testServerHttpsPort = 9443
    warContext = appName
}

liberty {
    server {
        name = "${appName}Server"
        configFile = file("src/main/liberty/config/server.xml")
        bootstrapProperties = ['default.http.port': testServerHttpPort,
                               'default.https.port': testServerHttpsPort,
                               'app.context.root': warContext]
        packageLiberty {
            archive = "$buildDir/${appName}.zip"
            include = "usr"
        }
    }
}

war {
    archiveName = "${baseName}.${extension}"
}
  1. 在项目根目录下,打成war包,
gradle clean build 
image.png
  1. 新建文件夹/mydocker ,并把项目war包拷贝到/mydocker中,以及contrast-agent-3.6.3.8220.jar拷贝其中,再新建Dockerfile文件,


    image.png

    编辑Dockerfile文件如下,

FROM websphere-liberty:kernel

COPY contrast-agent-3.6.3.8220.jar /home/
# Add my app and config
COPY --chown=1001:0  GradleSample.war /config/dropins/  
#COPY --chown=1001:0  src/main/liberty/config/server.xml /config/


ENV CONTRAST__API__URL https://ce.contrastsecurity.com/Contrast/
ENV CONTRAST__API__API_KEY Y6Xv6205Gr1h7u5EWteLOAyiRluTWIAf
ENV CONTRAST__API__USER_NAME agent_9e9e9db1-c274-4f95-a82d-ef6a7b6c6599@MingsOrg
ENV CONTRAST__API__SERVICE_KEY YT1GRAXTCS7L2YWQ

#最简单的方法:可以通过设置下面这个变量来控制contrast是否需要启动
ENV JAVA_TOOL_OPTIONS -javaagent:/home/contrast-agent-3.6.3.8220.jar

# This script will add the requested XML snippets, grow image to be fit-for-purpose and apply interim fixes
RUN configure.sh
  1. 在/mydocker目录构建image,
docker build . 
  1. 查询刚刚构建的image,并启动,


    image.png
    image.png
  2. 从liberty启动日志可以看到 Contrast已启动成功!

相关文章

  • Contrast 部署到web-sphere Liberty

    思路:将Contrast配置到liberty上,希望当liberty运行的时候,开启Contrast;首先在项目的...

  • devstack 安装openstack newton版

    1.环境介绍 由于github的openstack liberty版本的代码已过期,无法使用devstack部署l...

  • 配置OpenStack各服务组件使用SSL通信

    OpenStack 版本:Liberty操作系统:CentOS7下面的配置针对的是allinone的部署方式,但是...

  • Freedom and Love

    Freedom and love Liberty and love -petogfi Liberty and lo...

  • 论自由

    on liberty

  • Contrast配置

    Contrast Security 配置过程 Contrast对application的漏洞检测和自动防御功能通过...

  • Liberty

    昨晚 做了一个梦 梦见自己住在一个不知名的地方 老楼房里 二楼的窗户上 玻璃明朗 些许马尾草沿边生长 坚韧地顽强 ...

  • liberty

    last year same time i got cold yet,when you to do anyth...

  • liberty

    今天下午极不情愿的帮sp改完高中政治试卷,不过只发了一小时,我想我心理建设和内心反抗时间可能都不止一小时。所以这件...

  • Contrast配置总结

    Contrast介绍 项目在docker容器中运行,Contrast配置步骤: 构建项目为war包 dockerf...

网友评论

      本文标题:Contrast 部署到web-sphere Liberty

      本文链接:https://www.haomeiwen.com/subject/ttzrectx.html