将战争档案从Gitlab CI复制到Tomcat

发布于 2025-02-11 08:50:21 字数 1529 浏览 0 评论 0原文

我正在尝试创建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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

非要怀念 2025-02-18 08:50:21

您可以提供project-build作业中构建的战争文件作为伪像,因此可以在以下工作中获得。顺便说一句,您可能不应在作业名称中使用空格。

这可能看起来如下:

project-build:  
  image: ${IMAGE_PATH}/maven
  services:
    - tomcat:latest
  stage: build
  artifacts:
    paths:
      - /path/to/your/war
  script:
    - ${MAVEN_PATH}/mvn ${MAVEN_CLI_OPTS} clean package
    - ls -als
    - ls -als target

在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:

project-build:  
  image: ${IMAGE_PATH}/maven
  services:
    - tomcat:latest
  stage: build
  artifacts:
    paths:
      - /path/to/your/war
  script:
    - ${MAVEN_PATH}/mvn ${MAVEN_CLI_OPTS} clean package
    - ls -als
    - ls -als target

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 ADDed to your image.

Hope this helps :)

Best regards
Andreas

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文