81.0.0 • Published 2 years ago

@openstax/bakery-cli v81.0.0

Weekly downloads
153
License
-
Repository
-
Last release
2 years ago

Bakery Concourse Pipeline Config Generator and Bakery CLI

This directory contains the code necessary to both generate and run our content distribution and cops pipelines, either in individual steps or as a whole. Effort has been put in to paramaterize code pieces so that:

  • A downstream user (user of the Bakery CLI)
  • A developer making pipeline changes or debugging
  • A production or staging node
  • A CI node running tests

will all be reusing the same code, give or take some configuration.

Bakery CLI

Dependencies

To use the CLI, you must have all of the following already installed:

  • docker
  • docker-compose
  • node >= 12.16.1
  • npm

getting the above software installed is outside the scope of this documentation.

Installation

For installation inside the output-producer-service directory:

A simple npm install

To install the npm package:

npm -g i @openstax/bakery-cli

Usage

For now, when inside /bakery the file src/cli/execute.js is the entry point for the CLI, and must be called as an argument to node e.g. node ./src/cli/execute.js. Calling it without arguments will yield a help message. Each task in the pipeline should have a corresponding subcommand in this CLI so that one may run it individually and locally.

For example, to fetch a book and have its contents appear in the directory /tmp/data, one could use the following command, with bakery as their working directory:

node ./src/cli/execute.js run fetch -d /tmp/data staging.cnx.org col30149 latest

When using the npm package, bakery is the entry point for the CLI. Calling it without arguments will yield a help message. Calling bakery run will yeild all possible subcommands in this CLI.

For example, to fetch a book and have its contents appear in the directory /data/prealgebra-2e, one could use the following command:

bakery run fetch katalyst01.cnx.org col30939 latest -d ./data/prealgebra-2e

To assemble the book:

bakery run assemble col30939 -d ./data/prealgebra-2e

To link extras:

bakery run link-extras col30939 archive.cnx.org -d ./data/prealgebra-2e

To bake the book:

bakery run bake col30939 {path-to-recipe} {path-to-style} -d ./data/prealgebra-2e/

To mathify the book:

bakery run mathify col30939 -d ./data/prealgebra-2e/

To build the PDF:

bakery run build-pdf col30939 -d ./data/prealgebra-2e/

New Git-Storage Compatible Tasks

Git-storage compatible tasks are not ready for use outside of the CE Tech yet. The following graph represents the (almost) current state of git-storage compatible tasks. Intermediate states are shown in blue, tasks in yellow. This graph is created with yED and the source file for it is located here.

Flow for git-storage compatible pipelines

Bakery Concourse Pipeline Config Generator

Dependencies

  • node >= 12.16.1
  • npm

Setup

A simple npm install

Usage

build is an executable that provides a small cli to build your concourse pipeline/task files. This is the help message returned by calling it with ./build --help:

./build <command>

Commands:
  build.js pipeline <pipelinetype> [options] <env> [options]...  builds a bakery pipeline runnable with fly command
  [aliases: p]
  build.js task <taskname> [options]...  builds a bakery pipeline task runnable with fly execute                    [aliases: t]

Options:
  --help  Show help                                                                                  [boolean]

In general, for both the pipeline and task commands, the --help messages are fairly useful and complete. That is:

./build pipeline --help

and

./build task --help

will provide information about the command, defaults, and its positional and nonpositional arguments.

Generate a pipeline file for a particular environment

Run ./build pipeline <pipelinetype> [options] <env> [options]...

The choices for <pipelinetype> are the basenames of the .js files in the src/pipelines/ directory.

The choices for <env> are the basenames of the .json files in the env/ directory.

Examples:

  • ./build pipeline distribution prod -> Build the distribution pipeline with prod environment variables and output on stdout.
  • ./build pipeline cops staging -o cops-pipeline.staging.yml -> Build the cops pipeline with staging environment variables and output to file cops-pipeline.staging.yml, overwriting the file if it exists.

Generate a standalone task file suitable for fly execute

Run ./build task <taskname> [options]...

The choices for <taskname> are the basenames of the .js files in the src/tasks/ directory.

Example:

  • ./build task look-up-book -a "{bucketName: my-bucket}" -> Build the look-up-book task, injecting the object {bucketName: "my-bucket"} as the argument to the task function, and output the result to stdout
  • ./build task fetch-book -o fetch-book-task.yml -> Build the fetch-book task, and output the result to the file fetch-book-task.yml

Note: The --args option (shorthand, -a) must be valid yaml (or json, since yaml is a superset).

