From 8dd1d6cf466a1d2df5d01df336d1215cb65413c7 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 14:17:31 -0700 Subject: [PATCH 01/23] Adding ci for atlantis --- Makefile | 4 +- README.md | 2 + circle.yml | 32 ++++ e2e/.gitconfig | 3 + e2e/.gitignore | 1 + e2e/Makefile | 25 +++ e2e/e2e.go | 189 +++++++++++++++++++++ e2e/github.go | 13 ++ e2e/main.go | 161 ++++++++++++++++++ e2e/secrets-envs | Bin 0 -> 320 bytes e2e/standalone-with-env/atlantis.yaml | 2 + e2e/standalone-with-env/env/staging.tfvars | 0 e2e/standalone-with-env/main.tf | 3 + e2e/standalone/atlantis.yaml | 2 + e2e/standalone/main.tf | 3 + scripts/build.sh | 13 ++ scripts/e2e-deps.sh | 20 +++ scripts/e2e.sh | 24 +++ server/server.go | 34 ++++ 19 files changed, 529 insertions(+), 2 deletions(-) create mode 100644 circle.yml create mode 100644 e2e/.gitconfig create mode 100644 e2e/.gitignore create mode 100644 e2e/Makefile create mode 100644 e2e/e2e.go create mode 100644 e2e/github.go create mode 100644 e2e/main.go create mode 100644 e2e/secrets-envs create mode 100644 e2e/standalone-with-env/atlantis.yaml create mode 100644 e2e/standalone-with-env/env/staging.tfvars create mode 100644 e2e/standalone-with-env/main.tf create mode 100644 e2e/standalone/atlantis.yaml create mode 100644 e2e/standalone/main.tf create mode 100755 scripts/build.sh create mode 100755 scripts/e2e-deps.sh create mode 100755 scripts/e2e.sh diff --git a/Makefile b/Makefile index b273b4e63d..74003d9753 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,10 @@ deps-test: go get -t test: ## Run tests, coverage reports, and clean (coverage taints the compiled code) - go test -v . + go test -v ./... test-coverage: - go test -v -coverprofile=c.out + go test -v ./... -coverprofile=c.out go tool cover -html=c.out -o coverage.html dist: ## Package up everything in static/ using go-bindata-assetfs so it can be served by a single binary diff --git a/README.md b/README.md index 8f531afd99..9af9088bb5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # atlantis +[![CircleCI](https://circleci.com/gh/hootsuite/atlantis.svg?style=svg&circle-token=6a0c78c9b1fd77486c72a5e22512c7c9175f2aaf)](https://circleci.com/gh/hootsuite/atlantis) + A [terraform](https://www.terraform.io/) collaboration tool that enables you to collaborate on infrastructure safely and securely. ## Locking diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000..dbe1dfea0b --- /dev/null +++ b/circle.yml @@ -0,0 +1,32 @@ +machine: + # Environment variables for build + environment: + TERRAFORM_VERSION: 0.8.8 + +dependencies: + override: + # Install dependencies + - make deps + +test: + pre: + # Test dependencies + - make deps-test + + override: + # Run tests + - ./scripts/build.sh + + # Run e2e tests + post: + - ./scripts/e2e-deps.sh + # Start atlantis server + - ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: + background: true + - sleep 2 + - ./ngrok http 4141: + background: true + - sleep 2 + # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook + - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc + - ./scripts/e2e.sh diff --git a/e2e/.gitconfig b/e2e/.gitconfig new file mode 100644 index 0000000000..320325ead1 --- /dev/null +++ b/e2e/.gitconfig @@ -0,0 +1,3 @@ +[user] + name = Anubhav Mishra + email = anubhav.mishra@hootsuite.com diff --git a/e2e/.gitignore b/e2e/.gitignore new file mode 100644 index 0000000000..b38a38e4ac --- /dev/null +++ b/e2e/.gitignore @@ -0,0 +1 @@ +atlantis-tests diff --git a/e2e/Makefile b/e2e/Makefile new file mode 100644 index 0000000000..e9ab78f0b3 --- /dev/null +++ b/e2e/Makefile @@ -0,0 +1,25 @@ +WORKSPACE := $(shell pwd) + +.PHONY: test + +.DEFAULT_GOAL := help +help: ## List targets & descriptions + @cat Makefile* | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +debug: ## Output internal make variables + @echo WORKSPACE = $(WORKSPACE) + +deps: ## Get go dependencies + go get . + +build: ## Build the main Go service + go build -v -o atlantis-tests . + +deps-test: ## Run tests for go dependencies + go get -t + +test: ## Run tests, coverage reports, and clean (coverage taints the compiled code) + go test -v . + +run: ## Run e2e tests + ./atlantis-tests diff --git a/e2e/e2e.go b/e2e/e2e.go new file mode 100644 index 0000000000..4cb019c38b --- /dev/null +++ b/e2e/e2e.go @@ -0,0 +1,189 @@ +package main + +import ( + "errors" + "fmt" + "io/ioutil" + "log" + "os" + "os/exec" + "time" + + "github.com/google/go-github/github" +) + +type E2ETester struct { + githubClient *GithubClient + repoUrl string + ownerName string + repoName string + hookID int + cloneDirRoot string + projectType Project +} + +type E2EResult struct { + projectType string + githubPullRequestURL string + testResult string +} + +var testFileData = ` +resource "null_resource" "hello" { +} +` + +func (t *E2ETester) Start() (*E2EResult, error) { + cloneDir := fmt.Sprintf("%s/%s-test", t.cloneDirRoot, t.projectType.Name) + branchName := fmt.Sprintf("%s-%s", t.projectType.Name, time.Now().Format("20060102150405")) + testFileName := fmt.Sprintf("%s.tf", t.projectType.Name) + e2eResult := &E2EResult{} + e2eResult.projectType = t.projectType.Name + + // create the directory and parents if necessary + log.Printf("creating dir %q", cloneDir) + if err := os.MkdirAll(cloneDir, 0755); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to create dir %q prior to cloning, attempting to continue: %v", cloneDir, err)) + } + + cloneCmd := exec.Command("git", "clone", t.repoUrl, cloneDir) + // git clone the repo + log.Printf("git cloning into %q", cloneDir) + if output, err := cloneCmd.CombinedOutput(); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to clone repository: %v: %s", err, string(output))) + } + + // checkout a new branch for the project + log.Printf("checking out branch %q", branchName) + checkoutCmd := exec.Command("git", "checkout", "-b", branchName) + checkoutCmd.Dir = cloneDir + if err := checkoutCmd.Run(); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to git checkout branch %q: %v", branchName, err)) + } + + // write a file for running the tests + randomData := []byte(testFileData) + filePath := fmt.Sprintf("%s/%s/%s", cloneDir, t.projectType.Name, testFileName) + log.Printf("creating file to commit %q", filePath) + err := ioutil.WriteFile(filePath, randomData, 0644) + if err != nil { + return e2eResult, errors.New(fmt.Sprintf("couldn't write file %s: %v", filePath, err)) + } + + // add the file + log.Printf("git add file %q", filePath) + addCmd := exec.Command("git", "add", filePath) + addCmd.Dir = cloneDir + if err := addCmd.Run(); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to git add file %q: %v", filePath, err)) + } + + // commit the file + log.Printf("git commit file %q", filePath) + commitCmd := exec.Command("git", "commit", "-am", "test commit") + commitCmd.Dir = cloneDir + if output, err := commitCmd.CombinedOutput(); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to run git commit in %q: %v", cloneDir, err, string(output))) + } + + // push the branch to remote + log.Printf("git push branch %q", branchName) + pushCmd := exec.Command("git", "push", "origin", branchName) + pushCmd.Dir = cloneDir + if err := pushCmd.Run(); err != nil { + return e2eResult, errors.New(fmt.Sprintf("failed to git push branch %q: %v", branchName, err)) + } + + // create a new pr + title := fmt.Sprintf("This is a test pull request for atlantis e2e test for %s project type", t.projectType.Name) + head := fmt.Sprintf("%s:%s", t.githubClient.username, branchName) + body := "" + base := "master" + newPullRequest := &github.NewPullRequest{Title: &title, Head: &head, Body: &body, Base: &base} + + pull, _, err := t.githubClient.client.PullRequests.Create(t.githubClient.ctx, t.ownerName, t.repoName, newPullRequest) + if err != nil { + return e2eResult, errors.New(fmt.Sprintf("error while creating new pull request: %v", err)) + } + + // set pull request url + e2eResult.githubPullRequestURL = pull.GetHTMLURL() + + log.Printf("created pull request %s", pull.GetHTMLURL()) + + // defer closing pull request and delete remote branch + defer cleanUp(t, pull.GetNumber(), branchName) + + // create run plan comment + log.Printf("creating plan comment: %q", t.projectType.PlanCommand) + _, _, err = t.githubClient.client.Issues.CreateComment(t.githubClient.ctx, t.ownerName, t.repoName, pull.GetNumber(), &github.IssueComment{Body: github.String(t.projectType.PlanCommand)}) + if err != nil { + return e2eResult, errors.New(fmt.Sprintf("error creating 'run plan' comment on github")) + } + + // wait for atlantis to respond to webhook + time.Sleep(2 * time.Second) + + state := "not started" + // waiting for atlantis run and finish + for checkStatus(state) { + if state == "" { + log.Println("atlantis run hasn't started") + } + time.Sleep(2 * time.Second) + state, _ = getAtlantisStatus(t, branchName) + log.Printf("atlantis run is in %s state", state) + } + + log.Printf("atlantis run finished with %s status", state) + e2eResult.testResult = state + // check if atlantis run was a success + if state != "\"success\"" { + return e2eResult, errors.New(fmt.Sprintf("atlantis run project type %q failed with %s status", t.projectType.Name, state)) + } + + return e2eResult, nil +} + +func getAtlantisStatus(t *E2ETester, branchName string) (string, error) { + // check repo status + combinedStatus, _, err := t.githubClient.client.Repositories.GetCombinedStatus(t.githubClient.ctx, t.ownerName, t.repoName, branchName, nil) + if err != nil { + return "", err + } + + for _, status := range combinedStatus.Statuses { + if github.Stringify(status.Context) == "\"Atlantis\"" { + return github.Stringify(status.State), nil + } + } + + return "", nil +} + +func checkStatus(state string) bool { + for _, s := range []string{"\"success\"", "\"error\"", "\"failure\""} { + if state == s { + return false + } + } + return true +} + +func cleanUp(t *E2ETester, pullRequestNumber int, branchName string) error { + // clean up + pullClosed, _, err := t.githubClient.client.PullRequests.Edit(t.githubClient.ctx, t.ownerName, t.repoName, pullRequestNumber, &github.PullRequest{State: github.String("closed")}) + if err != nil { + return errors.New(fmt.Sprintf("error while closing new pull request: %v", err)) + } + log.Printf("closed pull request %d", pullClosed.GetNumber()) + + deleteBranchName := fmt.Sprintf("%s/%s", "heads", branchName) + _, err = t.githubClient.client.Git.DeleteRef(t.githubClient.ctx, t.ownerName, t.repoName, deleteBranchName) + if err != nil { + return errors.New(fmt.Sprintf("error while deleting branch %s: %v", deleteBranchName, err)) + } + log.Printf("deleted branch %s", deleteBranchName) + + return nil +} diff --git a/e2e/github.go b/e2e/github.go new file mode 100644 index 0000000000..67e87788f4 --- /dev/null +++ b/e2e/github.go @@ -0,0 +1,13 @@ +package main + +import ( + "context" + + "github.com/google/go-github/github" +) + +type GithubClient struct { + client *github.Client + ctx context.Context + username string +} diff --git a/e2e/main.go b/e2e/main.go new file mode 100644 index 0000000000..f1200032cd --- /dev/null +++ b/e2e/main.go @@ -0,0 +1,161 @@ +package main + +import ( + "context" + "log" + "os" + "strings" + + "fmt" + + "github.com/google/go-github/github" + "github.com/hashicorp/go-multierror" +) + +var defaultAtlantisURL = "http://localhost:4141/hooks" +var projectTypes = []Project{ + Project{"standalone", "run plan", "run apply"}, + Project{"standalone-with-env", "run plan staging", "run apply staging"}, +} + +type Project struct { + Name string + PlanCommand string + ApplyCommand string +} + +func main() { + + githubUsername := os.Getenv("GITHUB_USERNAME") + if githubUsername == "" { + log.Fatalf("GITHUB_USERNAME cannot be empty") + } + githubPassword := os.Getenv("GITHUB_PASSWORD") + if githubPassword == "" { + log.Fatalf("GITHUB_PASSWORD cannot be empty") + } + atlantisURL := os.Getenv("ATLANTIS_URL") + if atlantisURL == "" { + atlantisURL = defaultAtlantisURL + } + // add /hooks to the url + atlantisURL = fmt.Sprintf("%s/hooks", atlantisURL) + ownerName := os.Getenv("GITHUB_REPO_OWNER_NAME") + if ownerName == "" { + ownerName = "anubhavmishra" + } + repoName := os.Getenv("GITHUB_REPO_NAME") + if repoName == "" { + repoName = "atlantis-tests" + } + // using https to clone the repo + repoUrl := fmt.Sprintf("https://%s:%s@github.com/%s/%s.git", githubUsername, githubPassword, ownerName, repoName) + cloneDirRoot := os.Getenv("CLONE_DIR") + if cloneDirRoot == "" { + cloneDirRoot = "/tmp/atlantis-tests" + } + + // clean workspace + log.Printf("cleaning workspace %s", cloneDirRoot) + err := cleanDir(cloneDirRoot) + if err != nil { + log.Fatalf("failed to clean dir %q before cloning, attempting to continue: %v", cloneDirRoot, err) + } + + // create github client + tp := github.BasicAuthTransport{ + Username: strings.TrimSpace(githubUsername), + Password: strings.TrimSpace(githubPassword), + } + ghClient := github.NewClient(tp.Client()) + + githubClient := &GithubClient{client: ghClient, ctx: context.Background(), username: githubUsername} + + // we create atlantis hook once for the repo, since the atlantis server can handle multiple requests + log.Printf("creating atlantis webhook with %s url", atlantisURL) + hookID, err := createAtlantisWebhook(githubClient, ownerName, repoName, atlantisURL) + if err != nil { + log.Fatalf("error creating atlantis webhook: %v", err) + } + + // create e2e test + e2e := E2ETester{ + githubClient: githubClient, + repoUrl: repoUrl, + ownerName: ownerName, + repoName: repoName, + hookID: hookID, + cloneDirRoot: cloneDirRoot, + } + + // start e2e tests + results, err := startTests(e2e) + log.Printf("Test Results\n---------------------------\n") + for _, result := range results { + fmt.Printf("Project Type: %s \n", result.projectType) + fmt.Printf("Pull Request Link: %s \n", result.githubPullRequestURL) + fmt.Printf("Atlantis Run Status: %s \n", result.testResult) + fmt.Println("---------------------------") + } + if err != nil { + log.Fatalf(fmt.Sprintf("%s", err)) + } + +} + +func createAtlantisWebhook(g *GithubClient, ownerName string, repoName string, hookURL string) (int, error) { + // create atlantis hook + atlantisHook := &github.Hook{ + Name: github.String("web"), + Events: []string{"issue_comment", "pull_request", "push"}, + Config: map[string]interface{}{ + "url": hookURL, + "content_type": "json", + }, + Active: github.Bool(true), + } + + // moved to github.go + hook, _, err := g.client.Repositories.CreateHook(g.ctx, ownerName, repoName, atlantisHook) + if err != nil { + return 0, err + } + log.Println(hook.GetURL()) + + return hook.GetID(), nil +} + +func deleteAtlantisHook(g *GithubClient, ownerName string, repoName string, hookID int) error { + _, err := g.client.Repositories.DeleteHook(g.ctx, ownerName, repoName, hookID) + if err != nil { + return err + } + log.Printf("deleted webhook id %d", hookID) + + return nil +} + +func cleanDir(path string) error { + if err := os.RemoveAll(path); err != nil { + return err + } + return nil +} + +func startTests(e2e E2ETester) ([]*E2EResult, error) { + var testResults []*E2EResult + var testErrors *multierror.Error + // delete webhook when we are done running tests + defer deleteAtlantisHook(e2e.githubClient, e2e.ownerName, e2e.repoName, e2e.hookID) + + for _, projectType := range projectTypes { + log.Printf("starting e2e test for project type %q", projectType.Name) + e2e.projectType = projectType + // start e2e test + result, err := e2e.Start() + testResults = append(testResults, result) + testErrors = multierror.Append(testErrors, err) + } + + return testResults, testErrors.ErrorOrNil() +} diff --git a/e2e/secrets-envs b/e2e/secrets-envs new file mode 100644 index 0000000000000000000000000000000000000000..c58583e83e97f8354cdc9b0571bb673c46d23019 GIT binary patch literal 320 zcmV-G0l)rJVQh3|WM5zZX#vLxllQ18#}S19_NBR)aAbD#g*{jVk#hvtPeZI+X zOFd%`&A3ewb}4RpsWw`mntLr`)Oipa;B$O9=4PYlYv+GGoHySEN`{ zzL3%@fR3I%??*|U0tAJi!@$*)lPT>)&18(c_{y!_MbtzxsjR@@cS8$9g`xql)q#_| zlA}jpTrCEG74ID^fm`jzzgbTuN++0Pea3RFak}=Of*+sIo0CdCl~G@5;1r_%b!&Al z=?yWnMoM;pjl@bQo2`9nOzaPS2&@0-cM_Uj1|fNcKcpw_(t&*SgMUN-D>6GqN@x8p$%rMBS{uU~v35 SW5&Z?I`zwBd`KRtYg#snucr?H literal 0 HcmV?d00001 diff --git a/e2e/standalone-with-env/atlantis.yaml b/e2e/standalone-with-env/atlantis.yaml new file mode 100644 index 0000000000..1df19fe5d2 --- /dev/null +++ b/e2e/standalone-with-env/atlantis.yaml @@ -0,0 +1,2 @@ +--- +stash_path: "/hello/path" \ No newline at end of file diff --git a/e2e/standalone-with-env/env/staging.tfvars b/e2e/standalone-with-env/env/staging.tfvars new file mode 100644 index 0000000000..e69de29bb2 diff --git a/e2e/standalone-with-env/main.tf b/e2e/standalone-with-env/main.tf new file mode 100644 index 0000000000..d59a273088 --- /dev/null +++ b/e2e/standalone-with-env/main.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-east-1" +} diff --git a/e2e/standalone/atlantis.yaml b/e2e/standalone/atlantis.yaml new file mode 100644 index 0000000000..1df19fe5d2 --- /dev/null +++ b/e2e/standalone/atlantis.yaml @@ -0,0 +1,2 @@ +--- +stash_path: "/hello/path" \ No newline at end of file diff --git a/e2e/standalone/main.tf b/e2e/standalone/main.tf new file mode 100644 index 0000000000..e22b634ef1 --- /dev/null +++ b/e2e/standalone/main.tf @@ -0,0 +1,3 @@ +provider "aws" { + region = "us-east-1" +} \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000000..20d8d452e5 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +run_unit_test() { + echo "Running unit tests: 'make test'" + make test +} + +# Run unit tests +run_unit_test + +# Build packages to make sure they can be compiled +echo "Running 'make build'" +make build-service diff --git a/scripts/e2e-deps.sh b/scripts/e2e-deps.sh new file mode 100755 index 0000000000..989eadd863 --- /dev/null +++ b/scripts/e2e-deps.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +echo "Preparing to run e2e tests" +mv atlantis e2e/ + +# cd into e2e folder +cd e2e/ +# Encrypting secrets for atlantis runtime: https://github.com/circleci/encrypted-files +openssl aes-256-cbc -d -in secrets-envs -k $KEY >> ~/.circlerc +# Download terraform +curl -LOk https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip +unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /home/ubuntu/bin +# Download ngrok to create a tunnel to expose atlantis server +wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip +unzip ngrok-stable-linux-amd64.zip +chmod +x ngrok +wget https://stedolan.github.io/jq/download/linux64/jq +chmod +x jq +# Copy github config file - replace with circleci user later +cp .gitconfig ~/.gitconfig \ No newline at end of file diff --git a/scripts/e2e.sh b/scripts/e2e.sh new file mode 100755 index 0000000000..3653834c47 --- /dev/null +++ b/scripts/e2e.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail +IFS=$'\n\t' + +# Download dependencies +echo "Running 'make deps'" +make deps + +# Test dependencies +echo "Running 'make deps-test'" +make deps-test + +# Run tests +echo "Running 'make test'" +make test + +# Build packages to make sure they can be compiled +echo "Running 'make build'" +make build + +# Run e2e tests +echo "Running e2e test: 'make run'" +make run diff --git a/server/server.go b/server/server.go index dddad0869e..bbde32e7ea 100644 --- a/server/server.go +++ b/server/server.go @@ -10,6 +10,11 @@ import ( "os" "strings" +<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 +======= + "io/ioutil" + +>>>>>>> Adding ci for atlantis "github.com/elazarl/go-bindata-assetfs" "github.com/google/go-github/github" "github.com/gorilla/mux" @@ -18,14 +23,20 @@ import ( "github.com/hootsuite/atlantis/locking/dynamodb" "github.com/hootsuite/atlantis/logging" "github.com/hootsuite/atlantis/middleware" +<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 "github.com/hootsuite/atlantis/models" +======= +>>>>>>> Adding ci for atlantis "github.com/hootsuite/atlantis/recovery" "github.com/pkg/errors" "github.com/urfave/cli" "github.com/urfave/negroni" +<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 "io/ioutil" "path/filepath" "time" +======= +>>>>>>> Adding ci for atlantis ) const ( @@ -72,6 +83,7 @@ type ServerConfig struct { LockingDynamoDBTable string `mapstructure:"locking-dynamodb-table"` } +<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 // todo: rename to Command type CommandContext struct { Repo models.Repo @@ -117,6 +129,24 @@ type GeneralError struct { func (g GeneralError) Template() *CompiledTemplate { return GeneralErrorTmpl +======= +type ExecutionContext struct { + repoFullName string + pullNum int + requesterUsername string + requesterEmail string + comment string + repoSSHUrl string + head string + // commit base sha + base string + pullLink string + branch string + htmlUrl string + pullCreator string + command *Command + log *logging.SimpleLogger +>>>>>>> Adding ci for atlantis } func NewServer(config ServerConfig) (*Server, error) { @@ -313,6 +343,10 @@ func (s *Server) handlePullClosedEvent(w http.ResponseWriter, pullEvent github.P fmt.Fprintf(w, "Error unlocking locks: %v\n", err) return } +<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 +======= + +>>>>>>> Adding ci for atlantis fmt.Fprintln(w, "Locks unlocked") } From 0522d4663c645901e6783f269388260fd7c5da98 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 14:24:11 -0700 Subject: [PATCH 02/23] Removing rebase mess --- server/server.go | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/server/server.go b/server/server.go index bbde32e7ea..42f0ca8c0e 100644 --- a/server/server.go +++ b/server/server.go @@ -10,11 +10,10 @@ import ( "os" "strings" -<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 -======= "io/ioutil" + "path/filepath" + "time" ->>>>>>> Adding ci for atlantis "github.com/elazarl/go-bindata-assetfs" "github.com/google/go-github/github" "github.com/gorilla/mux" @@ -23,20 +22,11 @@ import ( "github.com/hootsuite/atlantis/locking/dynamodb" "github.com/hootsuite/atlantis/logging" "github.com/hootsuite/atlantis/middleware" -<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 "github.com/hootsuite/atlantis/models" -======= ->>>>>>> Adding ci for atlantis "github.com/hootsuite/atlantis/recovery" "github.com/pkg/errors" "github.com/urfave/cli" "github.com/urfave/negroni" -<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 - "io/ioutil" - "path/filepath" - "time" -======= ->>>>>>> Adding ci for atlantis ) const ( @@ -83,7 +73,6 @@ type ServerConfig struct { LockingDynamoDBTable string `mapstructure:"locking-dynamodb-table"` } -<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 // todo: rename to Command type CommandContext struct { Repo models.Repo @@ -129,24 +118,6 @@ type GeneralError struct { func (g GeneralError) Template() *CompiledTemplate { return GeneralErrorTmpl -======= -type ExecutionContext struct { - repoFullName string - pullNum int - requesterUsername string - requesterEmail string - comment string - repoSSHUrl string - head string - // commit base sha - base string - pullLink string - branch string - htmlUrl string - pullCreator string - command *Command - log *logging.SimpleLogger ->>>>>>> Adding ci for atlantis } func NewServer(config ServerConfig) (*Server, error) { @@ -343,10 +314,6 @@ func (s *Server) handlePullClosedEvent(w http.ResponseWriter, pullEvent github.P fmt.Fprintf(w, "Error unlocking locks: %v\n", err) return } -<<<<<<< d425de95fa1f3ee312a8b569290932163bc93bf1 -======= - ->>>>>>> Adding ci for atlantis fmt.Fprintln(w, "Locks unlocked") } From c1628ed67ca15ca5460a43042e511d32ad522732 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 14:33:53 -0700 Subject: [PATCH 03/23] setting up go environment for circleci --- Makefile | 2 +- circle.yml | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 74003d9753..f0061a3c99 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ debug: ## Output internal make variables @echo WORKSPACE = $(WORKSPACE) deps: - go get . + go get -v . build-service: ## Build the main Go service CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o atlantis . diff --git a/circle.yml b/circle.yml index dbe1dfea0b..3e8aedd370 100644 --- a/circle.yml +++ b/circle.yml @@ -1,32 +1,37 @@ machine: # Environment variables for build environment: + GOPATH: "${HOME}/.go_workspace" + WORKDIR: "${GOPATH}/src/github.com/hootsuite/atlantis" TERRAFORM_VERSION: 0.8.8 dependencies: override: + # move repository to the canonical import path + - mkdir -p "$(dirname ${WORKDIR})" + - cp -R "${HOME}/atlantis" "${WORKDIR}" # Install dependencies - - make deps + - cd "${HOME}" && make deps test: pre: # Test dependencies - - make deps-test + - cd "${HOME}" && make deps-test override: # Run tests - - ./scripts/build.sh + - cd "${HOME}" && ./scripts/build.sh # Run e2e tests post: - - ./scripts/e2e-deps.sh + - cd "${HOME}" && ./scripts/e2e-deps.sh # Start atlantis server - - ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: + - cd "${HOME}" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: background: true - sleep 2 - - ./ngrok http 4141: + - cd "${HOME}" && ./ngrok http 4141: background: true - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - - ./scripts/e2e.sh + - cd "${HOME}" && ./scripts/e2e.sh From 440c02a32d8f55743e4fe3cb62e293fff4e7669f Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 14:38:49 -0700 Subject: [PATCH 04/23] fixing typo with WORKDIR --- circle.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/circle.yml b/circle.yml index 3e8aedd370..b6076d3c46 100644 --- a/circle.yml +++ b/circle.yml @@ -11,27 +11,27 @@ dependencies: - mkdir -p "$(dirname ${WORKDIR})" - cp -R "${HOME}/atlantis" "${WORKDIR}" # Install dependencies - - cd "${HOME}" && make deps + - cd "${WORKDIR}" && make deps test: pre: # Test dependencies - - cd "${HOME}" && make deps-test + - cd "${WORKDIR}" && make deps-test override: # Run tests - - cd "${HOME}" && ./scripts/build.sh + - cd "${WORKDIR}" && ./scripts/build.sh # Run e2e tests post: - - cd "${HOME}" && ./scripts/e2e-deps.sh + - cd "${WORKDIR}" && ./scripts/e2e-deps.sh # Start atlantis server - - cd "${HOME}" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: + - cd "${WORKDIR}" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: background: true - sleep 2 - - cd "${HOME}" && ./ngrok http 4141: + - cd "${WORKDIR}" && ./ngrok http 4141: background: true - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - - cd "${HOME}" && ./scripts/e2e.sh + - cd "${WORKDIR}" && ./scripts/e2e.sh From 90def000592586017452560d94462a5cb323eecf Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 14:59:01 -0700 Subject: [PATCH 05/23] now excluding go get doesn't download e2e --- Makefile | 6 +++--- e2e/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f0061a3c99..9767c9f3bb 100644 --- a/Makefile +++ b/Makefile @@ -16,16 +16,16 @@ debug: ## Output internal make variables @echo WORKSPACE = $(WORKSPACE) deps: - go get -v . + go get -v $(go list ./... | grep -v e2e) build-service: ## Build the main Go service CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o atlantis . deps-test: - go get -t + go get -t $(go list ./... | grep -v e2e) test: ## Run tests, coverage reports, and clean (coverage taints the compiled code) - go test -v ./... + go test -v $(go list ./... | grep -v e2e) test-coverage: go test -v ./... -coverprofile=c.out diff --git a/e2e/Makefile b/e2e/Makefile index e9ab78f0b3..d3e7638896 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -10,7 +10,7 @@ debug: ## Output internal make variables @echo WORKSPACE = $(WORKSPACE) deps: ## Get go dependencies - go get . + go get -v . build: ## Build the main Go service go build -v -o atlantis-tests . From b2ea325cee5d2f9cdd4bfe7080026f54ee672ec1 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:06:13 -0700 Subject: [PATCH 06/23] fixing go get --- server/server.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/server.go b/server/server.go index 67ac180aa1..e52e8a0f8b 100644 --- a/server/server.go +++ b/server/server.go @@ -11,7 +11,6 @@ import ( "strings" "io/ioutil" - "path/filepath" "time" "github.com/elazarl/go-bindata-assetfs" @@ -94,7 +93,6 @@ type PathResult struct { Result Templater } - type Templater interface { Template() *CompiledTemplate } From 780de9147aaee3ff05de23eb3f88315e55e9ee6d Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:23:53 -0700 Subject: [PATCH 07/23] make targets now filter e2e tests --- Makefile | 8 +++++--- circle.yml | 2 +- scripts/e2e-deps.sh | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9767c9f3bb..46b92b086a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ BUILD_ID := $(shell git rev-parse --short HEAD 2>/dev/null || echo no-commit-id) WORKSPACE := $(shell pwd) +PKG := $(shell go list ./... | grep -v e2e) .PHONY: test @@ -14,18 +15,19 @@ debug: ## Output internal make variables @echo BUILD_ID = $(BUILD_ID) @echo IMAGE_NAME = $(IMAGE_NAME) @echo WORKSPACE = $(WORKSPACE) + @echo PKG = $(PKG) deps: - go get -v $(go list ./... | grep -v e2e) + go get -v $(PKG) build-service: ## Build the main Go service CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -o atlantis . deps-test: - go get -t $(go list ./... | grep -v e2e) + go get -t $(PKG) test: ## Run tests, coverage reports, and clean (coverage taints the compiled code) - go test -v $(go list ./... | grep -v e2e) + go test -v $(PKG) test-coverage: go test -v ./... -coverprofile=c.out diff --git a/circle.yml b/circle.yml index b6076d3c46..28206d02bf 100644 --- a/circle.yml +++ b/circle.yml @@ -34,4 +34,4 @@ test: - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - - cd "${WORKDIR}" && ./scripts/e2e.sh + - cd "${WORKDIR}/e2e" && ./scripts/e2e.sh diff --git a/scripts/e2e-deps.sh b/scripts/e2e-deps.sh index 989eadd863..c083b047ab 100755 --- a/scripts/e2e-deps.sh +++ b/scripts/e2e-deps.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash echo "Preparing to run e2e tests" -mv atlantis e2e/ +mv atlantis ${WORKDIR}/e2e/ # cd into e2e folder cd e2e/ From e9416c64f9e2909ed8e6673778e7ed4818fdba0d Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:29:21 -0700 Subject: [PATCH 08/23] fixing path to e2e script --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 28206d02bf..1243ab29b3 100644 --- a/circle.yml +++ b/circle.yml @@ -34,4 +34,4 @@ test: - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - - cd "${WORKDIR}/e2e" && ./scripts/e2e.sh + - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh From 4130eaa7dd0ad3d37d8f1b5c22b50f142aa76dc3 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:37:35 -0700 Subject: [PATCH 09/23] now removing old go files --- circle.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/circle.yml b/circle.yml index 1243ab29b3..76b96717dc 100644 --- a/circle.yml +++ b/circle.yml @@ -6,6 +6,10 @@ machine: TERRAFORM_VERSION: 0.8.8 dependencies: + pre: + # remove old go files + - rm -rf "$GOPATH" + override: # move repository to the canonical import path - mkdir -p "$(dirname ${WORKDIR})" From 2b047f5a8549c7563adb3998a5c99ae02e3701a9 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:44:33 -0700 Subject: [PATCH 10/23] clean up --- e2e/standalone-with-env/atlantis.yaml | 2 -- e2e/standalone-with-env/env/staging.tfvars | 0 e2e/standalone-with-env/main.tf | 3 --- e2e/standalone/atlantis.yaml | 2 -- e2e/standalone/main.tf | 3 --- 5 files changed, 10 deletions(-) delete mode 100644 e2e/standalone-with-env/atlantis.yaml delete mode 100644 e2e/standalone-with-env/env/staging.tfvars delete mode 100644 e2e/standalone-with-env/main.tf delete mode 100644 e2e/standalone/atlantis.yaml delete mode 100644 e2e/standalone/main.tf diff --git a/e2e/standalone-with-env/atlantis.yaml b/e2e/standalone-with-env/atlantis.yaml deleted file mode 100644 index 1df19fe5d2..0000000000 --- a/e2e/standalone-with-env/atlantis.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -stash_path: "/hello/path" \ No newline at end of file diff --git a/e2e/standalone-with-env/env/staging.tfvars b/e2e/standalone-with-env/env/staging.tfvars deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/e2e/standalone-with-env/main.tf b/e2e/standalone-with-env/main.tf deleted file mode 100644 index d59a273088..0000000000 --- a/e2e/standalone-with-env/main.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "aws" { - region = "us-east-1" -} diff --git a/e2e/standalone/atlantis.yaml b/e2e/standalone/atlantis.yaml deleted file mode 100644 index 1df19fe5d2..0000000000 --- a/e2e/standalone/atlantis.yaml +++ /dev/null @@ -1,2 +0,0 @@ ---- -stash_path: "/hello/path" \ No newline at end of file diff --git a/e2e/standalone/main.tf b/e2e/standalone/main.tf deleted file mode 100644 index e22b634ef1..0000000000 --- a/e2e/standalone/main.tf +++ /dev/null @@ -1,3 +0,0 @@ -provider "aws" { - region = "us-east-1" -} \ No newline at end of file From 36c90ad36baac1e18638c7949bb0dc724be19d0c Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 15:55:31 -0700 Subject: [PATCH 11/23] moving atlantis url environment variable along side e2e --- circle.yml | 2 -- e2e/main.go | 2 +- scripts/e2e.sh | 4 ++++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 76b96717dc..fdd06d5c5a 100644 --- a/circle.yml +++ b/circle.yml @@ -36,6 +36,4 @@ test: - cd "${WORKDIR}" && ./ngrok http 4141: background: true - sleep 2 - # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh diff --git a/e2e/main.go b/e2e/main.go index f1200032cd..19ee7e87cb 100644 --- a/e2e/main.go +++ b/e2e/main.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/go-multierror" ) -var defaultAtlantisURL = "http://localhost:4141/hooks" +var defaultAtlantisURL = "http://localhost:4141" var projectTypes = []Project{ Project{"standalone", "run plan", "run apply"}, Project{"standalone-with-env", "run plan staging", "run apply staging"}, diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 3653834c47..93b60b028f 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -19,6 +19,10 @@ make test echo "Running 'make build'" make build +# Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook +export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') +echo "ATLANTIS_URL="${ATLANTIS_URL} + # Run e2e tests echo "Running e2e test: 'make run'" make run From 0819d8961c1ee6e87a3f203a6458b3ea86ccd342 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:00:25 -0700 Subject: [PATCH 12/23] not exporting the variable anymore --- scripts/e2e.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 93b60b028f..771284ac85 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -20,7 +20,10 @@ echo "Running 'make build'" make build # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook -export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') +echo "Get the tunnel url" +curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url' + +ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') echo "ATLANTIS_URL="${ATLANTIS_URL} # Run e2e tests From 8dd6ad7aa06628a73ab2563a4d8e736fb7f8eacb Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:04:45 -0700 Subject: [PATCH 13/23] not exporting the variable anymore --- scripts/e2e.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 771284ac85..80ec1787a6 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -19,11 +19,9 @@ make test echo "Running 'make build'" make build -# Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook -echo "Get the tunnel url" -curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url' - -ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') + # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook +echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> ~/.circlerc +cat ~/.circlerc echo "ATLANTIS_URL="${ATLANTIS_URL} # Run e2e tests From 12bdc9f49354f6b037a87cc2adf462add9bb8b38 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:17:22 -0700 Subject: [PATCH 14/23] more testing --- circle.yml | 3 +++ scripts/e2e.sh | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index fdd06d5c5a..1e25de0337 100644 --- a/circle.yml +++ b/circle.yml @@ -36,4 +36,7 @@ test: - cd "${WORKDIR}" && ./ngrok http 4141: background: true - sleep 2 + # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook + - echo '\n' >> ~/.circlerc + - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> ~/.circlerc - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 80ec1787a6..b0aad5b712 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -19,8 +19,6 @@ make test echo "Running 'make build'" make build - # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook -echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> ~/.circlerc cat ~/.circlerc echo "ATLANTIS_URL="${ATLANTIS_URL} From 6757361c1da85d03ab5bf13063a6468b115893af Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:21:21 -0700 Subject: [PATCH 15/23] fixing typo --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 1e25de0337..b289271a17 100644 --- a/circle.yml +++ b/circle.yml @@ -37,6 +37,6 @@ test: background: true - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - - echo '\n' >> ~/.circlerc + - echo '' >> ~/.circlerc - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> ~/.circlerc - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh From 9ef6d262b775929e14ab400299f8675cce621481 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:28:18 -0700 Subject: [PATCH 16/23] test --- circle.yml | 2 +- scripts/e2e.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/circle.yml b/circle.yml index b289271a17..f59a69b2d7 100644 --- a/circle.yml +++ b/circle.yml @@ -38,5 +38,5 @@ test: - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - echo '' >> ~/.circlerc - - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url')' >> ~/.circlerc + - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh diff --git a/scripts/e2e.sh b/scripts/e2e.sh index b0aad5b712..3653834c47 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -19,9 +19,6 @@ make test echo "Running 'make build'" make build -cat ~/.circlerc -echo "ATLANTIS_URL="${ATLANTIS_URL} - # Run e2e tests echo "Running e2e test: 'make run'" make run From 2894665b117cffa4910a44e5b13d6b01a290821c Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:34:02 -0700 Subject: [PATCH 17/23] fixing more mistakes --- circle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index f59a69b2d7..74f660b427 100644 --- a/circle.yml +++ b/circle.yml @@ -30,10 +30,10 @@ test: post: - cd "${WORKDIR}" && ./scripts/e2e-deps.sh # Start atlantis server - - cd "${WORKDIR}" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: + - cd "${WORKDIR}/e2e" && ./atlantis server --gh-user="$GITHUB_USERNAME" --gh-password="$GITHUB_PASSWORD" --data-dir="/tmp" --require-approval=false --s3-bucket="$ATLANTIS_S3_BUCKET_NAME" --log-level="debug" &> /tmp/atlantis-server.log: background: true - sleep 2 - - cd "${WORKDIR}" && ./ngrok http 4141: + - cd "${WORKDIR}/e2e" && ./ngrok http 4141: background: true - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook From 035fece77ec9a8ba4c4e18306f6ff9b501c84228 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:42:58 -0700 Subject: [PATCH 18/23] now printing github url to debug --- e2e/e2e.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2e.go b/e2e/e2e.go index 4cb019c38b..2debdf1dec 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -48,7 +48,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { cloneCmd := exec.Command("git", "clone", t.repoUrl, cloneDir) // git clone the repo - log.Printf("git cloning into %q", cloneDir) + log.Printf("git cloning %s into %q", t.repoUrl, cloneDir) if output, err := cloneCmd.CombinedOutput(); err != nil { return e2eResult, errors.New(fmt.Sprintf("failed to clone repository: %v: %s", err, string(output))) } From 9af4e6f86ce828837c235b2bd9ddcda6a56c202e Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 16:47:13 -0700 Subject: [PATCH 19/23] removing git url debug --- e2e/e2e.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2e.go b/e2e/e2e.go index 2debdf1dec..4cb019c38b 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -48,7 +48,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { cloneCmd := exec.Command("git", "clone", t.repoUrl, cloneDir) // git clone the repo - log.Printf("git cloning %s into %q", t.repoUrl, cloneDir) + log.Printf("git cloning into %q", cloneDir) if output, err := cloneCmd.CombinedOutput(); err != nil { return e2eResult, errors.New(fmt.Sprintf("failed to clone repository: %v: %s", err, string(output))) } From 898d3da67080663d780b6fbcbf1734d957f12733 Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sat, 17 Jun 2017 17:23:21 -0700 Subject: [PATCH 20/23] regenerated all credentials --- e2e/secrets-envs | Bin 320 -> 320 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/e2e/secrets-envs b/e2e/secrets-envs index c58583e83e97f8354cdc9b0571bb673c46d23019..83f1846239d91006cd8068aea6e2b9fad3db7e33 100644 GIT binary patch literal 320 zcmV-G0l)rJVQh3|WM5xX)p_d<%wkfVmg`mTD#zP(x~9M%fJn?r%ISc!V1eOMo#Mr| z?T8wkQgycnfUA=v=#c>+t@;E@17rei6ED-8VEn3Z0+e=mii{?TewVr0xBpBC@t7qj z_E#~|Yf;Q^9Bjn*o8l@5;*Wfz(cS2luz)(cT&szbGHyZua1|@*ja8gQV3#Iv<*Kva zq~dkIi|Wu%*{yN^J4Tp0c|=Ksi?+ukmx;89y&sYiF>{fj=a|qpy^qB3I8_2RAAuHF zQt3d&fK978J2FUN!{Xt`(Wxd#TI&*VO?4(e1!l#DUBLt7)(6R)aAbD#g*{jVk#hvtPeZI+X zOFd%`&A3ewb}4RpsWw`mntLr`)Oipa;B$O9=4PYlYv+GGoHySEN`{ zzL3%@fR3I%??*|U0tAJi!@$*)lPT>)&18(c_{y!_MbtzxsjR@@cS8$9g`xql)q#_| zlA}jpTrCEG74ID^fm`jzzgbTuN++0Pea3RFak}=Of*+sIo0CdCl~G@5;1r_%b!&Al z=?yWnMoM;pjl@bQo2`9nOzaPS2&@0-cM_Uj1|fNcKcpw_(t&*SgMUN-D>6GqN@x8p$%rMBS{uU~v35 SW5&Z?I`zwBd`KRtYg#snucr?H From 8581b37a7a1f6679d9f4b56c1ca1c5afef0740db Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sun, 18 Jun 2017 16:44:30 -0700 Subject: [PATCH 21/23] fixes after review --- Makefile | 2 +- e2e/e2e.go | 34 +++++++++++++++++----------------- e2e/main.go | 5 +---- scripts/e2e-deps.sh | 2 +- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 46b92b086a..0d02872c7a 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ test: ## Run tests, coverage reports, and clean (coverage taints the compiled co go test -v $(PKG) test-coverage: - go test -v ./... -coverprofile=c.out + go test -v $(PKG) -coverprofile=c.out go tool cover -html=c.out -o coverage.html dist: ## Package up everything in static/ using go-bindata-assetfs so it can be served by a single binary diff --git a/e2e/e2e.go b/e2e/e2e.go index 4cb019c38b..b284b70fa9 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -1,7 +1,6 @@ package main import ( - "errors" "fmt" "io/ioutil" "log" @@ -43,14 +42,14 @@ func (t *E2ETester) Start() (*E2EResult, error) { // create the directory and parents if necessary log.Printf("creating dir %q", cloneDir) if err := os.MkdirAll(cloneDir, 0755); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to create dir %q prior to cloning, attempting to continue: %v", cloneDir, err)) + return e2eResult, fmt.Errorf("failed to create dir %q prior to cloning, attempting to continue: %v", cloneDir, err) } cloneCmd := exec.Command("git", "clone", t.repoUrl, cloneDir) // git clone the repo log.Printf("git cloning into %q", cloneDir) if output, err := cloneCmd.CombinedOutput(); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to clone repository: %v: %s", err, string(output))) + return e2eResult, fmt.Errorf("failed to clone repository: %v: %s", err, string(output)) } // checkout a new branch for the project @@ -58,7 +57,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { checkoutCmd := exec.Command("git", "checkout", "-b", branchName) checkoutCmd.Dir = cloneDir if err := checkoutCmd.Run(); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to git checkout branch %q: %v", branchName, err)) + return e2eResult, fmt.Errorf("failed to git checkout branch %q: %v", branchName, err) } // write a file for running the tests @@ -67,7 +66,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { log.Printf("creating file to commit %q", filePath) err := ioutil.WriteFile(filePath, randomData, 0644) if err != nil { - return e2eResult, errors.New(fmt.Sprintf("couldn't write file %s: %v", filePath, err)) + return e2eResult, fmt.Errorf("couldn't write file %s: %v", filePath, err) } // add the file @@ -75,7 +74,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { addCmd := exec.Command("git", "add", filePath) addCmd.Dir = cloneDir if err := addCmd.Run(); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to git add file %q: %v", filePath, err)) + return e2eResult, fmt.Errorf("failed to git add file %q: %v", filePath, err) } // commit the file @@ -83,7 +82,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { commitCmd := exec.Command("git", "commit", "-am", "test commit") commitCmd.Dir = cloneDir if output, err := commitCmd.CombinedOutput(); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to run git commit in %q: %v", cloneDir, err, string(output))) + return e2eResult, fmt.Errorf("failed to run git commit in %q: %v", cloneDir, err, string(output)) } // push the branch to remote @@ -91,7 +90,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { pushCmd := exec.Command("git", "push", "origin", branchName) pushCmd.Dir = cloneDir if err := pushCmd.Run(); err != nil { - return e2eResult, errors.New(fmt.Sprintf("failed to git push branch %q: %v", branchName, err)) + return e2eResult, fmt.Errorf("failed to git push branch %q: %v", branchName, err) } // create a new pr @@ -103,7 +102,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { pull, _, err := t.githubClient.client.PullRequests.Create(t.githubClient.ctx, t.ownerName, t.repoName, newPullRequest) if err != nil { - return e2eResult, errors.New(fmt.Sprintf("error while creating new pull request: %v", err)) + return e2eResult, fmt.Errorf("error while creating new pull request: %v", err) } // set pull request url @@ -118,7 +117,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { log.Printf("creating plan comment: %q", t.projectType.PlanCommand) _, _, err = t.githubClient.client.Issues.CreateComment(t.githubClient.ctx, t.ownerName, t.repoName, pull.GetNumber(), &github.IssueComment{Body: github.String(t.projectType.PlanCommand)}) if err != nil { - return e2eResult, errors.New(fmt.Sprintf("error creating 'run plan' comment on github")) + return e2eResult, fmt.Errorf("error creating 'run plan' comment on github") } // wait for atlantis to respond to webhook @@ -126,12 +125,13 @@ func (t *E2ETester) Start() (*E2EResult, error) { state := "not started" // waiting for atlantis run and finish - for checkStatus(state) { + for i := 0; i < 100 && checkStatus(state); i++ { + time.Sleep(2 * time.Second) + state, _ = getAtlantisStatus(t, branchName) if state == "" { log.Println("atlantis run hasn't started") + continue } - time.Sleep(2 * time.Second) - state, _ = getAtlantisStatus(t, branchName) log.Printf("atlantis run is in %s state", state) } @@ -139,7 +139,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { e2eResult.testResult = state // check if atlantis run was a success if state != "\"success\"" { - return e2eResult, errors.New(fmt.Sprintf("atlantis run project type %q failed with %s status", t.projectType.Name, state)) + return e2eResult, fmt.Errorf("atlantis run project type %q failed with %s status", t.projectType.Name, state) } return e2eResult, nil @@ -153,7 +153,7 @@ func getAtlantisStatus(t *E2ETester, branchName string) (string, error) { } for _, status := range combinedStatus.Statuses { - if github.Stringify(status.Context) == "\"Atlantis\"" { + if status.GetContext() == "\"Atlantis\"" { return github.Stringify(status.State), nil } } @@ -174,14 +174,14 @@ func cleanUp(t *E2ETester, pullRequestNumber int, branchName string) error { // clean up pullClosed, _, err := t.githubClient.client.PullRequests.Edit(t.githubClient.ctx, t.ownerName, t.repoName, pullRequestNumber, &github.PullRequest{State: github.String("closed")}) if err != nil { - return errors.New(fmt.Sprintf("error while closing new pull request: %v", err)) + return fmt.Errorf("error while closing new pull request: %v", err) } log.Printf("closed pull request %d", pullClosed.GetNumber()) deleteBranchName := fmt.Sprintf("%s/%s", "heads", branchName) _, err = t.githubClient.client.Git.DeleteRef(t.githubClient.ctx, t.ownerName, t.repoName, deleteBranchName) if err != nil { - return errors.New(fmt.Sprintf("error while deleting branch %s: %v", deleteBranchName, err)) + return fmt.Errorf("error while deleting branch %s: %v", deleteBranchName, err) } log.Printf("deleted branch %s", deleteBranchName) diff --git a/e2e/main.go b/e2e/main.go index 19ee7e87cb..40d00629ae 100644 --- a/e2e/main.go +++ b/e2e/main.go @@ -136,10 +136,7 @@ func deleteAtlantisHook(g *GithubClient, ownerName string, repoName string, hook } func cleanDir(path string) error { - if err := os.RemoveAll(path); err != nil { - return err - } - return nil + return os.RemoveAll(path) } func startTests(e2e E2ETester) ([]*E2EResult, error) { diff --git a/scripts/e2e-deps.sh b/scripts/e2e-deps.sh index c083b047ab..9657dcdc3d 100755 --- a/scripts/e2e-deps.sh +++ b/scripts/e2e-deps.sh @@ -5,7 +5,7 @@ mv atlantis ${WORKDIR}/e2e/ # cd into e2e folder cd e2e/ -# Encrypting secrets for atlantis runtime: https://github.com/circleci/encrypted-files +# Decrypting secrets for atlantis runtime: https://github.com/circleci/encrypted-files openssl aes-256-cbc -d -in secrets-envs -k $KEY >> ~/.circlerc # Download terraform curl -LOk https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip From b2f1b9d98c8b2ccdcc02ecd712b984db6b8618ae Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sun, 18 Jun 2017 16:48:32 -0700 Subject: [PATCH 22/23] removing a redundant step merging into one and some notes --- circle.yml | 3 +-- scripts/build.sh | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/circle.yml b/circle.yml index 74f660b427..57b320f754 100644 --- a/circle.yml +++ b/circle.yml @@ -37,6 +37,5 @@ test: background: true - sleep 2 # Set ATLANTIS_URL environment variable to be used by atlantis e2e test to create the webhook - - echo '' >> ~/.circlerc - - echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc + - echo '' >> ~/.circlerc && echo 'export ATLANTIS_URL=$(curl -s 'http://localhost:4040/api/tunnels' | jq -r '.tunnels[1].public_url') ' >> ~/.circlerc - cd "${WORKDIR}/e2e" && ../scripts/e2e.sh diff --git a/scripts/build.sh b/scripts/build.sh index 20d8d452e5..0b6fe90a63 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -11,3 +11,5 @@ run_unit_test # Build packages to make sure they can be compiled echo "Running 'make build'" make build-service + +# TODO: add parallel builds for every make target that has anything to do with testing. From 3a96724da5ea55748184c560b18bdb5d6276012e Mon Sep 17 00:00:00 2001 From: Anubhav Mishra Date: Sun, 18 Jun 2017 17:09:14 -0700 Subject: [PATCH 23/23] fixed bugs with string comparision --- e2e/e2e.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e/e2e.go b/e2e/e2e.go index b284b70fa9..0916d75c12 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -125,7 +125,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { state := "not started" // waiting for atlantis run and finish - for i := 0; i < 100 && checkStatus(state); i++ { + for i := 0; i < 20 && checkStatus(state); i++ { time.Sleep(2 * time.Second) state, _ = getAtlantisStatus(t, branchName) if state == "" { @@ -138,7 +138,7 @@ func (t *E2ETester) Start() (*E2EResult, error) { log.Printf("atlantis run finished with %s status", state) e2eResult.testResult = state // check if atlantis run was a success - if state != "\"success\"" { + if state != "success" { return e2eResult, fmt.Errorf("atlantis run project type %q failed with %s status", t.projectType.Name, state) } @@ -153,8 +153,8 @@ func getAtlantisStatus(t *E2ETester, branchName string) (string, error) { } for _, status := range combinedStatus.Statuses { - if status.GetContext() == "\"Atlantis\"" { - return github.Stringify(status.State), nil + if status.GetContext() == "Atlantis" { + return status.GetState(), nil } } @@ -162,7 +162,7 @@ func getAtlantisStatus(t *E2ETester, branchName string) (string, error) { } func checkStatus(state string) bool { - for _, s := range []string{"\"success\"", "\"error\"", "\"failure\""} { + for _, s := range []string{"success", "error", "failure"} { if state == s { return false }