我使用Jenkins与Kubernetes插件,我想将JNLP镜像与我的从属镜像组合使用。

huangapple go评论94阅读模式
英文:

I'm using Jenkins with Kubernetes plugin and I want to combine JNLP image with my slave image

问题

我希望我的默认 JNLP 容器能够运行我的镜像。
因此,我需要用我的镜像来覆盖 JNLP,但保留 JNLP 数据以便连接到我的主节点。

  1. 我应该将 JNLP 镜像作为基础使用,是吗?
  2. 如果我已经有 "FROM UBUNTU",我该如何将其与我的镜像组合,能够同时使用多个基础镜像并复制构建产物吗?我应该如何编写 Dockerfile?

我的自定义镜像 -

  1. FROM ubuntu:18.04
  2. ARG JFROG_CI_INT_USERNAME
  3. ARG JFROG_CI_INT_PASSWORD
  4. ARG JFROG_CI_INT_NPM_TOKEN
  5. ARG GITHUB_ORANGE_USER
  6. ARG GITHUB_ORANGE_PASSWORD
  7. ARG PULUMI_USER
  8. ARG PULUMI_TOKEN
  9. ENV GITHUB_ORANGE_USER=$GITHUB_ORANGE_USER
  10. ENV GITHUB_ORANGE_PASSWORD=$GITHUB_ORANGE_PASSWORD
  11. ENV DEBIAN_FRONTEND=noninteractive
  12. #=============
  13. # 设置工作目录
  14. #=============
  15. WORKDIR /home/jenkins
  16. COPY requirements.txt /
  17. COPY authorization.sh /
  18. # 更新软件仓库
  19. RUN apt-get update
  20. RUN apt-get -qqy install software-properties-common
  21. RUN add-apt-repository ppa:git-core/ppa
  22. RUN add-apt-repository ppa:openjdk-r/ppa
  23. RUN add-apt-repository ppa:deadsnakes/ppa
  24. RUN apt-get -qqy install git
  25. ENV PYTHON_VER="3.9"
  26. RUN apt-get -qqy update && \
  27. apt-get -qqy --no-install-recommends install \
  28. gpg-agent \
  29. software-properties-common \
  30. openjdk-11-jdk \
  31. ca-certificates \
  32. build-essential \
  33. tzdata \
  34. zip \
  35. unzip
  36. ENTRYPOINT ["/usr/local/bin/start.sh"]

注意:Dockerfile 中的中文注释已经保留。

英文:

I want my default JNLP container to run with my image.
Therefore, I need to overrite the JNLP with my image, but to keep the JNLP data to be able to connect to my master.

  1. The jnlp image I should have as base is inbound-agent no?
  2. How can I combine it with my image if I already have "FROM UBUNTU" can I combine multiple base images and copy the artifacts? How can I do that and what should be my dockerfile?

My own image -

  1. FROM ubuntu:18.04
  2. ARG JFROG_CI_INT_USERNAME
  3. ARG JFROG_CI_INT_PASSWORD
  4. ARG JFROG_CI_INT_NPM_TOKEN
  5. ARG GITHUB_ORANGE_USER
  6. ARG GITHUB_ORANGE_PASSWORD
  7. ARG PULUMI_USER
  8. ARG PULUMI_TOKEN
  9. ENV GITHUB_ORANGE_USER=$GITHUB_ORANGE_USER
  10. ENV GITHUB_ORANGE_PASSWORD=$GITHUB_ORANGE_PASSWORD
  11. ENV DEBIAN_FRONTEND=noninteractive
  12. #=============
  13. # Set WORKDIR
  14. #=============
  15. WORKDIR /home/jenkins
  16. COPY requirements.txt /
  17. COPY authorization.sh /
  18. # Update software repository
  19. RUN apt-get update
  20. RUN apt-get -qqy install software-properties-common
  21. RUN add-apt-repository ppa:git-core/ppa
  22. RUN add-apt-repository ppa:openjdk-r/ppa
  23. RUN add-apt-repository ppa:deadsnakes/ppa
  24. RUN apt-get -qqy install git
  25. ENV PYTHON_VER="3.9"
  26. RUN apt-get -qqy update && \
  27. apt-get -qqy --no-install-recommends install \
  28. gpg-agent \
  29. software-properties-common \
  30. openjdk-11-jdk \
  31. ca-certificates \
  32. build-essential \
  33. tzdata \
  34. zip \
  35. unzip \
  36. ENTRYPOINT ["/usr/local/bin/start.sh"]

答案1

得分: 1

您可以使用多阶段构建,但最终会得到一个紧密耦合的镜像,每次想要更改 Jenkins 代理版本时都需要重新构建它。

有一个更好(在我看来)的选项,使用两个容器。您可以在 Kubernetes 中运行代理,使用两个镜像:inbound-agent 和您的镜像。这是我有的一个工作流示例:

  1. pipeline {
  2. agent {
  3. kubernetes {
  4. yaml """
  5. apiVersion: v1
  6. kind: Pod
  7. spec:
  8. containers:
  9. - name: jnlp
  10. image: jenkins/inbound-agent:4.10-3-alpine-jdk8
  11. volumeMounts:
  12. - name: home-volume
  13. mountPath: /home/jenkins
  14. env:
  15. - name: HOME
  16. value: /home/jenkins
  17. - name: maven
  18. image: my-registry:5000/maven-3.6.3-jdk-11:latest
  19. command:
  20. - sleep
  21. args:
  22. - 1d
  23. volumeMounts:
  24. - name: home-volume
  25. mountPath: /home/jenkins
  26. env:
  27. - name: JAVA_TOOL_OPTIONS
  28. value: -Dfile.encoding=UTF8
  29. volumes:
  30. - name: home-volume
  31. emptyDir: {}
  32. """
  33. }
  34. }
  35. stages {
  36. stage('Build') {
  37. steps {
  38. script {
  39. container('maven') {
  40. sh('mvn clean deploy')

这样,您可以使这两个镜像解耦,但它们在同一个 Pod 中运行以使工作流正常工作。

英文:

You can do a multi-stage build but you'll end with a tightly coupled image, and you'll have to rebuild it every time you want to change the jenkins agent version.

There's a better (IMHO) option, using two containers. You can run an agent in kubernetes using two images: inbound-agent and your image. This is from a working pipeline that I have:

  1. pipeline {
  2. agent {
  3. kubernetes {
  4. yaml """
  5. apiVersion: v1
  6. kind: Pod
  7. spec:
  8. containers:
  9. - name: jnlp
  10. image: jenkins/inbound-agent:4.10-3-alpine-jdk8
  11. volumeMounts:
  12. - name: home-volume
  13. mountPath: /home/jenkins
  14. env:
  15. - name: HOME
  16. value: /home/jenkins
  17. - name: maven
  18. image: my-registry:5000/maven-3.6.3-jdk-11:latest
  19. command:
  20. - sleep
  21. args:
  22. - 1d
  23. volumeMounts:
  24. - name: home-volume
  25. mountPath: /home/jenkins
  26. env:
  27. - name: JAVA_TOOL_OPTIONS
  28. value: -Dfile.encoding=UTF8
  29. volumes:
  30. - name: home-volume
  31. emptyDir: {}
  32. """
  33. }
  34. }
  35. stages {
  36. stage('Build') {
  37. steps {
  38. script {
  39. container('maven') {
  40. sh('mvn clean deploy')

This way you have both images decoupled, but they run together in the same pod to make the pipeline work.

huangapple
  • 本文由 发表于 2023年2月26日 20:48:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572075.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定