Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ogma-cli: Allow customizing the standalone application template. Refs #189. #191

Merged

Conversation

ivanperez-keera
Copy link
Member

@ivanperez-keera ivanperez-keera commented Dec 24, 2024

Adjust ogma-cli and ogma-core to allow customizing the standalone Copilot monitoring application by using custom-provided templates, as prescribed in the solution proposed for #189.

Unlike in the solution proposed for #189, the README is not modified to explain how to use this feature, since there is no section in the current README explaining how the standalone command works.

@ivanperez-keera ivanperez-keera force-pushed the develop-standalone-templates branch from 47a477c to 7748292 Compare December 24, 2024 06:06
@ivanperez-keera
Copy link
Member Author

Change Manager: The comments of the standalone and standalone' functions are no longer correct, since the function no longer prints. Instead, it generates a standalone Copilot monitor.

…pplication. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

This commit modifies the ogma-core standalone command to use mustache to
generate the Copilot monitor via a template and variable expansion. We
introduce a new template that uses variables, and we modify the cabal
file to include the files that make up the default template as data
files that are copied over during installation.

To be able to generate the files, we need to introduce a target
directory option for the standalone command.
…mand. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

A prior commit introduced, in the standalone command, support for custom
templates. Unlike the prior implementation of the standalone command,
which printed the output to standard output, the new interface puts the
result in a file (or several files) included with the template.  To
implement this new functionality, we have added an argument to specify a
target directory for the generated standalone application,
where the files will be copied to.

This commit modifies the tests for the standalone command to provide a
temporary directory as destination. We default to the temporary
directory of the host system. Since this is only used for testing and
not during normal operation, and the ogma implementation is open source,
we consider this safe from a security standpoint.
…ory. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

A prior commit introduced, in the standalone command, support for custom
templates. Unlike the prior implementation of the standalone command,
which printed the output to standard output, the new interface puts the
result in a file (or several files) included with the template.  To
implement this new functionality, we have added an argument to specify a
target directory for the generated standalone application, where the
files will be copied to.

This commit exposes that new parameter to set the target directory to
the user in the CLI.
…d. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

A prior commit introduced, in the standalone command, the ability to use
mustache to expand variables in a template.

This commit modifies the standalone command to accept an additional
argument that points to a user-provided directory with a custom
template.
…ommand. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), or not using ogma altogether for that reason.

A prior commit introduced, in the standalone command, support for custom
templates and, with it, the ability to pass a custom directory
containing a standalone application template.

This commit modifies the tests for the standalone command to provide no
custom template directory, to use the default included with Ogma.
…plate source directory. Refs nasa#189.

The standalone backend uses a fixed template to generate the Copilot
monitor. That template does not fit all use cases, so we are finding
users heavily modifying the output (which is hard to keep up with when
there are changes), and or not using ogma altogether for that reason.

A recent commit introduced into ogma-core the ability to use a custom
template and expand variables using mustache.

This commit exposes that new parameter to the user in the CLI.
@ivanperez-keera ivanperez-keera force-pushed the develop-standalone-templates branch from 7748292 to 9c76554 Compare December 24, 2024 15:12
@ivanperez-keera
Copy link
Member Author

Implementor: Fix implemented, review requested.

@ivanperez-keera
Copy link
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
    • The solution proposed produces the expected result. Details:
      The following dockerfile generates a standalone Copilot monitor using the default template and using a copy and the default template and checks that both are the same. It then adds a file to the copy of the template and checks that the file is copied to the target directory when the custom template is used, after which it prints the message "Success". Compiling the produced component completes successfully:
      FROM ubuntu:trusty
      
      ENV DEBIAN_FRONTEND=noninteractive
      
      RUN apt-get update
      
      RUN apt-get install --yes software-properties-common
      RUN add-apt-repository ppa:hvr/ghc
      RUN apt-get update
      
      RUN apt-get install --yes ghc-8.6.5 cabal-install-2.4
      RUN apt-get install --yes libz-dev
      
      ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:$PWD/.cabal-sandbox/bin:$PATH
      
      RUN cabal update
      RUN cabal v1-sandbox init
      RUN cabal v1-install alex happy
      RUN apt-get install --yes git
      
      CMD git clone $REPO \
          && cd $NAME \
          && git checkout $COMMIT \
          && cd .. \
          && cp -r $NAME/ogma-core/templates/standalone custom-template-standalone \
          && cabal v1-sandbox init \
          && cabal v1-install $NAME/$PAT**/ copilot-4.1 --constraint="aeson>=2.0.3.0" \
          && ./.cabal-sandbox/bin/ogma standalone --file-name $NAME/ogma-cli/examples/fret.json --input-format fcs --target-dir orig \
          && ./.cabal-sandbox/bin/ogma standalone --file-name $NAME/ogma-cli/examples/fret.json --input-format fcs --target-dir new --template-dir custom-template-standalone \
          && diff -rq orig new \
          && rm -rf new/ \
          && echo "Success" >> custom-template-standalone/README \
          && ./.cabal-sandbox/bin/ogma standalone --file-name $NAME/ogma-cli/examples/fret.json --input-format fcs --target-dir new --template-dir custom-template-standalone \
          && cabal v1-exec -- runhaskell -XPartialTypeSignatures -Wno-partial-type-signatures new/Copilot.hs \
          && cat new/README
      
      Command (substitute variables based on new path after merge):
      $ docker run -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "PAT=ogma"  -e "COMMIT=9c76554ab695e98ed05a01caad099f0347519358" -it ogma-verify-189
      
  • Implementation is documented. Details:
    The new code has comments. Changes to old code had their comments adapted.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed.
  • Required version bumps are evaluated. Details:
    No bump needed. New feature is backwards compatible.

@ivanperez-keera ivanperez-keera merged commit 5c41152 into nasa:develop Dec 24, 2024
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-standalone-templates branch December 24, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant