Skip to content
Snippets Groups Projects
Commit 90a0183a authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

Update build process to include js assets for legacy compatibility

parent ca614044
No related branches found
No related tags found
No related merge requests found
......@@ -3,33 +3,82 @@
pipeline {
agent {
kubernetes {
label 'kubedeploy-agent-' + env.JOB_NAME.replaceAll("/", "-")
label 'buildenv-agent'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: kubectl
image: eclipsefdn/kubectl:okd-c1
command:
- cat
tty: true
resources:
limits:
cpu: 1
memory: 1Gi
volumeMounts:
- mountPath: "/home/default/.kube"
name: "dot-kube"
readOnly: false
- name: jnlp
resources:
limits:
cpu: 1
memory: 1Gi
volumes:
- name: "dot-kube"
emptyDir: {}
apiVersion: v1
kind: Pod
spec:
containers:
- name: buildcontainer
image: eclipsefdn/stack-build-agent:h111.3-n18.16-jdk11
imagePullPolicy: Always
command:
- cat
tty: true
resources:
requests:
cpu: "1"
memory: "4Gi"
limits:
cpu: "2"
memory: "4Gi"
env:
- name: "HOME"
value: "/home/jenkins"
- name: "MAVEN_OPTS"
value: "-Duser.home=/home/jenkins"
volumeMounts:
- name: m2-repo
mountPath: /home/jenkins/.m2/repository
- name: m2-secret-dir
mountPath: /home/jenkins/.m2/settings.xml
subPath: settings.xml
readOnly: true
- mountPath: "/home/jenkins/.m2/settings-security.xml"
name: "m2-secret-dir"
readOnly: true
subPath: "settings-security.xml"
- mountPath: "/home/jenkins/.mavenrc"
name: "m2-dir"
readOnly: true
subPath: ".mavenrc"
- mountPath: "/home/jenkins/.m2/wrapper"
name: "m2-wrapper"
readOnly: false
- mountPath: "/home/jenkins/.cache"
name: "yarn-cache"
readOnly: false
- mountPath: "/home/jenkins/.sonar"
name: "sonar-cache"
readOnly: false
- mountPath: "/home/jenkins/.config"
name: "config-folder"
readOnly: false
- name: jnlp
resources:
requests:
memory: "1024Mi"
cpu: "500m"
limits:
memory: "1024Mi"
cpu: "1000m"
volumes:
- name: "m2-dir"
configMap:
name: "m2-dir"
- name: m2-secret-dir
secret:
secretName: m2-secret-dir
- name: m2-repo
emptyDir: {}
- name: m2-wrapper
emptyDir: {}
- name: yarn-cache
emptyDir: {}
- name: sonar-cache
emptyDir: {}
- name: config-folder
emptyDir: {}
'''
}
}
......@@ -73,66 +122,7 @@ pipeline {
}
stages {
stage('Build build environment docker image') {
agent {
label 'docker-build'
}
steps {
withDockerRegistry([credentialsId: '04264967-fea0-40c2-bf60-09af5aeba60f', url: 'https://index.docker.io/v1/']) {
sh '''
docker build -f src/main/docker/Dockerfile.agent --no-cache -t ${IMAGE_NAME}-build-env:${TAG_NAME} -t ${IMAGE_NAME}-build-env:latest .
docker push ${IMAGE_NAME}-build-env:${TAG_NAME}
docker push ${IMAGE_NAME}-build-env:latest
'''
}
}
}
stage('Build project') {
agent {
kubernetes {
label 'buildenv-agent'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: buildcontainer
image: eclipsefdn/eclipsefdn-project-adopters-build-env:latest
imagePullPolicy: Always
command:
- cat
tty: true
resources:
limits:
cpu: 2
memory: 4Gi
env:
- name: "MAVEN_OPTS"
value: "-Duser.home=/home/jenkins"
volumeMounts:
- name: settings-xml
mountPath: /home/jenkins/.m2/settings.xml
subPath: settings.xml
readOnly: true
- name: m2-repo
mountPath: /home/jenkins/.m2/repository
- name: jnlp
resources:
limits:
cpu: 2
memory: 4Gi
volumes:
- name: settings-xml
secret:
secretName: m2-secret-dir
items:
- key: settings.xml
path: settings.xml
- name: m2-repo
emptyDir: {}
'''
}
}
steps {
container('buildcontainer') {
sh '''
......
{
"extends": "./node_modules/eclipsefdn-solstice-assets/babel.config.json"
}
\ No newline at end of file
const eclipsefdn_adopters_element = document.querySelectorAll(".eclipsefdn-adopters")[0];
function testAdopters(baseURL) {
fetch(baseURL + "/assets/js/adopters.json")
.then(function(response) {
if (response.ok) {
return response.json();
} else {
return Promise.reject(response);
}
})
.then(function(data) {createWGAdopters(data.adopters, baseURL)})
.catch(function(error) {console.log(error)})
}
function createWGAdopters(data, baseURL) {
var project_set = new Set();
for(var i=0; i<data.length; i++) {
// Loop the projects of this adopter
for(var j=0; j<data[i].projects.length; j++) {
var project = data[i].projects[j];
// If not exists this project
if( !project_set.has(project) ) {
project_set.add(project);
// add the title
createProjectHeader(project);
}
createAdopters(project, data[i], baseURL);
}
}
scrollToAnchor();
}
function createProjectHeader(project) {
var h2 = document.createElement('h2');
h2.textContent = project;
h2.setAttribute("id", project);
eclipsefdn_adopters_element.appendChild(h2);
// add the button
var headerAnchor = document.createElement('a');
headerAnchor.setAttribute('class', 'btn btn-xs btn-secondary margin-left-10');
headerAnchor.setAttribute('href', 'https://projects.eclipse.org/projects/' + project);
headerAnchor.textContent = project;
h2.appendChild(headerAnchor);
var ul = document.createElement('ul');
ul.setAttribute("class", "text-center list-inline");
ul.setAttribute("id", project + "-ul");
eclipsefdn_adopters_element.appendChild(ul);
}
function createAdopters(project, adopter, baseURL) {
var element = document.getElementById(project + "-ul");
// Skip creating the logo if it is empty string or undefined or null
if (!adopter['logo']) {
return;
}
// Get the home page url of this adopter
var url = '';
if (typeof adopter['homepage_url'] !== 'undefined') {
url = adopter['homepage_url'];
}
// Get the name of this adopter
var name = '';
if (typeof adopter['name'] !== 'undefined') {
name = adopter['name'];
}
// Get the logo of this adopter
var logo = '';
if (typeof adopter['logo'] !== 'undefined') {
logo = adopter['logo'];
}
// Create the html elements
var li = document.createElement('li');
var a = document.createElement('a');
var img = document.createElement('img');
a.setAttribute('href', url);
img.setAttribute('alt', name);
img.setAttribute('src', baseURL + '/assets/images/adopters/' + logo);
img.setAttribute('class', 'adopters-img');
a.appendChild(img);
li.appendChild(a);
element.appendChild(li);
}
// Function to scroll when there is anchor in url
function scrollToAnchor() {
if (location.hash) {
var projectId = location.hash.replace('#', '');
var element = document.getElementById(`${projectId}`);
element.scrollIntoView();
}
}
\ No newline at end of file
/*!
* Copyright (c) 2019 Eclipse Foundation, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* Contributors:
* Eric Poirier <eric.poirier@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
const EclipseFdnAdopters = (function (window, document) {
class EclipseFdnAdoptersClass {
precompiledRegex =
/<([^>]*?)>;(\s?[\w-]*?="(?:\\"|[^"])*";){0,}\s?rel="next"/;
// Default settings
default_options = {
project_id: '',
selector: '.eclipsefdn-adopters',
ul_classes: '',
logo_white: false,
working_group: '',
src_root: 'https://api.eclipse.org/adopters',
src_projects_prefix: '/projects',
};
getMergedOptions(options) {
// Default settings copy
var opts = JSON.parse(JSON.stringify(this.default_options));
// Go through the parameters of Options if its defined and is an object
if (typeof options !== 'undefined' && typeof options === 'object') {
for (var optionName in this.default_options) {
if (
typeof options[optionName] === 'undefined' ||
(typeof options[optionName] !== 'string' &&
typeof options[optionName] !== 'boolean')
) {
continue;
}
opts[optionName] = options[optionName];
}
}
return opts;
}
/**
* Replace the adopters container
* @public
* @param {Object} options Videos attributes
*/
getList = function (options) {
var t = this;
var opts = this.getMergedOptions(options);
this.fireCall(opts, function (response) {
t.createProjectList(
response,
opts,
document.querySelectorAll(opts.selector)
);
t.scrollToAnchor();
});
};
/**
* Replace the adopters container
* @public
* @param {Object} options Videos attributes
*/
getWGList = function (options) {
var t = this;
var opts = this.getMergedOptions(options);
// create callback on ready
this.fireCall(opts, function (response) {
t.createWGProjectsList(
response,
opts,
document.querySelectorAll(opts.selector)
);
t.scrollToAnchor();
});
};
fireCall(opts, callback, currentData = []) {
var t = this;
var xhttp = new XMLHttpRequest();
// create callback on ready
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// merge new data with current
var json = JSON.parse(this.responseText);
if (Array.isArray(currentData) || currentData.length) {
json = currentData.concat(json);
}
// check the link header as long as its set
var linkHeader = xhttp.getResponseHeader('Link');
if (linkHeader !== null) {
var match = linkHeader.match(t.precompiledRegex);
// if there is no match, then there is no next and we are on the last page and should process data through callback
if (match !== null) {
opts.next = match[1];
t.fireCall(opts, callback, json);
} else {
callback(json);
}
} else {
callback(json);
}
} else if (this.readyState == 4) {
console.log(
'Error while retrieving adopters data, could not complete operation'
);
}
};
// get the URL to call, using the 'next' url if set, otherwise building from original option set
var url;
if (opts.next !== undefined) {
url = opts.next;
} else {
url = opts.src_root + opts.src_projects_prefix;
if (opts.project_id !== undefined && opts.project_id.trim() !== '') {
url += '/' + opts.project_id;
}
if (
opts.working_group !== undefined &&
opts.working_group.trim() !== ''
) {
url += '?working_group=' + opts.working_group;
}
}
// send request to get JSON data
xhttp.open('GET', url, true);
xhttp.send();
}
createWGProjectsList(json_object, opts, el) {
for (const project of json_object) {
var projectOpts = JSON.parse(JSON.stringify(opts));
projectOpts.project_id = project.project_id;
// add the title
const h2 = document.createElement('h2');
h2.textContent = project.name;
h2.setAttribute('id', project.project_id);
for (var i = 0; i < el.length; i++) {
el[i].appendChild(h2);
}
const headerAnchor = document.createElement('a');
headerAnchor.setAttribute(
'class',
'btn btn-xs btn-secondary margin-left-10 uppercase'
);
headerAnchor.setAttribute(
'href',
'https://projects.eclipse.org/projects/' + project.project_id
);
headerAnchor.textContent = project.project_id;
h2.appendChild(headerAnchor);
this.createProjectList(json_object, projectOpts, el);
}
}
createProjectList(json_object, opts, el) {
const ul = document.createElement('ul');
if (typeof json_object !== 'undefined') {
for (const project of json_object) {
if (opts.project_id !== project.project_id) {
continue;
}
for (const adopter of project.adopters) {
// Get the home page url of this adopter
var url = '';
if (typeof adopter['homepage_url'] !== 'undefined') {
url = adopter['homepage_url'];
}
// Get the name of this adopter
var name = '';
if (typeof adopter['name'] !== 'undefined') {
name = adopter['name'];
}
// Skip creating the logo if it's empty string or undefined or null
if (opts['logo_white'] === true && !adopter['logo_white']) {
continue;
}
if (opts['logo_white'] !== true && !adopter['logo']) {
continue;
}
// Get the logo of this adopter
var logo = '';
if (opts['logo_white'] === true) {
logo = adopter['logo_white'];
} else {
logo = adopter['logo'];
}
// Create the html elements
let li = document.createElement('li');
let a = document.createElement('a');
let img = document.createElement('img');
a.setAttribute('href', url);
img.setAttribute('alt', name);
img.setAttribute(
'src',
opts.src_root + '/assets/images/adopters/' + logo
);
img.setAttribute('class', 'adopters-img');
a.appendChild(img);
li.appendChild(a);
ul.appendChild(li);
}
}
}
for (var i = 0; i < el.length; i++) {
if (opts['ul_classes'] !== '') {
ul.setAttribute('class', opts['ul_classes']);
}
el[i].appendChild(ul);
}
}
// Function to scroll when there is anchor in url
scrollToAnchor() {
if (location.hash) {
var projectId = location.hash.replace('#', '');
var element = document.getElementById(`${projectId}`);
element.scrollIntoView();
}
}
}
window.eclipseFdnAdopters = new EclipseFdnAdoptersClass();
})(window, document);
export default EclipseFdnAdopters;
\ No newline at end of file
......@@ -14,8 +14,9 @@
"scripts": {
"test": "jsonlint config/adopters.json",
"build": "rm -rf src/main/resources/META-INF/resources/* && cp -R static/assets src/main/resources/META-INF/resources/",
"postinstall": "npm run minify_adopters",
"postinstall": "npm run production && npm run minify_adopters",
"minify_adopters": "mkdir -p target/config && ./node_modules/json-minify/index.js config/adopters.json > target/config/adopters.json",
"production": "NODE_ENV=production webpack --progress --config=node_modules/laravel-mix/setup/webpack.config.js && npm run adopters_json && npm run test",
"adopters_json": "cp config/adopters.json static/assets/js"
},
"dependencies": {
......
####
#
# Create a base image for building web+java properties. Add support for nodeJS, NPM, and mvn
#
####
FROM alpine:3.12
# add mvn, npm, nodejs, hugo
RUN apk add --update --no-cache\
openjdk11-jre \
npm \
nodejs \
nghttp2 \
maven \
wget \
tar
WORKDIR /tmp
RUN wget -qO- https://github.com/gohugoio/hugo/releases/download/v0.62.2/hugo_0.62.2_Linux-64bit.tar.gz | tar xvz -C /bin/
ENTRYPOINT [ "/bin/sh" ]
\ No newline at end of file
{
"/js/adopters_test.js": "/js/adopters_test.js",
"/js/eclipsefdn.adopters.js": "/js/eclipsefdn.adopters.js",
"/js/scripts.min.js": "/js/scripts.min.js",
"/css/styles.css": "/css/styles.css"
"/js/eclipsefdn.adopters.js": "/js/eclipsefdn.adopters.js"
}
/*!
* Copyright (c) 2018, 2020 Eclipse Foundation, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* Contributors:
* Christopher Guindon <chris.guindon@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
require('./node_modules/eclipsefdn-solstice-assets/webpack-solstice-assets.mix.js');
let mix = require('laravel-mix');
mix.EclipseFdnSolsticeAssets();
mix.setPublicPath('static/assets');
mix.setResourceRoot('../');
mix.js('js/adopters_test.js', './static/assets/js/adopters_test.js');
mix.js('js/eclipsefdn.adopters.js', './static/assets/js/eclipsefdn.adopters.js');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment