Giter VIP home page Giter VIP logo

aio-cli-plugin-asset-compute's Introduction

oclif Version License codecov Travis

@adobe/aio-cli-plugin-asset-compute

Asset Compute Plugin for the Adobe I/O CLI. This plugin supports developing and testing of Asset Compute custom workers.

Documentation

Further documentation:

Installation and Usage

For interactive use as developer, install this as aio-cli plugin using:

aio plugins:install @adobe/aio-cli-plugin-asset-compute

To list available commands, run

aio asset-compute

See commands for a description of all commands.

When aio asset-compute is run inside a project directory with a package.json with the plugin installed as devDependency (see below), then it will use exactly that dependency version (available since 1.4.0). This ensures test execution behaves the same as with aio app test in e.g. CI builds, even if the plugin version installed by the developer in aio is different. In other directories it will simply use its own command implementations.

Use as project Dependency

Inside Asset Compute App Builder projects, @adobe/aio-cli-plugin-asset-compute will also be present as npm devDependency. This is used by aio app test and aio app run.

Projects created using aio app init with the Asset Compute Worker generator will automatically be include this dependency in their package.json, so no separate installation is required.

In case of creating a project setup from scratch, install it as devDependency using:

npm install --save-dev @adobe/aio-cli-plugin-asset-compute

Then it can be used with aio app test or npm test by adding a test script to the package.json. Or an aio app hook such as post-app-run. Note that the bin name is adobe-asset-compute in this case:

    "scripts": {
        "test": "adobe-asset-compute test-worker",
        "post-app-run": "adobe-asset-compute devtool"
    }

Debugging workers

If you use the debug library inside your worker code, you can enable it in test-worker and run-worker commands by setting the WORKER_DEBUG environment variable just like the standard DEBUG variable:

WORKER_DEBUG=mystuff aio asset-compute test-worker

Commands

aio devtool

Starts the Asset Compute Developer Tool

USAGE
  $ aio devtool [-v] [--version] [--port <value>]

FLAGS
  -v, --verbose   Verbose output
  --port=<value>  [default: 9000] Http port of the Asset Compute Developer Tool Server
  --version       Show version

DESCRIPTION
  Starts the Asset Compute Developer Tool

aio run-worker FILE RENDITION

Run worker from local project using Docker

USAGE
  $ aio run-worker [FILE] [RENDITION] [-v] [--version] [-a <value>] [-d <value> | -P <value> | -p <value>]

ARGUMENTS
  FILE       Path to input file for worker
  RENDITION  Path where to create output rendition.
             Single file for single rendition, or directory to create multiple renditions, in which case the full
             parameter json including rendition names must be provided using --data.

FLAGS
  -P, --paramFile=<value>  Path to parameter json file.
  -a, --action=<value>     Worker to run. Use action name from manifest. Not required if there is only one.
  -d, --data=<value>       Complete input parameters as JSON string. Allows multiple renditions.
  -p, --param=<value>...   <key> <value> - Set parameters for rendition, can be used multiple times
  -v, --verbose            Verbose output
  --version                Show version

DESCRIPTION
  Run worker from local project using Docker

aio test-worker [TESTCASE]

Run tests from local project

USAGE
  $ aio test-worker [TESTCASE] [-v] [--version] [-a <value>] [-u]

ARGUMENTS
  TESTCASE  Test case(s) to run. Supports glob patterns. If not set, runs all tests.

FLAGS
  -a, --action=<value>    Worker to test. Use action name from manifest. If not set, runs tests for all workers.
  -u, --updateRenditions  Replace expected renditions of failing test cases with the generated rendition.
  -v, --verbose           Verbose output
  --version               Show version

DESCRIPTION
  Run tests from local project

ALIASES
  $ aio tw

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

aio-cli-plugin-asset-compute's People

Contributors

adamcin avatar alexkli avatar badvision avatar bobvanmanen avatar dependabot[bot] avatar drgirlfriend avatar jdelbick avatar pheenomenon avatar purplecabbage avatar semantic-release-bot avatar shazron avatar tmathern avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-cli-plugin-asset-compute's Issues

Tests are outdated

Not sure the impact of this, currently tests are passing.

