Skip to content

Commit

Permalink
Update to version 2.0.5
Browse files Browse the repository at this point in the history
- added callback feature plus bug-fixes
- Follow Notification Lambda approach to build and upload zip file + new way to clean directory
- fix CI
  • Loading branch information
rtapella committed Oct 30, 2024
1 parent ae4f880 commit 405f0fb
Show file tree
Hide file tree
Showing 42 changed files with 378 additions and 4,756 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ RUN apt-get update && \
WORKDIR /opt/ddrv/src
COPY src /opt/ddrv/src

COPY ./LICENSE /opt/ddrv/src/

RUN npm config set @gov.nasa.jpl.m2020.cs3:registry=https://cae-artifactory.jpl.nasa.gov:443/artifactory/api/npm/npm-release-local/
RUN npm config set @gov.nasa.jpl.ammos.ids:registry=https://artifactory.jpl.nasa.gov/artifactory/api/npm/npm-develop-local/

Expand Down
2 changes: 2 additions & 0 deletions Dockerfile-localbuild
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ RUN apt-get update && \
WORKDIR /opt/ddrv/src
COPY src /opt/ddrv/src

COPY ./LICENSE /opt/ddrv/src/

RUN npm config set @gov.nasa.jpl.m2020.cs3:registry=https://cae-artifactory.jpl.nasa.gov:443/artifactory/api/npm/npm-release-local/
RUN npm config set @gov.nasa.jpl.ammos.ids:registry=https://artifactory.jpl.nasa.gov/artifactory/api/npm/npm-develop-local/

Expand Down
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
COPYRIGHT

Copyright (c) 2024 California Institute of Technology (“Caltech”). U.S. Government sponsorship acknowledged.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of Caltech nor its operating division, the Jet Propulsion Laboratory, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
export NAME ?= datadrive-commandline
export RELEASE_NAME ?= latest
export VERSION ?= latest


install:
npm --prefix src/ install

package:
npm --prefix src/ run package
docker run --rm -v "${PWD}":"/opt/ddrv/":z -e "IN_DOCKER_CONTAINER=TRUE" -e "NAME=${NAME}" -e "VERSION=${VERSION}" -e "WORKING_DIR=/opt/ddrv" cae-artifactory.jpl.nasa.gov:17001/node:18.16.1 /opt/ddrv/ci.cd/create_zip.sh
push:
curl -H X-JFrog-Art-Api:${CAE_ARTI_TOKEN_PSW} -T deployment/dist/${NAME}__${VERSION}.zip ${ARTIFACTORY_URL}/${IMAGE_PREFIX}/${NAME}__${VERSION}.zip
copy:
docker run --rm -v "${PWD}":"/opt/ddrv/":z -e "IN_DOCKER_CONTAINER=TRUE" -e "NAME=${NAME}" -e "VERSION=${VERSION}" -e "NEW_TAG=${NEW_TAG}" -e "WORKING_DIR=/opt/ddrv" cae-artifactory.jpl.nasa.gov:17001/node:18.16.1 /opt/ddrv/ci.cd/copy_release.sh
clean:
docker run --rm -v "${PWD}":"/opt/ddrv/":z -e "IN_DOCKER_CONTAINER=TRUE" -e "NAME=${NAME}" -e "VERSION=${VERSION}" -e "WORKING_DIR=/opt/ddrv" cae-artifactory.jpl.nasa.gov:17001/node:18.16.1 /opt/ddrv/ci.cd/clean_dir.sh

build:
docker build -t $(NAME):$(RELEASE_NAME) -f Dockerfile-localbuild .
Expand All @@ -16,7 +24,7 @@ test:
npm --prefix src/ test

release:
npm --prefix src/ run semantic-release
npm --prefix src/ install --only=dev && npm --prefix src/ run semantic-release

release-dry-run:
npm --prefix src/ run semantic-release-dry-run
npm --prefix src/ install --only=dev && npm --prefix src/ run semantic-release-dry-run
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you are a developer or want to make changes, or try an unreleased development

#### Prerequisites

- NodeJS: tested with v14.15.0, versions newer should also work
- NodeJS: tested with v14.15.0, versions newer should also work.

#### Building with Docker (recommended)

Expand Down Expand Up @@ -56,8 +56,7 @@ If you are a developer or want to make changes, or try an unreleased development
To configure the CLI, please run the following command:

- `ddrv config --help` will show the help screen and available options
- The basic required configuration is the Datadrive Middleware server and the PEP server,
- ex: `./ddrv config -d [datadrive_middleware_hostname] -p [pep_hostname]`
- The basic required configuration is the Datadrive Middleware server and the PEP server, ex: `./ddrv config -d [datadrive_middleware_hostname] -p [pep_hostname]`
- Other typical options include a custom log path and the time interval to roll the log files: `./ddrv config --dd-host datadrive-middle-dev.dev.m20.jpl.nasa.gov --pep-host data.dev.m20.jpl.nasa.gov --logdir log_output_folder --log-date-pattern daily`

The command above will create a configuration JSON file in `~/.datadrive/datadrive.json`. Note: You should only need to run this once unless `~/.datadrive/datadrive.json` file is deleted or you are using the ddrv CLI with multiple environments.
Expand Down Expand Up @@ -131,14 +130,15 @@ By default, logs are archived in a gzip file. To disable this functionality, set

The `--log-date-pattern`, `--no_gzip_rolling_logs`, and `--logdir` options can also be used with the `ddrv subscribe` command to determine the logging options for that particular subscription session.

### Subscriptions with your own script
### Subscriptions that auto-execute a command on each downloaded file

You can run a single script that will be called for every notification.
You can run a single shell command that will be called for every file downloaded. You can use this to automatically run post-processing, for example.

- Ex: `./ddrv subscribe -p [ocs_package_name] -o [output_directory_path_here] -r -x [regex_filter] --callback 'command_to_execute'`
- `--callback` flag's value should be in single quotes
- `--callback` flag's value is an shell command and can use these special variables: `$FILENAME` `$SRC_PATH` `$DEST_PATH`
- for example: `ddrv subscribe -if --retain-path -p sample-package -o output_folder -f 'filter-string*' -P --callback 'echo $FILENAME $SRC_PATH $DEST_PATH'`

- Ex: `./ddrv subscribe -p [ocs_package_name] -o [output_directory_path_here] -r -x [regex_filter] --plugin-path [path_to_script]`
- `--plugin-path` flag's value should be an absolute path to your script.
- Please the `src/plugin_examples` folder for example scripts that you can take inspiration from.
- You must inherit from `DdPlugin` class and implement `processItem` function.

## Unit Test

Expand Down Expand Up @@ -289,7 +289,7 @@ Please note, these test cases are for **developers** performing manual test from

#### Expected Results

- Files since given date will be downloaded. In this case, "seeme123.txt" should be downloaded.
- Files since given date will be downloaded. In this case, "seeme123.txt" should be downloaded..

#### Cleanup

Expand Down
23 changes: 23 additions & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
## [2.0.4](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/compare/v2.0.3...v2.0.4) (2024-10-09)


### Bug Fixes

