自建nexus私服

目的

  • 加速maven构建:如果项目配置了很多外部远程仓库(非私服)的时候,构建速度就会大大降低,因为所有的jar包都需要从这些远程仓库再下载;当然就可以节省自己的外网带宽,减少重复请求造成的外网带宽消耗;
  • 推送自己工程的产物;

k8s自建nexus服务器

参考 segmentfault.com/a/119000004…

nexus自建仓库

image.png

proxy:代理的远程仓库,如:阿里云等; hosted:是指本地或者内部项目仓库;

我建立两个hosted用来放置自己的产物; image.png

maven-central代理阿里中心仓maven.aliyun.com/nexus/conte…

![image.png](p1-juejin.byteimg.com/tos-cn-i- k3u1fbpfcp/3c2d149ef8c54dcaacf2d907551cbbd9~tplv-k3u1fbpfcp-watermark.image?)

setting.xml配置和工程pom.xml配置

参考: juejin.cn/post/701396…

然后我把原来本地仓的所有包全删了,点了下IDEA-maven-deploy,然后 maven-central就有了从阿里中心仓同步的jar包,hosted里也有了自己工程的产物。

argo-workflow使用maven镜像构建工程,配置中心仓为私服

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: buildkit-
  namespace: argo
spec:
  ttlStrategy:
    secondsAfterCompletion: 1800 # Time to live after workflow is completed, replaces ttlSecondsAfterFinished
    secondsAfterSuccess: 1800     # Time to live after workflow is successful
    secondsAfterFailure: 1800     # Time to live after workflow fails
  arguments:
    parameters:
      - name: repo
        value: https://username:[email protected]/..............
      - name: branch
        value: master
      - name: path
        value: .
      - name: image
        value: yyy:test111
      - name: dockerfile
        value: Dockerfile
  dnsPolicy: ClusterFirst
  hostAliases:
  - ip: "10.112.21.246"
    hostnames:
    - "git.xxx.com"
  entrypoint: main
  volumeClaimTemplates:
    - metadata:
        name: work
        annotations:
          volume.beta.kubernetes.io/storage-class: "tmp-nfs-client-storageclass"
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 64Mi
  templates:
    - name: main
      dag:
        tasks:
          - name: clone
            template: clone
            arguments:
              parameters:
                - name: repo
                  value: "{{workflow.parameters.repo}}"
                - name: branch
                  value: "{{workflow.parameters.branch}}"
          - name: build
            template: build
            arguments:
              parameters:
                - name: path
                  value: "{{workflow.parameters.path}}"
            depends: "clone"
    - name: clone
      inputs:
        parameters:
          - name: repo
          - name: branch
      container:
        volumeMounts:
          - mountPath: /work
            name: work
        image: alpine/git:v2.26.2
        workingDir: /work
        # Do a shallow clone, which is the fastest way to clone, by using the
        # --depth, --branch, and --single-branch options
        args:
          - clone
          - --depth
          - "1"
          - --branch
          - "{{inputs.parameters.branch}}"
          - --single-branch
          - "{{inputs.parameters.repo}}"
          - .
    - name: build
      inputs:
        parameters:
          - name: path
      container:
        image: maven:3-alpine
        volumeMounts:
          - mountPath: /work
            name: work
        workingDir: /work
        command:
          - mvn
        args:
          - --settings=settings.xml
          - -B
          - -DskipTests
          - clean 
          - package
复制代码

settings.xml是IDEA的maven配置文件,其中设置下mirror为我们的nexus地址

 <mirror>
     <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <name>Nexus</name>
  <url>http://xxx:8081/repository/maven-central/</url>
</mirror>
复制代码

参考文档:

Packaging a local repository with the image hub.docker.com/_/maven#:~:…

猜你喜欢

转载自juejin.im/post/7040719780399022093
今日推荐