我有一个Spring Boot应用程序,它使用gradle作为依赖项管理器。我已经使用Export As war文件创建了war文件。并在亚马逊网络服务ElasticBeanstalk中部署了相同的应用程序。我使用的平台是Tomcat 8.5 with Java 8 running on 64bit Amazon Linux/3.4.5
现在,我想使用AWS的CI/CD,并想创建一个代码管道来将war文件部署到EBS。
在创建代码管道时,它要求我构建代码构建项目。
下面是我的build命令:
version: 0.2
#env:
#variables:
# key: "value"
# key: "value"
#parameter-store:
# key: "value"
# key: "value"
#secrets-manager:
# key: secret-id:json-key:version-stage:version-id
# key: secret-id:json-key:version-stage:version-id
#exported-variables:
# - variable
# - variable
#git-credential-helper: yes
#batch:
#fast-fail: true
#build-list:
#build-matrix:
#build-graph:
phases:
#install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
#runtime-versions:
# name: version
# name: version
#commands:
# - command
# - command
#pre_build:
#commands:
# - command
# - command
build:
commands:
- gradle build
# - command
#post_build:
#commands:
# - command
# - command
#reports:
#report-name-or-arn:
#files:
# - location
# - location
#base-directory: location
#discard-paths: yes
#file-format: JunitXml | CucumberJson
#artifacts:
#files:
# - location
# - location
#name: $(date +%Y-%m-%d)
#discard-paths: yes
#base-directory: location
#cache:
#paths:
# - paths我在这里做了哪些更改,以便创建war文件并将其部署到EBS。因为我对构建过程和CI/CD非常陌生,所以我有点困惑。
我的build.gradle文件是:
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'war'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
//compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.4.15.Final'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.2.7.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.20'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.3.0.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.0.RELEASE'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.784'
providedCompile group: 'org.projectlombok', name: 'lombok', version: '0.11.0'
// https://mvnrepository.com/artifact/org.projectlombok/lombok
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.18'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '4.1.2'
compile group: 'org.apache.poi', name: 'poi', version: '4.1.2'
compile group: 'org.codehaus.mojo', name: 'exec-maven-plugin', version: '3.0.0'
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'com.google.zxing', name: 'core', version: '3.4.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'com.google.common', name: 'google-collect', version: '0.5'
developmentOnly("org.springframework.boot:spring-boot-devtools")
//testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}发布于 2021-08-25 18:29:32
几天前我遇到了同样的问题,我几乎没有为gradle找到任何好的资源。通过上传gradle构建过程中生成的WAR文件,您可以轻松地将应用程序直接部署到Elastic Beanstalk。
当您将WAR文件上传到Beanstalk时,它会被提取/分解,Beanstalk会在内部为您执行此操作。但是当你使用流水线时,你需要直接上传分解的文件,而不是WAR。看起来AWS Codepipeline仍然不是战争友好的。
首先,要生成分解的WAR文件,您需要将以下内容添加到build.gradle中:
task explodedWar(type: Sync) {
into "${buildDir}/exploded"
with war }要生成分解文件夹,您需要使用以下命令通过终端运行以下任务:
./gradlew explodedWar您将在build文件夹中找到一个名为exploded的文件夹,您将能够在其中看到分解的WAR的内容。
下面是下面的builspec.yml文件,您可以使用它来构建代码并使用管道进行部署。我使用的环境是Tomcat 8.5 with Corretto 8 running on 64bit Amazon Linux 2
version: 0.1
phases:
install:
run-as: root
commands:
- echo Installing gradle
- wget https://services.gradle.org/distributions/gradle-7.1.1-bin.zip
- unzip -d /opt/gradle gradle-7.1.1-bin.zip
pre_build:
commands:
- echo Entering pre build
build:
commands:
- /opt/gradle/gradle-7.1.1/bin/gradle clean
- /opt/gradle/gradle-7.1.1/bin/gradle explodedWar
post_build:
commands:
- echo Entering post build
artifacts:
files:
- '**/*'
base-directory: build/exploded/
discard-paths: no您可以查看AWS buildspec.yml documentation,了解更多语法和特性,具体取决于您的用例。
https://stackoverflow.com/questions/67335589
复制相似问题