* release version to artifactory 2 ([#199](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/issues/199)) ([e5c2e80](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/commit/e5c2e8017975accbcdc13108e26f3c0cdc1848e3))

## [2.0.3](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/compare/v2.0.2...v2.0.3) (2024-10-09)


### Bug Fixes

* push releaase version to artifactory ([#197](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/issues/197)) ([555a451](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/commit/555a451ee4b9b852065509e325affef9aefff1ff))

## [2.0.2](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/compare/v2.0.1...v2.0.2) (2024-10-09)


### Bug Fixes

* Follow Notification Lambda approach to build and upload zip file + new way to clean directory ([#191](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/issues/191)) ([38cc89c](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/commit/38cc89c17e86a5f2601a008b0bd770b3d2941883))
* still testing release stage ([#195](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/issues/195)) ([df295b8](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/commit/df295b8178930aef3c6243388d01af735987c627))
* testing release ([#193](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/issues/193)) ([dca476e](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/commit/dca476e536157d904487dc08193620a6f218ee54))

## [2.0.1](https://github.jpl.nasa.gov/MIPL/DataDrive-CommandLine/compare/v2.0.0...v2.0.1) (2024-07-18)


Expand Down
77 changes: 50 additions & 27 deletions src/buildScript.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
'use strict';
"use strict";

const shelljs = require('shelljs');
const minimist = require('minimist');
const fs = require('fs-extra');
const path = require('path');
const shelljs = require("shelljs");
const minimist = require("minimist");
const fs = require("fs-extra");
const path = require("path");

const WORKSPACE = process.env.WORKSPACE || process.cwd();
const DIST_DIR = `${__dirname}-dist`;
const SVC_NAME = 'cli'; //path.basename(__dirname);
const SVC_NAME = "cli"; //path.basename(__dirname);
const ZIP_FILE = `ddrv-${SVC_NAME}-bundle.zip`;
const DEPLOY_DIR = '../deployment';
const PKG_DIR = './ddrv-cli';
const DEPLOY_DIR = "../deployment";
const PKG_DIR = "./ddrv-cli";

//console.log(`DIST_DIR = ${DIST_DIR}`)
//console.log(`DEPLOY_DIR = ${DEPLOY_DIR}`)
//console.log(`PKG_DIR = ${PKG_DIR}`)

const README_FILE = "README.TXT";

const README_FILE = 'README.TXT';

const {
clean,
build,
deploy
} = minimist(process.argv.slice(2));
const { clean, build, deploy } = minimist(process.argv.slice(2));

let logLevel = 0;

Expand All @@ -32,11 +27,11 @@ function upLevel(lvlDelta) {
}

function log(msg) {
console.log(' '.repeat(logLevel) + msg);
console.log(" ".repeat(logLevel) + msg);
}

function err(msg) {
console.error(' '.repeat(logLevel) + msg);
console.error(" ".repeat(logLevel) + msg);
}

function doClean() {
Expand Down Expand Up @@ -78,7 +73,11 @@ function doCopyRecursive(fromDir, toDir) {
// Recurse if directory.
const _stats = fs.lstatSync(fromFilePath);
if (_stats.isDirectory()) {
if (files[i] === 'core' || files[i] === 'plugins' || files[i] === 'exceptions') {
if (
files[i] === "core" ||
files[i] === "plugins" ||
files[i] === "exceptions"
) {
log(`Copying directory ${fromFilePath}...`);
upLevel(1);
doCopyRecursive(fromFilePath, toFilePath);
Expand All @@ -88,7 +87,6 @@ function doCopyRecursive(fromDir, toDir) {
log(`Copying file ${files[i]}`);
fs.copySync(fromFilePath, toFilePath);
}

}
}

Expand All @@ -110,7 +108,9 @@ function doCopy() {
function doConfig() {
log(`Setting up NPM config params in ${DIST_DIR}.`);
if (process.env.VENUE || process.env.BRANCH) {
log(`Found environment variables VENUE=${process.env.VENUE} and BRANCH=${process.env.BRANCH}`);
log(
`Found environment variables VENUE=${process.env.VENUE} and BRANCH=${process.env.BRANCH}`,
);
const NPMRC = `${DIST_DIR}/.npmrc`;
if (process.env.VENUE) {
fs.writeFileSync(NPMRC, `venue = "${process.env.VENUE}"\n`);
Expand All @@ -119,32 +119,56 @@ function doConfig() {
fs.appendFileSync(NPMRC, `branch = "${process.env.BRANCH}"\n`);
}
} else {
log('No environment variables for VENUE/BRANCH. Deployment will use the defaults from package.json');
log(
"No environment variables for VENUE/BRANCH. Deployment will use the defaults from package.json",
);
}
}

function doInstall() {
log(`Running NPM INSTALL in ${DIST_DIR}.`);
shelljs.cd(DIST_DIR);
shelljs.exec('npm install --production');
shelljs.exec("npm install --production");
}

function doTextReplace() {
const licenseText = fs.readFileSync(
path.join(__dirname, "LICENSE"),
"utf-8",
);
const licenseScript = fs.readFileSync(
path.join(DIST_DIR, "ddrv-license.js"),
"utf-8",
);
const updatedLicenseScript = licenseScript.replace(
"${LICENSE_TEXT}",
licenseText,
);
fs.writeFileSync(
path.join(DIST_DIR, "ddrv-license.js"),
updatedLicenseScript,
);
}

function doBuild(clean = true) {
log(`Building ${__dirname} in ${DIST_DIR}:`);
upLevel(1);
doInit();
doCopy();
doTextReplace();
doConfig();
doInstall();
upLevel(-1);
}

function doPackage() {
shelljs.cd(DIST_DIR);
for (const tgtOS of ['linux', 'macos', 'win']) {
for (const tgtOS of ["linux", "macos", "win"]) {
log(`Packaging the DataDrive CLI for ${tgtOS}`);
fs.ensureDirSync(`${PKG_DIR}/${tgtOS}-x64`);
shelljs.exec(`pkg . -t ${tgtOS}-x64 --output ${PKG_DIR}/${tgtOS}-x64/ddrv`);
shelljs.exec(
`pkg . -t ${tgtOS}-x64 --output ${PKG_DIR}/${tgtOS}-x64/ddrv`,
);
shelljs.chmod(555, `${PKG_DIR}/${tgtOS}-x64/ddrv*`);
}
// Move the README
Expand All @@ -153,7 +177,7 @@ function doPackage() {
shelljs.cd(PKG_DIR);
// ZIP it up, ready for staging.
shelljs.exec(`zip -rq ${ZIP_FILE} .`);
shelljs.mv(`${ZIP_FILE}`, '..');
shelljs.mv(`${ZIP_FILE}`, "..");
}

function doStage() {
Expand Down Expand Up @@ -190,10 +214,9 @@ function ensureProjectDir() {
ensureProjectDir();
if (deploy) {
doDeploy();
//log(`Deploy option currently not supported`);
//log(`Deploy option currently not supported`);
} else if (clean) {
doClean();
} else if (build) {
doBuild();
}

29 changes: 0 additions & 29 deletions src/core/AxiosWrapper.js

This file was deleted.

Loading

0 comments on commit 405f0fb

Please sign in to comment.