/services

Intra-Git repository promotions for GitOps.

Primary LanguageGoApache License 2.0Apache-2.0

services Build Status Docker Repository on Quay

A tool for promoting between GitHub repositories.

This is a pre-alpha PoC for promoting versions of files between environments, represented as repositories.

Building

You need Go version 1.14 to build this project.

$ go build ./cmd/services

Running

You'll need a GitHub token to test this out.

$ export GITHUB_TOKEN=<paste in GitHub access token>
$ ./services promote --from https://github.com/organisation/first-environment.git --to https://github.com/organisation/second-environment.git --service service-a --commit-name <User to commit as> --commit-email <Email to commit as>

If the commit-name and commit-email are not provided, it will attempt to find them in ~/.gitconfig, otherwise it will fail.

This will copy all files under /services/service-a/base/config/* in first-environment to second-environment, commit and push, and open a PR for the change.

Testing

$ go test ./...

To run the complete integration tests, including pushing to the Git repository:

$ TEST_GITHUB_TOKEN=<a valid github auth token> go test ./...

Note that the tests in pkg/git/repository_test.go will clone and manipulate a remote Git repository locally.

To run a particular test: for example,

go test ./pkg/git -run TestCopyServiceWithFailureCopying

Getting started

This section is temporary. To create a sample promotion Pull Request, until rhd-gitops-example#8 is done:

./services promote --from [url.to.dev] --to [url.to.staging] --service service-a`

At a high level the services command currently:

  • git clones the source and target repositories into ~/.promotion/cache
  • creates a branch (as per the given --branch-name)
  • checks out the branch
  • copies the relevant files from the cloned source into the cloned target
  • pushes the cloned target
  • creates a PR from the new branch in the target to master in the target

Important notes:

  • We need to remove the local cache between requests. See rhd-gitops-example#20. Until then, add rm -rf ~/.promotion/cache; before subsequent requests.
  • New pull requests need new branches (i.e you cannot run the same command twice). Add --branch [unique branch name] before submitting further promotion PRs. See rhd-gitops-example#21.
  • See rhd-gitops-example#19 for an issue related to problems 'promoting' config from a source repo into a gitops repo.

Release process

When a new tag is pushed with the v prefix, a GitHub release will be created with binaries produced for 64-bit Linux, and Mac automatically.