Files
releases/docs/DEVELOPMENT.md
T
Torin Sandall 157e4f083a Add references to the grammar
The special iterator variable ("_") is not supported yet. The _ variable will
be handled by mangling the variable name while parsing the rules (which are
still to come).

Also refactored terms to use type declaration and type switches. All terms are
now represented by underlying Go types without relying on extra structs. The
Kind attribute on Term has been removed in favour of type switches.

Lastly, removing the generated parser from the repository for now. Once the
grammar has stabilized, we can add the generated code back. The diffs were
unpleasant.
2016-04-02 12:03:31 -07:00

3.5 KiB

Development

Environment

OPA is written in the Go programming language.

If you are not familiar with Go we recommend you read through the How to Write Go Code article to familiarize yourself with the standard Go development environment.

Requirements:

  • Git
  • GitHub account (if you are contributing)
  • Go (version 1.5.x and 1.6.x are supported)
  • GNU Make

Getting Started

After cloning the repository, run make deps to install the parser generator ("pigeon") into your workspace.

Next, run make all to build the project and execute all of the tests. If this succeeds, there should be a new binary in the top level directory ("opa").

Verify the build was successful by running opa version.

You can re-build the project with make build and execute all of the tests with make test.

Workflow

  1. Go to https://github.com/open-policy-agent/opa and fork the repository into your account by clicking the "Fork" button.

  2. Clone the fork to your local machine.

    cd $GOPATH
    mkdir -p src/github.com/open-policy-agent
    cd src/github.com/open-policy-agent
    git clone git@github.com/<GITHUB USERNAME>/opa.git opa
    cd opa
    git remote add upstream https://github.com/open-policy-agent/opa.git
    
  3. Create a branch for your changes.

    git checkout -b somefeature
    
  4. Update your local branch with upstream.

    git fetch upstream
    git rebase upstream/master
    
  5. Develop your changes and regularly update your local branch against upstream.

    • Make sure you run go fmt on your code before submitting a Pull Request.
  6. Commit changes and push to your fork.

    git commit
    git push origin somefeature
    
  7. Submit a Pull Request via https://github.com/<GITHUB USERNAME>/opa. You should be prompted to with a "Compare and Pull Request" button that mentions your branch.

  8. Once your Pull Request has been reviewed and signed off please squash your commits. If you have a specific reason to leave multiple commits in the Pull Request, please mention it in the discussion.

    If you are not familiar with squashing commits, see the following blog post for a good overview.

Dependencies

Glide is a command line tool used for dependency management. You must have Glide installed in order to add new dependencies or update existing dependencies. If you are not changing dependencies you do not have to install Glide, all of the dependencies are contained in the vendor directory.

If you need to add a dependency to the project:

  1. Run glide get <package> to download the package.
    • This command should be used instead of go get <package>.
    • The package will be stored under the vendor directory.
    • The glide.yaml file will be updated.
  2. Manually remove the VCS directories (e.g., .git, .hg, etc.) from the new vendor directories.
  3. Commit the changes in glide.yaml, glide.lock, and new vendor directories.

If you need to update the dependencies:

  1. Run glide update --update-vendored.
  2. Commit the changes to the glide.lock file and any files under the vendor directory.

Opalog

If you need to modify the Opalog syntax you must update opalog/opalog.peg. Both make build and make test will re-generate the parser but if you want to test the parser generation explicitly you can run make generate.