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

Updates to infrastructure and some documentation on process #18

Merged
merged 1 commit into from
Mar 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.vscode
opa
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go

install: ./install-deps-gen-code.sh

go:
- 1.5
- 1.6
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Change Log

All notable changes to this project will be documented in this file. This
project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2015 The OPA Authors. All rights reserved.
# Use of this source code is governed by an Apache2
# license that can be found in the LICENSE file.

PACKAGES := github.com/open-policy-agent/opa/jsonlog/.../ \
github.com/open-policy-agent/opa/cmd/.../

BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh)
BUILD_HOSTNAME := $(shell ./build/get-build-hostname.sh)

LDFLAGS := -ldflags "-X github.com/open-policy-agent/opa/version.Vcs=$(BUILD_COMMIT) \
-X github.com/open-policy-agent/opa/version.Timestamp=$(BUILD_TIMESTAMP) \
-X github.com/open-policy-agent/opa/version.Hostname=$(BUILD_HOSTNAME)"

GO := go

GO15VENDOREXPERIMENT := 1
export GO15VENDOREXPERIMENT

.PHONY: all generate build test clean

all: build test

generate:
$(GO) generate

build:
$(GO) build -o opa $(LDFLAGS)

test:
$(GO) test -v $(PACKAGES)

clean:
rm -f ./opa
9 changes: 9 additions & 0 deletions build/get-build-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

GIT_SHA=$(git rev-parse --short HEAD)

if [ -z "$(git status --porcelain 2>/dev/null)" ]; then
echo $GIT_SHA
else
echo "$GIT_SHA-dirty"
fi
3 changes: 3 additions & 0 deletions build/get-build-hostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

hostname -f
3 changes: 3 additions & 0 deletions build/get-build-timestamp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

date -u +"%Y-%m-%dT%H:%M:%SZ"
15 changes: 15 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package cmd

import "github.com/spf13/cobra"
import "path"
import "os"

var RootCommand = &cobra.Command{
Use: path.Base(os.Args[0]),
Short: "Open Policy Agent (OPA)",
Long: "An open source project to policy enable any application.",
}
25 changes: 25 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2016 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package cmd

import "fmt"
import "github.com/spf13/cobra"
import "github.com/open-policy-agent/opa/version"

var versionCommand = &cobra.Command{
Use: "version",
Short: "Print the version of OPA",
Long: "Show version and build information for OPA.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Version: " + version.Version)
fmt.Println("Build Commit: " + version.Vcs)
fmt.Println("Build Timestamp: " + version.Timestamp)
fmt.Println("Build Hostname: " + version.Hostname)
},
}

func init() {
RootCommand.AddCommand(versionCommand)
}
112 changes: 112 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Development

## Environment

OPA is written in the [Go](https://golang.org) programming language.

If you are not familiar with Go we recommend you read through the [How to Write Go
Code](https://golang.org/doc/code.html) 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, you can run `make all` to build the project and
execute all of the tests. If this succeeds, there should be a binary
in the top 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](https://github.com/open-policy-agent/opa) and fork the repository
into your account by clicking the "Fork" button.

1. 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
```

1. Create a branch for your changes.

```
git checkout -b somefeature
```

1. Update your local branch with upstream.

```
git fetch upstream
git rebase upstream/master
```

1. 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.

1. Commit changes and push to your fork.

```
git commit
git push origin somefeature
```

1. 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.

1. 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](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html).

## Dependencies

[Glide](https://github.com/Masterminds/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.
1. Manually remove the VCS directories (e.g., .git, .hg, etc.) from the new
vendor directories.
1. 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`.
1. 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 jsonlog/parser.peg
and run `make generate` to re-generate the parser code.

> If you encounter an error because "pigeon" is not installed, run `glide
> rebuild` to build and install the vendored dependencies (which include the
> parser generator). Note, you will need to have [Glide](https://github.com/Masterminds/glide)
> installed for this.

Commit the changes to the parser.peg and parser.go files.
80 changes: 80 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Release Process

## Overview

The release process consists of three phases: versioning, building, and
publishing.

Versioning involves maintaining the CHANGELOG.md and version.go files inside
the repository and tagging the repository to identify specific releases.

Building involves obtaining a copy of the repository, checking out the release
tag, and building the packages.

Publishing involves creating a new *Release* on GitHub with the relevant
CHANGELOG.md snippet and uploading the packages from the build phase.

## Versioning

1. Obtain copy of remote repository.

```
git clone git@github.com/open-policy-agent/opa.git
```

1. Edit CHANGELOG.md to update the Unreleased header (e.g., s/Unreleased/0.12.8/) and add any missing items to prepare for release.

1. Edit version/version.go to set Version variable to prepare for release (e.g., s/Version = “0.12.8-dev”/Version = "0.12.8”/).

1. Commit the changes and push to remote repository.

```
git commit -a -m “Prepare v<version> release”
git push origin master
```

1. Tag repository with release version and push tags to remote repository.

```
git tag v<semver>
git push origin --tags
```

1. Edit CHANGELOG.md to add back the Unreleased header to prepare for development.

1. Edit version/version.go to set Version variable to prepare for development (e.g., s/Version = “0.12.8”/Version = “0.12.9-dev”/).

1. Commit the changes and push to remote repository.

```
git commit -a -m “Prepare v<next_semvar> development”
git push origin master
```

## Building

1. Obtain copy of remote repository.

```
git clone git@github.com/open-policy-agent/opa.git
```

1. Checkout release tag.

```
git checkout v<semver>
```

1. Run command to build packages. This will produce a bunch of binaries (e.g., amd64/linux, i386/linux, amd64/darwin, etc.) that can be published (“distributions”).

```
make dist
```

## Publishing

1. Open browser and go to https://github.com/open-policy-agent/opa/releases

1. Create a new release for the version.
- Copy the changelog content into the message.
- Upload the distributions packages.
77 changes: 77 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package: github.com/open-policy-agent/opa
import:
- package: github.com/PuerkitoBio/pigeon
- package: golang.org/x/tools
subpackages:
- cmd/goimports
- package: github.com/spf13/cobra
Loading