Looking through all the project mocks, some are:

  • specifying an ancient runtime: 'nodejs:10'
  • declaring dependency of "@adobe/asset-compute-sdk": "^2.10.6" which is 2 majors outdated

Also, the test-projects directory, after tests are run, consumes ~1.5 GB of disk space. It would be nice if this was cleaned up, or mocked so all the dependencies did not need to be installed.

Deprecate nodejs:10

Runtime is deprecating the nodejs:10 image on Jan. 4th, 2023.

Remove the image from the list of available kinds here and mark it as deprecated.

Test-worker doesn't use any extra parameters provided to worker action via manifest.yml

First of all, not sure if the right repo to raise that issue but in my opinion it fits the best. Anyway, when implementing workers to uses some 3rd party service you usually need to provide some secrets/credentials to use that service via the action parameters (via manifest.yml). Apparently, if such params are defined, if running the test-worker tests via aio app test those parameters simply does not exists - so unable to test properly any worker.

Expected Behaviour

  • Any parameter defined in manifest.yml is passed to the worker action when running test-worker

Actual Behaviour

  • Parameters from manifest.yml are simply ignored

Steps to reproduce

You can use my sample repo to reproduce the issue: https://github.com/marcinczeczko/aio-cli-test-worker-reproducer

  • It's basically a vanilla worker code generate via aio app init
  • I added myParam to the manifest.yml and params argument to the worker code, as follows and then printed out to console log.
