将战争档案从Gitlab CI复制到Tomcat
我正在尝试创建CI/CD管道来构建战争文件并将其部署到Gitlab的Tomcat容器。
我正在使用Maven图像来构建项目。创建战争文件后,我想将其复制到某个文件夹中,以便可以将其复制到tomcat服务器,在容器中,WebApps目录中。
我目前的方法和目标是在项目中使用Dockerfile。从Tomcat图像中,使用项目战争运行Tomcat。我尝试使用添加dockerfile,但是战争所在的目录路径$ ci_project_dir并不是Dockerfile所在的地方。
以下是“ .gitlab-ci.yml”文件。
stages:
# Build project
- build
- package
# Build and deploy mailService
#- deploy
variables:
# Variables that can be used throughout the pipeline are defined here.
# Maven variables
MAVEN_CLI_OPTS: '-s /appdir/.m2/settings.xml'
MAVEN_PATH: '/appdir/opt/apache-maven-3.8.4/bin'
IMAGE_PATH: 'gitlab-registry.gs.mil/gteam-development/docker'
project-build:
image: ${IMAGE_PATH}/maven
services:
- tomcat:latest
stage: build
script:
- ${MAVEN_PATH}/mvn ${MAVEN_CLI_OPTS} clean package
- ls -als
- ls -als target
build docker image:
stage: package
image: docker
services:
- docker:dind
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
tags:
- dind
以下是我使用图像来运行tomcat的“ dockerfile”。我需要将战争文件复制到Tomcat WebApps文件夹并构建另一个图像。
FROM tomcat:latest
LABEL maintainer=”Jacquelyne Wilson”
# ADD $CI_PROJECT/target/geoint-rfi-data-api.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD [“catalina.sh”, “run”]
注意:我在GitLab容器注册表中拥有的这些图像。希望这是足够的信息。 这是我第一次创建Gitlab CI管道的经历。如果我的条款和方法不理想,我的歉意。
I am trying to create a CI/CD pipeline to build war file and deploy it to Tomcat Container from GitLab.
I am using a Maven image to build the project. Once the war file is created, I would like to copy it to some folder so that from there it can be copied to the tomcat server, in a container, webapps directory.
My current approach and goal is to use a Dockerfile in my project. From a Tomcat image, run Tomcat using the project war. I tried using ADD in the Dockerfile but the directory paths where the war resides, $CI_PROJECT_DIR, is not where the Dockerfile is looking.
The following is the ".gitlab-ci.yml" file.
stages:
# Build project
- build
- package
# Build and deploy mailService
#- deploy
variables:
# Variables that can be used throughout the pipeline are defined here.
# Maven variables
MAVEN_CLI_OPTS: '-s /appdir/.m2/settings.xml'
MAVEN_PATH: '/appdir/opt/apache-maven-3.8.4/bin'
IMAGE_PATH: 'gitlab-registry.gs.mil/gteam-development/docker'
project-build:
image: ${IMAGE_PATH}/maven
services:
- tomcat:latest
stage: build
script:
- ${MAVEN_PATH}/mvn ${MAVEN_CLI_OPTS} clean package
- ls -als
- ls -als target
build docker image:
stage: package
image: docker
services:
- docker:dind
script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
- docker build -t $CI_REGISTRY_IMAGE .
- docker push $CI_REGISTRY_IMAGE
tags:
- dind
The following is the "Dockerfile" I am using to run Tomcat using the image. I need to copy my war file to the Tomcat webapps folder and build another image.
FROM tomcat:latest
LABEL maintainer=”Jacquelyne Wilson”
# ADD $CI_PROJECT/target/geoint-rfi-data-api.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD [“catalina.sh”, “run”]
NOTE: These images I have in our Gitlab Container Registry. Hope this is enough information.
This is my first experience creating Gitlab CI pipeline. My apologies if my terms and approach is not ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以提供
project-build
作业中构建的战争文件作为伪像,因此可以在以下工作中获得。顺便说一句,您可能不应在作业名称中使用空格。这可能看起来如下:
在Docker构建作业中,您可以将战争文件从工件复制到docker构建上下文路径,以便可以
添加
ed 到您的图像中。希望这有帮助:)
最好的问候
安德烈亚斯
You can provide the WAR file built in your
project-build
job as an artifact, so it is available in the following job. By the way, you should probably not use spaces in the job name.This could look like the following:
And in the docker build job, you can then copy the WAR file from the artifact to the docker build context path so it can be
ADD
ed to your image.Hope this helps :)
Best regards
Andreas