-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1075 from openshift-cherrypick-robot/cherry-pick-…
…1043-to-release-4.3 Bug 1848335: [release-4.3] Support Nodejs 12 Agent
- Loading branch information
Showing
8 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile.localdev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
FROM quay.io/openshift/origin-jenkins-agent-base:v4.0 | ||
|
||
MAINTAINER Akram Ben Aissi <abenaiss@redhat.com> | ||
|
||
ENV NODEJS_VERSION=12 \ | ||
NPM_CONFIG_PREFIX=$HOME/.npm-global \ | ||
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ | ||
BASH_ENV=/usr/local/bin/scl_enable \ | ||
ENV=/usr/local/bin/scl_enable \ | ||
PROMPT_COMMAND=". /usr/local/bin/scl_enable" \ | ||
LANG=en_US.UTF-8 \ | ||
LC_ALL=en_US.UTF-8 | ||
COPY contrib/bin/scl_enable /usr/local/bin/scl_enable | ||
COPY contrib/bin/configure-agent /usr/local/bin/configure-agent | ||
|
||
# Install NodeJS | ||
RUN curl https://raw.githubusercontent.com/cloudrouter/centos-repo/master/CentOS-Base.repo -o /etc/yum.repos.d/CentOS-Base.repo && \ | ||
curl http://mirror.centos.org/centos-7/7/os/x86_64/RPM-GPG-KEY-CentOS-7 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 && \ | ||
INSTALL_PKGS="make gcc-c++" && \ | ||
DISABLES="--disablerepo=rhel-server-extras --disablerepo=rhel-server --disablerepo=rhel-fast-datapath --disablerepo=rhel-server-optional --disablerepo=rhel-server-ose --disablerepo=rhel-server-rhscl" && \ | ||
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ | ||
yum $DISABLES install -y --setopt=tsflags=nodocs --disableplugin=subscription-manager $INSTALL_PKGS && \ | ||
rpm -V $INSTALL_PKGS && \ | ||
curl -sL https://rpm.nodesource.com/setup_12.x | bash - && \ | ||
yum $DISABLES install -y --setopt=tsflags=nodocs --disableplugin=subscription-manager nodejs && \ | ||
rpm -V nodejs && \ | ||
yum clean all -y | ||
|
||
RUN chown -R 1001:0 $HOME && \ | ||
chmod -R g+rw $HOME | ||
|
||
USER 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
FROM quay.io/openshift/origin-jenkins-agent-base:v4.0 | ||
|
||
MAINTAINER Akram Ben Aissi <abenaiss@redhat.com> | ||
|
||
# Labels consumed by Red Hat build service | ||
LABEL com.redhat.component="jenkins-agent-nodejs-12-rhel7-container" \ | ||
name="openshift4/jenkins-agent-nodejs-12-rhel7" \ | ||
version="4.4" \ | ||
architecture="x86_64" \ | ||
io.k8s.display-name="Jenkins Agent Nodejs" \ | ||
io.k8s.description="The jenkins agent nodejs image has the nodejs tools on top of the jenkins slave base image." \ | ||
io.openshift.tags="openshift,jenkins,agent,nodejs" | ||
|
||
ENV NODEJS_VERSION=12 \ | ||
NPM_CONFIG_PREFIX=$HOME/.npm-global \ | ||
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ | ||
BASH_ENV=/usr/local/bin/scl_enable \ | ||
ENV=/usr/local/bin/scl_enable \ | ||
PROMPT_COMMAND=". /usr/local/bin/scl_enable" \ | ||
LANG=en_US.UTF-8 \ | ||
LC_ALL=en_US.UTF-8 | ||
|
||
COPY contrib/bin/scl_enable /usr/local/bin/scl_enable | ||
COPY contrib/bin/configure-agent /usr/local/bin/configure-agent | ||
|
||
# Install NodeJS | ||
RUN INSTALL_PKGS="rh-nodejs${NODEJS_VERSION} rh-nodejs${NODEJS_VERSION}-nodejs-nodemon make gcc-c++" && \ | ||
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ | ||
yum install -y --setopt=tsflags=nodocs --disableplugin=subscription-manager $INSTALL_PKGS && \ | ||
rpm -V $INSTALL_PKGS && \ | ||
yum clean all -y | ||
|
||
RUN chown -R 1001:0 $HOME && \ | ||
chmod -R g+rw $HOME | ||
|
||
USER 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Node Slave Image | ||
==================== | ||
|
||
This repository contains Dockerfiles for a Jenkins Agent Docker image intended for | ||
use with [OpenShift v3](https://github.com/openshift/origin) | ||
|
||
Node Registry Support | ||
--------------------------------- | ||
This Node agent image supports using a [Node Mirror/Registry](https://blog.sonatype.com/using-nexus-3-as-your-repository-part-2-npm-packages) manager such as Sonatype Nexus 3 via setting the NPM_MIRROR_URL environment variable on the slave pod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This is for the purpose of building containers on the CentOS Community Container | ||
# Pipeline. The containers are built, tested and delivered to registry.centos.org and | ||
# lifecycled as well. A corresponding entry must exist in the container index itself, | ||
# located at https://github.com/CentOS/container-index/tree/master/index.d | ||
# You can know more at the following links: | ||
# * https://github.com/CentOS/container-pipeline-service/blob/master/README.md | ||
# * https://github.com/CentOS/container-index/blob/master/README.rst | ||
# * https://wiki.centos.org/ContainerPipeline | ||
|
||
# This will be part of the name of the container. It should match the job-id in index entry | ||
job-id: jenkins-agent-nodejs-12-centos7 | ||
|
||
#the following are optional, can be left blank | ||
#defaults, where applicable are filled in | ||
#nulecule-file : nulecule | ||
|
||
# This flag tells the container pipeline to skip user defined tests on their container | ||
test-skip : True | ||
|
||
# This is path of the script that initiates the user defined tests. It must be able to | ||
# return an exit code. | ||
test-script : null | ||
|
||
# This is the path of custom build script. | ||
build-script : null | ||
|
||
# This is the path of the custom delivery script | ||
delivery-script : null | ||
|
||
# This flag tells the pipeline to deliver this container to docker hub. | ||
docker-index : True | ||
|
||
# This flag can be used to enable or disable the custom delivery | ||
custom-delivery : False | ||
|
||
# This flag can be used to enable or disable delivery of container to local registry | ||
local-delivery : True | ||
|
||
Upstreams : | ||
- ref : | ||
url : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
# extract the different element of an url into a JSON structure | ||
parse_url() { | ||
# extract the protocol | ||
proto="$(echo $1 | cut -f1 -d: )" | ||
if [[ ! -z $proto ]] ; then | ||
# remove the protocol | ||
url="$(echo ${1/"$proto://"/})" | ||
# extract the user (if any) | ||
login="$(echo $url | grep @ | cut -d@ -f1)" | ||
username="$(echo $login | cut -d: -f1)" | ||
password="$(echo $login | cut -d: -f2)" | ||
# extract the host | ||
host_port="$(echo ${url/$login@/} | cut -d/ -f1) " | ||
host="$(echo $host_port | cut -f1 -d:) " | ||
|
||
# by request - try to extract the port | ||
port="$(echo $host_port | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')" | ||
# extract the uri (if any) | ||
resource="/$(echo $url | grep / | cut -d/ -f2-)" | ||
fi | ||
echo -n "{ \"uri\": \"$1\" , \"url\": \"$url\" , \"proto\": \"$proto\" , \"login\": \"$login\" ," | ||
echo " \"username\": \"$username\" , \"password\": \"$password\" , \"host\": \"$host\" , \"port\": \"$port\" }" | ||
} | ||
|
||
get_npm_proxy_config(){ | ||
local proto json | ||
proto=$1 | ||
json=$2 | ||
username=$( echo $json | jq -r .username) | ||
password=$( echo $json | jq -r .password) | ||
host=$( echo $json | jq -r .host) | ||
port=$( echo $json | jq -r .port) | ||
proxy_url="$host:$port" | ||
|
||
if [ -n "$username" -a -n "$password" ]; then | ||
proxy_url="$proto://$username:$password@$proxy_url" | ||
fi | ||
|
||
echo $proxy_url | ||
} | ||
|
||
|
||
if [ -n "$http_proxy" ]; then | ||
json=$( parse_url $http_proxy ) | ||
proxy=$(get_npm_proxy_config http "$json") | ||
npm -g config set proxy $proxy | ||
fi | ||
|
||
if [ -n "$https_proxy" ]; then | ||
json=$( parse_url $https_proxy ) | ||
proxy=$(get_npm_proxy_config https "$json") | ||
npm -g config set https_proxy $proxy | ||
fi | ||
|
||
if [ -n "$no_proxy" ]; then | ||
npm -g config set noproxy $no_proxy | ||
fi | ||
|
||
if [ -n "$NPM_MIRROR_URL" ]; then | ||
npm -g config set registry "$NPM_MIRROR_URL" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This will make scl collection binaries work out of box. | ||
unset BASH_ENV PROMPT_COMMAND ENV | ||
source scl_source enable rh-nodejs12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/docker/engine-api/types/container" | ||
"github.com/openshift/jenkins/pkg/docker" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "NodeJS Agent Suite") | ||
} | ||
|
||
var dockercli *docker.Client | ||
var imageName string | ||
|
||
var _ = BeforeSuite(func() { | ||
var err error | ||
dockercli, err = docker.NewEnvClient() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
imageName = os.Getenv("IMAGE_NAME") | ||
if imageName == "" { | ||
imageName = "vbobade/openshift-jenkins-base-agent" | ||
} | ||
}) | ||
|
||
var _ = Describe("NodeJS agent testing", func() { | ||
var id string | ||
|
||
AfterEach(func() { | ||
if CurrentGinkgoTestDescription().Failed { | ||
By("printing container logs") | ||
logs, err := dockercli.ContainerLogs(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
_, err = GinkgoWriter.Write(logs) | ||
Expect(err).NotTo(HaveOccurred()) | ||
} | ||
|
||
err := dockercli.ContainerStop(id, nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = dockercli.ContainerRemove(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
It("should contain a runnable oc", func() { | ||
var err error | ||
id, err = dockercli.ContainerCreate( | ||
&container.Config{ | ||
Image: imageName, | ||
Cmd: []string{"oc"}, | ||
Tty: true, | ||
}, | ||
nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = dockercli.ContainerStart(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
code, err := dockercli.ContainerWait(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(code).To(Equal(0)) | ||
}) | ||
|
||
It("should contain a runnable npm", func() { | ||
// the default entrypoint for the image assumes if you supply more than | ||
// one arg, you are trying to invoke the slave logic, so we have to | ||
// override the entrypoint to run complicated commands for testing. | ||
|
||
var err error | ||
id, err = dockercli.ContainerCreate( | ||
&container.Config{ | ||
Image: imageName, | ||
Entrypoint: []string{"/bin/bash", "-c", "npm --version"}, | ||
Tty: true, | ||
}, | ||
nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = dockercli.ContainerStart(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
code, err := dockercli.ContainerWait(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(code).To(Equal(0)) | ||
}) | ||
|
||
It("should contain a runnable node", func() { | ||
// the default entrypoint for the image assumes if you supply more than | ||
// one arg, you are trying to invoke the slave logic, so we have to | ||
// override the entrypoint to run complicated commands for testing. | ||
|
||
var err error | ||
id, err = dockercli.ContainerCreate( | ||
&container.Config{ | ||
Image: imageName, | ||
Entrypoint: []string{"/bin/bash", "-c", "node --version"}, | ||
Tty: true, | ||
}, | ||
nil) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
err = dockercli.ContainerStart(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
code, err := dockercli.ContainerWait(id) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(code).To(Equal(0)) | ||
}) | ||
}) |