exports.main = worker(async (source, rendition, params) {}
  1. Run aio app test
  2. Open the generate log file and fine the line (will start with All the params: that prints out all the action params). It will contains all the params without but no myParam
2020-10-06T09:39:41.197858382Z All the params:  {
  13   │ 2020-10-06T09:39:41.197882664Z   source: { url: 'file.jpg' },
  14   │ 2020-10-06T09:39:41.197888364Z   renditions: [ { fmt: 'jpg', qlt: 10, target: undefined } ],
  15   │ 2020-10-06T09:39:41.197892623Z   requestId: 'Test: corrupt-input -----------------------------------------------',
  16   │ 2020-10-06T09:39:41.197896726Z   metrics: AssetComputeMetrics {
  17   │ 2020-10-06T09:39:41.197923345Z     startDate: 2020-10-06T09:39:41.073Z,
  18   │ 2020-10-06T09:39:41.197928861Z     params: [Circular],
  19   │ 2020-10-06T09:39:41.197933175Z     newRelic: NewRelic { defaultMetrics: [Object], canSendMetrics: false }
  20   │ 2020-10-06T09:39:41.197956590Z   },
  21   │ 2020-10-06T09:39:41.197962640Z   times: {}
  22   │ 2020-10-06T09:39:41.197967078Z }

Platform and Version

System:
    OS: macOS 10.15.6
    CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
    Memory: 30.11 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.22.1 - ~/.asdf/installs/nodejs/10.22.1/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.6 - ~/.asdf/installs/nodejs/10.22.1/bin/npm
  Virtualization:
    Docker: 19.03.12 - /usr/local/bin/docker
  npmGlobalPackages:
    @adobe/aio-cli: 4.0.0
  CLI plugins:
    @adobe/aio-cli 4.0.0 (core)
    @adobe/aio-cli-plugin-aem 1.0.4 (user)
    @adobe/aio-cli-plugin-aep 1.0.5 (user)
    @adobe/aio-cli-plugin-app 4.0.2 (core)
    @adobe/aio-cli-plugin-asset-compute 1.4.3 (user)
    @adobe/aio-cli-plugin-auth 2.4.0 (core)
    @adobe/aio-cli-plugin-certificate 0.2.0 (core)
    @adobe/aio-cli-plugin-cloudmanager 0.14.0 (user)
    @adobe/aio-cli-plugin-cna 0.2.1 (user)
    @adobe/aio-cli-plugin-config 2.3.0 (core)
    @adobe/aio-cli-plugin-console 3.2.0 (core)
    @adobe/aio-cli-plugin-events 1.1.0 (core)
    @adobe/aio-cli-plugin-info 1.1.1 (core)
    @adobe/aio-cli-plugin-runtime 2.0.0 (core)
    @oclif/plugin-autocomplete 0.2.0 (core)
    @oclif/plugin-not-found 1.2.4 (core)
    @oclif/plugin-plugins 1.9.0 (core)
    @oclif/plugin-warn-if-update-available 1.7.0 (core)

Sample Code that illustrates the problem

See my github repo: https://github.com/marcinczeczko/aio-cli-test-worker-reproducer

Logs taken while reproducing problem

See above.

`util.prepareInOutDir()` should precreate `out/errors` to support optional extra files created by ShellScriptWorker

Expected Behaviour

When testing a shellscript worker, it may be necessary to check for the presence or content of the out/errors/error.json and out/errors/type.txt output files defined by the ShellScriptWorker.prepareMetadata() function. A test script should have the ability to open these files for reading, in the same way that the out/rendition0.png file can be read.

Actual Behaviour

However, when running npm test in a CI environment under a different user than the docker daemon, the asset-compute plugin fails to ensure that the out/errors directory is pre-created with the execute bit allowed for everyone, which makes it possible for the docker user to create it with a more restrictive umask, leading to a situation like this:

$ sudo ls -laF /home/circleci/repo/.nui/2022_04_21T17_51_03_056Z/out
total 208
drwxrwxrwx 3 circleci       circleci         4096 Apr 21 17:51 ./
drwxrwxr-x 6 circleci       circleci         4096 Apr 21 17:51 ../
drwxrw-rw- 2 circleci-admin circleci-admin   4096 Apr 21 17:51 errors/
-rwxrw-rw- 1 circleci-admin circleci-admin 198804 Apr 21 17:51 rendition0.ai*

In the above example, even though the errors/ directory and its children are readable by everyone, the lack of the execute bit makes it impossible for the circleci user to open the directory to read the contents of those nested files.

Reproduce Scenario (including but not limited to)

  1. Set up a circleci pipeline using the default machine (linux) runner, where the docker agent is running as circleci-admin and the shell is running as circleci.
  2. Run npm test on a shellscript worker project where worker.sh writes content to either $errorfile or $typefile, for example:
mkdir -p "$(dirname "$typefile")"
echo "image/png" > "$typefile"
  1. Attempt to read the contents of the out/errors/type.txt file in the validate script
expect_typefile="$(dirname "${BASH_SOURCE[0]}")/type.txt"
typefile="$(dirname "$2")/errors/type.txt"
cmp -s "${expect_typefile}" "${typefile}"
  1. Confirm

Platform and Version

  • CircleCI Machine Linux Medium
  • @adobe/aio-cli-plugin-asset-compute 1.5.0

Links

Installing plugin @adobe/aio-cli-plugin-asset-compute... failed

I have latest version of node, it failed when I execute the aio commad.

warning @adobe/aio-cli-plugin-asset-compute > @adobe/asset-compute-devtool > [email protected]: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
warning @adobe/aio-cli-plugin-asset-compute > @adobe/asset-compute-devtool > express-formidable > [email protected]: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
error @adobe/[email protected]: The engine "node" is incompatible with this module. Expected version "^10 || ^12 || ^14". Got "17.2.0"
error Found incompatible module.
Installing plugin @adobe/aio-cli-plugin-asset-compute... failed
Error: yarn add @adobe/aio-cli-plugin-asset-compute@latest
--non-interactive
--mutex=file:/Users/mohammedahmed/.local/share/@adobe/aio-cli/yarn.lock
--preferred-cache-folder=/Users/mohammedahmed/Library/Caches/@adobe/aio-cl
i/yarn --check-files exited with code 1

init hook breaks contracts

There is hacky code in the published init hook which modifies oclif's internal config plugin list.
Plugins should interact with the system through the apis of the system and not go and modify things, especially with hooks as they run for every command, not just asset-compute commands.

This is similar to previous practices where JS libraries would rewrite prototypes for other objects.

devDependency cannot be updated

There is a devDep on {"@adobe/aio-cli-plugin-app": "^8.0.0"} however the current version is 9.2.0

I tried updating this, but immediately broke all the tests.

The way this is used it appears it could actually be a peer dependency. I think this need to be thought out and re-architected to work with published apis.

Calls to @adobe/aio-cli-plugin-app/src/commands/app/deploy are bound to break at any time, without even a major version bump, this is internal to the aio-cli-plugin-app and should not be directly depended on.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.