我对Docker比较陌生,我有一个来自https://hub.docker.com/layers/jenkins/jnlp-slave/4.7-1-jdk11/images/sha256-b93b836b2d4f59f027106e3991ed1e777dc092d8feec2c56f29214201d6c2322?context=explore的基础映像
最重要的是,我试图添加一些实用程序,其中包括awscli,我已经尝试了许多方法,从使用USER jenkins
指令到chown
都没有效果,aws cli总是安装到/usr/local/bin
根目录下,当Jenkins用户试图访问它时,它找不到/权限拒绝。我也试过用-i
和-b
指令安装,但没有效果!
下面是我的docker文件:
ADD file:575bf0d00d72810609a4118728923f11625b43de536352fe69a341086e4ebfd1 in /
ENV TZ=Asia/Singapore
COPY * /home/jenkins/.ssh/
USER root
RUN pwd
RUN apt-get update && apt-get install -y ca-certificates apt-transport-https wget curl
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update && apt-get install google-cloud-sdk kubectl -y
RUN apt install vim -y
COPY /helm /usr/local/bin/helm
RUN helm init --client-only --skip-refresh
RUN helm repo rm stable
RUN helm repo add stable https://charts.helm.sh/stable
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update && apt install rsync -y --no-install-recommends && chown jenkins:jenkins /home/jenkins/.ssh/ -R && chmod 700 /home/jenkins/.ssh -R && chmod 400 /home/jenkins/.ssh/id_rsa*
RUN mkdir -p /home/jenkins/.kube/ && chown jenkins:jenkins /home/jenkins/.kube/ -R
RUN apt-get install -y jq
### Lines in this block are for Dev K8s Jenkins image. Optional and can be commented out for other environments ###
RUN apt install -y python3-pip && pip3 install Jinja2 && pip3 install jinja2-cli
RUN pip3 install yq
RUN wget https://github.com/roboll/helmfile/releases/download/v0.119.1/helmfile_linux_amd64 && chmod +x helmfile_linux_amd64 && mv helmfile_linux_amd64 /usr/local/bin/helmfile
### End of block ###
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get install -y nodejs
RUN node -v
RUN npm -v
RUN npm install -g newman && npm install -g newman-reporter-htmlextra && npm install -g newman-reporter-junitfull
RUN mkdir -p /home/jenkins/aws-cli && chown jenkins:jenkins /home/jenkins/aws-cli -R && cd /home/jenkins/ && curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install -i /home/jenkins/aws-cli -b /home/jenkins/aws-cli/bin && export PATH="/home/jenkins/aws-cli/bin:$PATH" && chown jenkins:jenkins /home/jenkins/aws-cli -R
USER jenkins
ENTRYPOINT ["jenkins-agent"]
我只是希望jenkins用户能够运行awscli命令。
1条答案
按热度按时间8ftvxx2r1#
您需要确保安装了AWS CLI,并且Docker映像中的Jenkins用户可以访问该CLI。试试这个: