尝试基于 Alpine 构建 Jenkins Docker 图像时出现 AWT 错误 -
AWT error while trying to build Jenkins Docker image based on Alpine -
我正在尝试构建自己的 Jenkins Docker 映像。我将 Alpine-based Jdk Docker image. I adapted the Jenkins Docker image 用于 Alpine-Linux。
我必须安装一些软件包才能正确构建它,但是一旦我 运行 它,我就会遇到以下错误:
hudson.util.AWTProblem: java.lang.NullPointerException
at hudson.WebAppMain.contextInitialized(WebAppMain.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at winstone.Launcher.<init>(Launcher.java:156)
at winstone.Launcher.main(Launcher.java:356)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main._main(Main.java:293)
at Main.main(Main.java:98)
Caused by: java.lang.NullPointerException
at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
at sun.font.SunFontManager.run(SunFontManager.java:431)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:376)
at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.font.FontManagerFactory.run(FontManagerFactory.java:83)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.getFamily(Font.java:1220)
at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
at java.awt.Font.getFamily(Font.java:1186)
at java.awt.Font.toString(Font.java:1683)
at hudson.util.ChartUtil.<clinit>(ChartUtil.java:255)
at hudson.WebAppMain.contextInitialized(WebAppMain.java:184)
... 19 more
我跟随我的朋友 Google 尝试了不同的解决方案,要么安装 fontconfig 包,要么添加 Java 参数
JAVA_OPTS="-Djava.awt.headless=true"
或事件将 JDK 版本更改为 7,但似乎没有任何效果。
这是我的 dockerfile
FROM java:8-jdk-alpine
RUN apk update && apk add wget git curl zip bash fontconfig && rm -rf /var/lib/apt/lists/*
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
# Jenkins is run with user `jenkins`, uid = 1000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN adduser -S -h "$JENKINS_HOME" -u 1000 -s /bin/bash jenkins
# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
VOLUME /var/jenkins_home
# `/usr/share/jenkins/ref/` contains all reference configuration we want
# to set on a fresh new installation. Use it to bundle additional plugins
# or config file with your custom jenkins Docker image.
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
ENV TINI_SHA 066ad710107dc7ee05d3aa6e4974f01dc98f3888
# Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fL https://github.com/krallin/tini/releases/download/v0.5.0/tini-static -o /bin/tini \
&& chmod +x /bin/tini \
&& echo "$TINI_SHA /bin/tini" | sha1sum -c -
COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy
ENV JENKINS_VERSION 1.642.2
ENV JENKINS_SHA e72e06e64d23eefb13090459f517b0697aad7be0
# could use ADD but this one does not check Last-Modified header
# see https://github.com/docker/docker/issues/8331
RUN curl -fL http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -o /usr/share/jenkins/jenkins.war \
&& echo "$JENKINS_SHA /usr/share/jenkins/jenkins.war" | sha1sum -c -
ENV JENKINS_UC https://updates.jenkins-ci.org
RUN chown -R jenkins "$JENKINS_HOME" /usr/share/jenkins/ref
# for main web interface:
EXPOSE 8080
# will be used by attached slave agents:
EXPOSE 50000
ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log
USER jenkins
COPY jenkins.sh /usr/local/bin/jenkins.sh
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
COPY plugins.sh /usr/local/bin/plugins.sh
希望你们中的某个人能提供帮助,否则我将使用更重的官方 Jenkins 图像。
提前致谢。
也许您正在尝试完成与我相同的事情:https://hub.docker.com/r/serverking/jenkinsdsl/
我还尝试添加不同的依赖项来解决问题,在我的 docker 文件下面:
FROM alpine:latest
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk/jre
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
ENV JENKINS_VERSION 2.19.4
# Add scripts and plugin list
ADD src /
# Packages
RUN set -x && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community && \
apk update && \
apk upgrade && \
apk add --no-cache ca-certificates supervisor openjdk8 bash git curl zip wget docker ttf-dejavu jq coreutils openssh py2-pip && \
echo "*** fix key permissions ***" && \
chmod 600 /root/.ssh/id_rsa && \
echo "*** Installing docker-compose ***" && \
pip install --upgrade pip && \
pip install docker-compose
# Install Jenkins and plugins from plugins.txt
RUN set -x && \
echo "*** Installing jenkins ***" && \
curl -sSL --create-dirs --retry 1 http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -o /usr/share/jenkins/jenkins.war && \
echo "*** Recursive solve and reduce plugin dependencies ***" && \
bash -c 'curl -sSO https://updates.jenkins-ci.org/current/update-center.actual.json && \
function solve { \
for dependency in $(cat update-center.actual.json | jq --arg p "${1%:*}" -r '"'"'.plugins[] | select(.name == $p) | .dependencies[] | select(.optional == false) | .name + ":" + .version'"'"');do \
echo $dependency >> /var/jenkins_home/plugins.txt; \
solve $dependency; \
done \
} && \
for plugin in $(tr '"'"'\n'"'"' '"'"' '"'"' < /var/jenkins_home/plugins.txt);do solve $plugin; done && \
sort -Vr /var/jenkins_home/plugins.txt | sort -u -t: -k1,1 -o /var/jenkins_home/plugins.txt' && \
echo "*** Jenkins install plugins from plugins.txt *** " && \
while read plugin; do \
echo "*** Downloading ${plugin} ***" && \
curl -sSL --create-dirs --retry 3 https://updates.jenkins-ci.org/download/plugins/${plugin%:*}/${plugin#*:}/${plugin%:*}.hpi -o /var/jenkins_home/plugins/${plugin%:*}.jpi && \
touch /var/jenkins_home/plugins/${plugin%:*}.jpi.pinned; \
done < /var/jenkins_home/plugins.txt
EXPOSE 8080 8443 50000
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
为什么我自己做而不是使用官方的 JenkinsCI Dockerfile?
插件也必须是不可变的,否则构建不
确定性的。
官方没有涉及XML和不变性。没有人
其实想编辑XLM文件。
存储无法应对 docker 不可变概念,因此执行器
刹车.
构建必须是一次性的,如果存在它们必须重新附加到
仍有工作。
这下就全部解决了。
我正在尝试构建自己的 Jenkins Docker 映像。我将 Alpine-based Jdk Docker image. I adapted the Jenkins Docker image 用于 Alpine-Linux。 我必须安装一些软件包才能正确构建它,但是一旦我 运行 它,我就会遇到以下错误:
hudson.util.AWTProblem: java.lang.NullPointerException
at hudson.WebAppMain.contextInitialized(WebAppMain.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at winstone.Launcher.<init>(Launcher.java:156)
at winstone.Launcher.main(Launcher.java:356)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Main._main(Main.java:293)
at Main.main(Main.java:98)
Caused by: java.lang.NullPointerException
at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
at sun.font.SunFontManager.run(SunFontManager.java:431)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:376)
at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.font.FontManagerFactory.run(FontManagerFactory.java:83)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.getFamily(Font.java:1220)
at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
at java.awt.Font.getFamily(Font.java:1186)
at java.awt.Font.toString(Font.java:1683)
at hudson.util.ChartUtil.<clinit>(ChartUtil.java:255)
at hudson.WebAppMain.contextInitialized(WebAppMain.java:184)
... 19 more
我跟随我的朋友 Google 尝试了不同的解决方案,要么安装 fontconfig 包,要么添加 Java 参数
JAVA_OPTS="-Djava.awt.headless=true"
或事件将 JDK 版本更改为 7,但似乎没有任何效果。 这是我的 dockerfile
FROM java:8-jdk-alpine
RUN apk update && apk add wget git curl zip bash fontconfig && rm -rf /var/lib/apt/lists/*
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
# Jenkins is run with user `jenkins`, uid = 1000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN adduser -S -h "$JENKINS_HOME" -u 1000 -s /bin/bash jenkins
# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
VOLUME /var/jenkins_home
# `/usr/share/jenkins/ref/` contains all reference configuration we want
# to set on a fresh new installation. Use it to bundle additional plugins
# or config file with your custom jenkins Docker image.
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
ENV TINI_SHA 066ad710107dc7ee05d3aa6e4974f01dc98f3888
# Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fL https://github.com/krallin/tini/releases/download/v0.5.0/tini-static -o /bin/tini \
&& chmod +x /bin/tini \
&& echo "$TINI_SHA /bin/tini" | sha1sum -c -
COPY init.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-agent-port.groovy
ENV JENKINS_VERSION 1.642.2
ENV JENKINS_SHA e72e06e64d23eefb13090459f517b0697aad7be0
# could use ADD but this one does not check Last-Modified header
# see https://github.com/docker/docker/issues/8331
RUN curl -fL http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -o /usr/share/jenkins/jenkins.war \
&& echo "$JENKINS_SHA /usr/share/jenkins/jenkins.war" | sha1sum -c -
ENV JENKINS_UC https://updates.jenkins-ci.org
RUN chown -R jenkins "$JENKINS_HOME" /usr/share/jenkins/ref
# for main web interface:
EXPOSE 8080
# will be used by attached slave agents:
EXPOSE 50000
ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log
USER jenkins
COPY jenkins.sh /usr/local/bin/jenkins.sh
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup /usr/share/jenkins/ref/plugins from a support bundle
COPY plugins.sh /usr/local/bin/plugins.sh
希望你们中的某个人能提供帮助,否则我将使用更重的官方 Jenkins 图像。 提前致谢。
也许您正在尝试完成与我相同的事情:https://hub.docker.com/r/serverking/jenkinsdsl/
我还尝试添加不同的依赖项来解决问题,在我的 docker 文件下面:
FROM alpine:latest
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk/jre
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000
ENV JENKINS_VERSION 2.19.4
# Add scripts and plugin list
ADD src /
# Packages
RUN set -x && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main && \
apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community && \
apk update && \
apk upgrade && \
apk add --no-cache ca-certificates supervisor openjdk8 bash git curl zip wget docker ttf-dejavu jq coreutils openssh py2-pip && \
echo "*** fix key permissions ***" && \
chmod 600 /root/.ssh/id_rsa && \
echo "*** Installing docker-compose ***" && \
pip install --upgrade pip && \
pip install docker-compose
# Install Jenkins and plugins from plugins.txt
RUN set -x && \
echo "*** Installing jenkins ***" && \
curl -sSL --create-dirs --retry 1 http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -o /usr/share/jenkins/jenkins.war && \
echo "*** Recursive solve and reduce plugin dependencies ***" && \
bash -c 'curl -sSO https://updates.jenkins-ci.org/current/update-center.actual.json && \
function solve { \
for dependency in $(cat update-center.actual.json | jq --arg p "${1%:*}" -r '"'"'.plugins[] | select(.name == $p) | .dependencies[] | select(.optional == false) | .name + ":" + .version'"'"');do \
echo $dependency >> /var/jenkins_home/plugins.txt; \
solve $dependency; \
done \
} && \
for plugin in $(tr '"'"'\n'"'"' '"'"' '"'"' < /var/jenkins_home/plugins.txt);do solve $plugin; done && \
sort -Vr /var/jenkins_home/plugins.txt | sort -u -t: -k1,1 -o /var/jenkins_home/plugins.txt' && \
echo "*** Jenkins install plugins from plugins.txt *** " && \
while read plugin; do \
echo "*** Downloading ${plugin} ***" && \
curl -sSL --create-dirs --retry 3 https://updates.jenkins-ci.org/download/plugins/${plugin%:*}/${plugin#*:}/${plugin%:*}.hpi -o /var/jenkins_home/plugins/${plugin%:*}.jpi && \
touch /var/jenkins_home/plugins/${plugin%:*}.jpi.pinned; \
done < /var/jenkins_home/plugins.txt
EXPOSE 8080 8443 50000
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
为什么我自己做而不是使用官方的 JenkinsCI Dockerfile?
插件也必须是不可变的,否则构建不 确定性的。
官方没有涉及XML和不变性。没有人 其实想编辑XLM文件。
存储无法应对 docker 不可变概念,因此执行器 刹车.
构建必须是一次性的,如果存在它们必须重新附加到 仍有工作。
这下就全部解决了。