I don't like generating intermediate files to run set-pipeline or execute!

Use process substitution! Example: fly -t dev sp -p bakery -c <(./build pipeline cops staging)

Development and QA

Tip for development

The Bakery CLI allows the user to specify an image_resource for concourse to run the task in instead of the default. This is especially useful for either developing locally on the cops-bakery-scripts or perhaps being able to use the checked out code to create an image rather than using the image on Docker Hub when running tests. There is some specific convention for how to do this sort of thing.

For example, if one wanted to make changes to cops-bakery-scripts and have those changes reflect in the CLI running locally, one would have to follow these steps: 1. Have src/scripts as your working directory 2. Make the desired change in the src/scripts/*.py file 3. Build the image with docker build . 4. Tag the build image as localhost:5000/openstax/cops-bakery/scripts:latest (the prefix of localhost:5000 is required, what you name and tag your image is up to you), for example, with docker tag $(docker image ls | awk 'NR==2 {print $3}') localhost:5000/openstax/cops-bakery-scripts:latest 5. Run the desired pipeline step with the CLI with the --image flag, e.g. node ./src/cli/execute.js run assemble-meta --image localhost:5000/openstax/cops-bakery-scripts:latest -d /tmp/data col30149

Note: This is probably most useful for the cops-bakery-scripts image, but you can technically use a local version of an image like nebuchadnezzar as well.

Tip for development, deployment, and QA

Both the Bakery CLI and the Pipeline Config Generator allow you to specify a tag of a remote image to use with the --tag. For example, if a tag, important-tag, has been released for each of our images, one can: 1. Generate a pipeline pinning all versions of images to that tag with usage like ./build pipeline cops staging --tag=important-tag 2. Run an individual task with the Bakery CLI using the image of that tag as the image_resource with usage like node ./src/cli/execute.js run fetch -d /tmp/data staging.cnx.org col30149 latest --tag=important-tag

Testing

npm run lint will lint the JS files in bakery and npm run test will run regression tests on bakery via the CLI.

There are basic tests for the Python scripts used in some of the bakery tasks in bakery/src/tests which can be run as follows:

pip install bakery/src/scripts/.[test]
pytest bakery
79.0.0

2 years ago

78.0.0

2 years ago

80.0.0

2 years ago

81.0.0

2 years ago

77.0.0

2 years ago

76.0.0

2 years ago

75.0.0

3 years ago

74.0.0

3 years ago

73.0.0

3 years ago

72.0.0

3 years ago

71.0.0

3 years ago

70.0.0

3 years ago

69.0.0

3 years ago

68.0.0

3 years ago

66.0.0

3 years ago

67.0.0

3 years ago

65.0.0

3 years ago

64.0.0

3 years ago

63.0.0

3 years ago

62.0.0

3 years ago

60.0.0

3 years ago

61.0.0

3 years ago

59.0.0

3 years ago

58.0.0

3 years ago

49.0.0

3 years ago

53.0.0

3 years ago

48.0.0

3 years ago

52.0.0

3 years ago

56.0.0

3 years ago

55.0.0

3 years ago

54.0.0

3 years ago

50.0.0

3 years ago

57.0.0

3 years ago

51.0.0

3 years ago

47.0.0

3 years ago

46.0.0

3 years ago

45.0.0

3 years ago

44.0.0

3 years ago

43.0.0

3 years ago

42.0.0

3 years ago

41.0.0

3 years ago

40.0.0

3 years ago

39.0.0

3 years ago

38.0.0

3 years ago

37.0.0

3 years ago

36.0.0

3 years ago

35.0.0

3 years ago

34.0.0

3 years ago

32.0.0

3 years ago

33.0.0

3 years ago

31.0.0

3 years ago

30.0.0

3 years ago

29.0.0

3 years ago

28.0.0

3 years ago

26.0.0

3 years ago

27.0.0

3 years ago

25.0.0

3 years ago

24.0.0

3 years ago

23.0.0

3 years ago

22.0.0

3 years ago

21.0.0

3 years ago

20.0.0

3 years ago

19.0.0

3 years ago

18.0.0

3 years ago

17.0.0

3 years ago

15.0.0

3 years ago

14.0.0

3 years ago

13.0.0

3 years ago

12.0.0

3 years ago

16.0.0

3 years ago

10.0.0

3 years ago

11.0.0

3 years ago

9.0.0

3 years ago

8.0.0

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.0.0

3 years ago

3.0.0

3 years ago

4.0.0

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago