diff --git a/.gitignore b/.gitignore index 5155ab9..124dd4b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ coverage/ node_modules/ .vscode/ output -dist \ No newline at end of file +dist +.history/ diff --git a/.pax/.keep b/.pax/.keep new file mode 100644 index 0000000..e69de29 diff --git a/.pax/pre-packaging.sh b/.pax/pre-packaging.sh new file mode 100644 index 0000000..0d28ea1 --- /dev/null +++ b/.pax/pre-packaging.sh @@ -0,0 +1,19 @@ +#!/bin/sh -e +set -x + +################################################################################ +# This program and the accompanying materials are made available under the terms of the +# Eclipse Public License v2.0 which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright IBM Corporation 2018, 2020 +################################################################################ + +FUNC=[CreatePax][pre-packaging] +PWD=$(pwd) + +# display extracted files +echo "$FUNC content of $PWD...." +find . -print diff --git a/.pax/prepare-workspace.sh b/.pax/prepare-workspace.sh new file mode 100755 index 0000000..02ed0f8 --- /dev/null +++ b/.pax/prepare-workspace.sh @@ -0,0 +1,78 @@ +#!/bin/bash -e + +################################################################################ +# This program and the accompanying materials are made available under the terms of the +# Eclipse Public License v2.0 which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-v20.html +# +# SPDX-License-Identifier: EPL-2.0 +# +# Copyright IBM Corporation 2018, 2020 +################################################################################ + +################################################################################ +# Build script +# +# - build client +# - import ui server dependency +################################################################################ + +# contants +SCRIPT_NAME=$(basename "$0") +BASEDIR=$(dirname "$0") +PAX_WORKSPACE_DIR=.pax +PACKAGE_NAME=$(node -e "console.log(require('./package.json').name)") +PACKAGE_VERSION=$(node -e "console.log(require('./package.json').version)") +PACKAGE_DESC=$(node -e "console.log(require('./package.json').description)") +# APPLICAIION_URI=$(node -e "console.log(require('./package.json').config.baseuri)") +# APPLICAIION_PORT=$(node -e "console.log(require('./package.json').config.port)") +ZOWE_PLUGIN_ID="com.ibm.${PACKAGE_NAME}" + +cd $BASEDIR +cd .. +ROOT_DIR=$(pwd) + +# prepare pax workspace +echo "[${SCRIPT_NAME}] cleaning PAX workspace ..." +rm -fr "${PAX_WORKSPACE_DIR}/content" +mkdir -p "${PAX_WORKSPACE_DIR}/content" + +# copy plugin definition files +# echo "[${SCRIPT_NAME}] copying plugin definitions ..." +# cp -r plugin-definition "${PAX_WORKSPACE_DIR}/content" + +# build client +if [ ! -f "dist/app.min.js" ]; then + echo "[${SCRIPT_NAME}] building client ..." + npm run build +fi + +cd "${ROOT_DIR}" + +# copy explorer-jes to target folder +echo "[${SCRIPT_NAME}] copying sample node api backend ..." +mkdir -p "${PAX_WORKSPACE_DIR}/content/app" +cp README.md "${PAX_WORKSPACE_DIR}/content/app" +cp package.json "${PAX_WORKSPACE_DIR}/content/app" +cp package-lock.json "${PAX_WORKSPACE_DIR}/content/app" +cp -r dist/. "${PAX_WORKSPACE_DIR}/content/app" + +# copy start script to target folder +echo "[${SCRIPT_NAME}] copying startup script ..." +mkdir -p "${PAX_WORKSPACE_DIR}/content/bin" +cp -r bin/start.sh "${PAX_WORKSPACE_DIR}/content/bin" +cp -r bin/configure.sh "${PAX_WORKSPACE_DIR}/content/bin" +cp -r bin/env.sh "${PAX_WORKSPACE_DIR}/content/bin" + +# move content to another folder +rm -fr "${PAX_WORKSPACE_DIR}/ascii" +mkdir -p "${PAX_WORKSPACE_DIR}/ascii" +rsync -rv \ + --include '*.json' --include '*.html' --include '*.jcl' --include '*.template' \ + --exclude '*.zip' --exclude '*.png' --exclude '*.tgz' --exclude '*.tar.gz' --exclude '*.pax' \ + --prune-empty-dirs --remove-source-files \ + "${PAX_WORKSPACE_DIR}/content/" \ + "${PAX_WORKSPACE_DIR}/ascii" + +echo "[${SCRIPT_NAME}] ${PAX_WORKSPACE_DIR} folder is prepared." +exit 0 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..df10414 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,113 @@ +#!groovy + +/** + * This program and the accompanying materials are made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-v20.html + * + * SPDX-License-Identifier: EPL-2.0 + * + * Copyright IBM Corporation 2020 + */ + + +node('ibm-jenkins-slave-dind') { + def lib = library("jenkins-library").org.zowe.jenkins_shared_library + + def pipeline = lib.pipelines.nodejs.NodeJSPipeline.new(this) + + pipeline.admins.add("stevenh") + + pipeline.setup( + packageName: 'org.zowe.sample-node-api', + nodeJsVersion: 'v10.18.1', + github: [ + email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL, + usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL, + ], + artifactory: [ + url : lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL, + usernamePasswordCredential : lib.Constants.DEFAULT_LFJ_ARTIFACTORY_ROBOT_CREDENTIAL, + ], + pax: [ + sshHost : lib.Constants.DEFAULT_PAX_PACKAGING_SSH_HOST, + sshPort : lib.Constants.DEFAULT_PAX_PACKAGING_SSH_PORT, + sshCredential : lib.Constants.DEFAULT_PAX_PACKAGING_SSH_CREDENTIAL, + remoteWorkspace : lib.Constants.DEFAULT_PAX_PACKAGING_REMOTE_WORKSPACE, + ], + installRegistries: [ + [ + email : lib.Constants.DEFAULT_LFJ_NPM_PRIVATE_REGISTRY_EMAIL, + usernamePasswordCredential : lib.Constants.DEFAULT_LFJ_NPM_PRIVATE_REGISTRY_CREDENTIAL, + registry : lib.Constants.DEFAULT_LFJ_NPM_PRIVATE_REGISTRY_INSTALL, + ] + ], + publishRegistry: [ + email : lib.Constants.DEFAULT_LFJ_NPM_PRIVATE_REGISTRY_EMAIL, + usernamePasswordCredential : lib.Constants.DEFAULT_LFJ_NPM_PRIVATE_REGISTRY_CREDENTIAL, + ], + // FIXME: ideally this should set to false (using default by remove this line) + ignoreAuditFailure : true, + // FIXME: npm version in ibm-jenkins-slave-dind is too old, doesn't support "npm ci" + alwaysUseNpmInstall : true + + ) + + pipeline.build() + + // // we have a custom build command + // pipeline.build( + // operation: { + // ansiColor('xterm') { + // pipeline.nvmShell "npm run prod" + // } + // } + // ) + + // pipeline.test( + // name : 'Unit', + // junit : "target/report.xml", + // cobertura : [ + // coberturaReportFile : "coverage/cobertura-coverage.xml", + // // if coverage check failed, the pipeline will be marked as UNSTABLE, which + // // will block publish/release. So we overwrite default and set to false here. + // // FIXME: ideally this should set to true (using default by remove this line) + // autoUpdateStability : false, + // fileCoverageTargets : '100, 0, 0', + // classCoverageTargets : '85, 0, 0', + // methodCoverageTargets : '80, 0, 0', + // lineCoverageTargets : '80, 0, 0', + // conditionalCoverageTargets: '70, 0, 0', + // ], + // htmlReports : [ + // [dir: "coverage/lcov-report", files: "index.html", name: "Report: Code Coverage"], + // ], + // ) + + // we need sonar scan + // failBuild set to false whilst investigating https://github.com/zowe/zlux/issues/285 + pipeline.sonarScan( + scannerTool : lib.Constants.DEFAULT_LFJ_SONARCLOUD_SCANNER_TOOL, + scannerServer : lib.Constants.DEFAULT_LFJ_SONARCLOUD_SERVER, + allowBranchScan : lib.Constants.DEFAULT_LFJ_SONARCLOUD_ALLOW_BRANCH, + failBuild : false + ) + + // we have pax packaging step + pipeline.packaging(name: 'sample-node-api') + + // define we need publish stage + pipeline.publish( + operation: { + echo "Default npm publish will be skipped." + }, + artifacts: [ + '.pax/sample-node-api.pax' + ] + ) + + // define we need release stage + pipeline.release() + + pipeline.end() +} diff --git a/README.md b/README.md index 61eb250..5e4ba27 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ npm install --only=prod ### 3) Manage lifecycle of service with core zowe components -Use property `EXTERNAL_COMPONENT` located in file `$INSTANCE_DIR/instance.env` -Append it with your service lifecycle scripts. +Use property `EXTERNAL_COMPONENTS` located in file `$INSTANCE_DIR/instance.env` +Append it (comma separated) with the directory containing your service lifecycle scripts. In our sample it is: ``` diff --git a/package.json b/package.json index 74fc972..1770db7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sample-node-api", "version": "1.0.0", - "description": "", + "description": "Zowe sample node API", "main": "index.js", "scripts": { "dev": "nodemon src/index.js",