微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有插件 frontend-maven-plugin 的缓存节点模块库

如何解决带有插件 frontend-maven-plugin 的缓存节点模块库

我有一个在 Gitlab CICD Pipeline(使用 docker)上配置的 React 项目。 在我的管道中,我有一个步骤来创建使用 frontend-maven-plugin 插件 (Packaging) 的包

每次我运行管道时,都会下载所有工件。我想在管道中使用缓存,但下面的配置不起作用。我认为前端 Maven 插件使用不同的缓存位置。

我该如何配置?

管道 Gitlab :

stages:
  - build
  - analyse
  - package
  - deploiement

cache:
  paths:
    - project_front/projectdir/node_modules/

variables:
  MAVEN_CLI_OPTS: "-s ${MAVEN_PROJECT_SETTINGS} --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=${MAVEN_PROJECT_REPO}"

#
# Build de l'application
Build:
  image: maven:3.5.2-jdk-8
  stage: build
  tags: [ 'project' ]
  script:
    # Récupération de la version du projet maven
    - mvn $MAVEN_CLI_OPTS -U  clean install -D maven.test.skip=true

#
# Step d'analyse SONAR
Qualimétrie:
  image: maven:3.5.2-jdk-8
  stage: analyse
  tags: [ 'project' ]
  script:
    - mvn  $MAVEN_CLI_OPTS -P sonarqubeproject,jacoco,nexus -U -D sonar.qualitygate.wait=true -D sonar.branch.name=$CI_COMMIT_BRANCH verify sonar:sonar
  artifacts:
    when: always
    reports:
      junit:
        - "*/target/surefire-reports/TEST-*.xml"

#
# Génération du package de livraison
Packaging:
  image: maven:3.5.2-jdk-8
  stage: package
  tags: [ 'project' ]
  script:
    # Packaging
    - mvn $MAVEN_CLI_OPTS -P package_livraison -U  package -Dmaven.test.skip=true  -D HTTP_PROXY=${PROXY_SRV} -D HTTPS_PROXY=${PROXY_SRV}
  artifacts:
    paths:
      - '**/target/*.tar.gz'

#
# Step de déploiement Ansible
Deploiement INT:
  stage: deploiement
  tags: [ 'project' ]
  image: ansible/centos7-ansible
  only:
    - master
    - develop
    - feature-gitlab-cicd
  when: manual
  dependencies:
    - Packaging
  script:
    #Installation de XMLLINT pour récupérer la version dans le POM
    - yum -y install libxml2
    # Récupération de la version du projet maven
    - VERSION_PROJECT=`xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml`
    # Execution du ssh-agent
    - eval $(ssh-agent -s)
    # Récupération de la clé privée de l'hote et envoi dans le container
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    # Création des répertoires
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    # Recherche de l'hote
    - ssh-keyscan myhost >> ~/.ssh/kNown_hosts
    - chmod 644 ~/.ssh/kNown_hosts
    # Envoi du package à la machine PROJECT
    - cp project_deploiement/target/*.tar.gz /home/gitlab-runner/depot/
    #Lancement du playbook
    - ansible-playbook -v -i project_ansible/project-hosts project_ansible/ansible/project-install-playbook-int.yml -f 10 --extra-vars "project_version=${VERSION_PROJECT} -vvvv"

简介:

 <profile>
            <id>package_livraison</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>${frontend-maven-plugin.version}</version>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <yarnVersion>${yarn.version}</yarnVersion>
                            <workingDirectory>${frontend-src-dir}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>install-frontend-tools</id>
                                <goals>
                                    <goal>install-node-and-yarn</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>yarn-install</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <!-- Le proxy maven n'est pas utilisé,on le redéfinit-->
                                    <yarnInheritsProxyConfigFromMaven>true</yarnInheritsProxyConfigFromMaven>
                                    <arguments>install</arguments>

                                </configuration>
                            </execution>
                            <execution>
                                <id>build-frontend</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <arguments>build</arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

属性

<properties>
    <frontend-src-dir>./projectdir</frontend-src-dir>
    <node.version>v10.15.3</node.version>
    <yarn.version>v1.15.2</yarn.version>
    <frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>
</properties>

目录结构

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。