Skip to content

Commit

Permalink
Merge pull request #2426 from amazeeio/pullrequest-fixed-api-tests
Browse files Browse the repository at this point in the history
Add Pull Requests to Controller Tests
  • Loading branch information
Schnitzel authored Dec 28, 2020
2 parents 2823f93 + 432b7a9 commit 0c3c5e9
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 30 deletions.
44 changes: 31 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ api-development: build/api build/api-db build/local-api-data-watcher-pusher buil
KIND_VERSION = v0.9.0
GOJQ_VERSION = v0.11.2
KIND_IMAGE = kindest/node:v1.19.1@sha256:98cf5288864662e37115e362b23e4369c8c4a408f99cbc06e58ac30ddc721600
TESTS = [features-kubernetes,nginx,drupal-php72,drupal-php73,drupal-php74,drupal-postgres,python]
TESTS = [api,features-kubernetes,nginx,drupal-php72,drupal-php73,drupal-php74,drupal-postgres,python]
CHARTS_TREEISH = main

local-dev/kind:
Expand Down Expand Up @@ -991,6 +991,19 @@ kind/cluster: local-dev/kind
&& echo -e '\nOr running locally:\n' \
&& echo -e './local-dev/kind export kubeconfig --name "$(CI_BUILD_TAG)"\n' \
&& echo -e 'kubectl ...\n'
$(MAKE) kind/cluster-osx-ip

kind/cluster-osx-ip:
ifeq ($(ARCH), darwin)
export KUBECONFIG="$$(pwd)/kubeconfig.kind.$(CI_BUILD_TAG)" && \
if ! ifconfig lo0 | grep $$(./local-dev/kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}') -q; then sudo ifconfig lo0 alias $$(./local-dev/kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}'); fi
docker rm --force $(CI_BUILD_TAG)-kind-proxy-32080 || true
docker run -d --name $(CI_BUILD_TAG)-kind-proxy-32080 \
--publish 32080:32080 \
--link $(CI_BUILD_TAG)-control-plane:target --network kind \
alpine/socat -dd \
tcp-listen:32080,fork,reuseaddr tcp-connect:target:32080
endif

KIND_SERVICES = api api-db api-redis auth-server broker controllerhandler docker-host drush-alias keycloak keycloak-db kubectl-build-deploy-dind local-api-data-watcher-pusher local-git ssh tests
KIND_TOOLS = kind helm kubectl jq
Expand All @@ -1001,28 +1014,33 @@ kind/test: kind/cluster helm/repos $(addprefix local-dev/,$(KIND_TOOLS)) $(addpr
&& git clone https://github.com/uselagoon/lagoon-charts.git "$$CHARTSDIR" \
&& cd "$$CHARTSDIR" \
&& git checkout $(CHARTS_TREEISH) \
&& export KUBECONFIG=$$(mktemp ../kubeconfig.XXX) \
&& KIND_CLUSTER_NAME="$(CI_BUILD_TAG)" ../local-dev/kind export kubeconfig \
&& export KUBECONFIG="$$(realpath ../kubeconfig.kind.$(CI_BUILD_TAG))" \
&& export IMAGE_REGISTRY="registry.$$(../local-dev/kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}').nip.io:32080/library" \
&& $(MAKE) install-registry HELM=$$(realpath ../local-dev/helm) KUBECTL=$$(realpath ../local-dev/kubectl) \
&& docker login -u admin -p Harbor12345 $$IMAGE_REGISTRY \
&& for image in $(KIND_SERVICES); do \
docker tag $(CI_BUILD_TAG)/$$image $$IMAGE_REGISTRY/$$image:$(BRANCH_NAME) \
&& docker push $$IMAGE_REGISTRY/$$image:$(BRANCH_NAME); \
done \
&& cd .. && $(MAKE) kind/push-images && cd "$$CHARTSDIR" \
&& $(MAKE) fill-test-ci-values TESTS=$(TESTS) IMAGE_TAG=$(BRANCH_NAME) \
HELM=$$(realpath ../local-dev/helm) KUBECTL=$$(realpath ../local-dev/kubectl) \
JQ=$$(realpath ../local-dev/jq) \
OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=$$IMAGE_REGISTRY/kubectl-build-deploy-dind:$(BRANCH_NAME) \
IMAGE_REGISTRY=$$IMAGE_REGISTRY \
HELM=$$(realpath ../local-dev/helm) KUBECTL=$$(realpath ../local-dev/kubectl) \
JQ=$$(realpath ../local-dev/jq) \
OVERRIDE_BUILD_DEPLOY_DIND_IMAGE=$$IMAGE_REGISTRY/kubectl-build-deploy-dind:$(BRANCH_NAME) \
IMAGE_REGISTRY=$$IMAGE_REGISTRY \
&& docker run --rm --network host --name ct-$(CI_BUILD_TAG) \
--volume "$$(pwd)/test-suite-run.ct.yaml:/etc/ct/ct.yaml" \
--volume "$$(pwd):/workdir" \
--volume "$$(realpath $$KUBECONFIG):/root/.kube/config" \
--volume "$$(realpath ../kubeconfig.kind.$(CI_BUILD_TAG)):/root/.kube/config" \
--workdir /workdir \
"quay.io/helmpack/chart-testing:v3.1.1" \
ct install

.PHONY: kind/push-images
kind/push-images:
export KUBECONFIG="$$(pwd)/kubeconfig.kind.$(CI_BUILD_TAG)" && \
export IMAGE_REGISTRY="registry.$$(./local-dev/kubectl get nodes -o jsonpath='{.items[0].status.addresses[0].address}').nip.io:32080/library" \
&& docker login -u admin -p Harbor12345 $$IMAGE_REGISTRY \
&& for image in $(KIND_SERVICES); do \
docker tag $(CI_BUILD_TAG)/$$image $$IMAGE_REGISTRY/$$image:$(BRANCH_NAME) \
&& docker push $$IMAGE_REGISTRY/$$image:$(BRANCH_NAME); \
done

.PHONY: kind/clean
kind/clean: local-dev/kind
KIND_CLUSTER_NAME="$(CI_BUILD_TAG)" ./local-dev/kind delete cluster
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then
fi

if [ "$BUILD_TYPE" == "pullrequest" ]; then
BUILD_ARGS+=(--build-arg LAGOON_GIT_SHA="${LAGOON_GIT_SHA}")
BUILD_ARGS+=(--build-arg LAGOON_PR_HEAD_BRANCH="${PR_HEAD_BRANCH}")
BUILD_ARGS+=(--build-arg LAGOON_PR_HEAD_SHA="${PR_HEAD_SHA}")
BUILD_ARGS+=(--build-arg LAGOON_PR_BASE_BRANCH="${PR_BASE_BRANCH}")
Expand Down
1 change: 1 addition & 0 deletions lagoon-charts.2nl
Submodule lagoon-charts.2nl added at 845c6a
1 change: 1 addition & 0 deletions lagoon-charts.3fo
Submodule lagoon-charts.3fo added at 845c6a
1 change: 1 addition & 0 deletions lagoon-charts.F8t
Submodule lagoon-charts.F8t added at 9b23f0
1 change: 1 addition & 0 deletions lagoon-charts.OSM
Submodule lagoon-charts.OSM added at 845c6a
1 change: 1 addition & 0 deletions lagoon-charts.Zly
Submodule lagoon-charts.Zly added at 845c6a
2 changes: 1 addition & 1 deletion tests/tasks/api/pullrequest-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
headers:
Authorization: "Bearer {{ token }}"
body_format: json
body: '{ "query": "mutation($projectName:String!, $number:Int!, $title:String!, $baseName:String!, $baseRef:String!, $headName:String!, $headRef:String!) {deployEnvironmentPullrequest(input:{project:{name:$projectName},number:$number,title:$title,baseBranchName:$baseName,baseBranchRef:$baseRef,headBranchName:$headName,headBranchRef:$headRef})}", "variables": {"projectName":"{{ project }}","number":"{{ git_pr_number }}","title":"{{ git_pr_title }}","baseName":"{{ git_base_branch }}","baseRef":"{{ git_base_commit_hash }}","headName":"{{ git_pr_branch }}","headRef":"{{ git_pr_commit_hash }}"}}'
body: '{ "query": "mutation($projectName:String!, $number:Int!, $title:String!, $baseName:String!, $baseRef:String!, $headName:String!, $headRef:String!) {deployEnvironmentPullrequest(input:{project:{name:$projectName},number:$number,title:$title,baseBranchName:$baseName,baseBranchRef:$baseRef,headBranchName:$headName,headBranchRef:$headRef})}", "variables": {"projectName":"{{ project }}","number":{{ git_pr_number }},"title":"{{ git_pr_title }}","baseName":"{{ git_base_branch }}","baseRef":"{{ git_base_commit_hash }}","headName":"{{ git_pr_branch }}","headRef":"{{ git_pr_commit_hash }}"}}'
register: apiresponse
- name: "{{ testname }} - POST api deployEnvironmentPullrequest with pr number {{ git_pr_number }}, git base branch {{ git_base_branch }}, base commit hash {{ git_base_commit_hash }}, pr branch {{ git_pr_branch }}, pr commit hash {{ git_pr_commit_hash }} to {{ lookup('env','API_PROTOCOL') }}://{{ lookup('env','API_HOST') }}:{{ lookup('env','API_PORT') }}/graphql"
debug:
Expand Down
18 changes: 2 additions & 16 deletions tests/tests/api/deploy-pullrequest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,12 @@
git_base_commit_hash: "{{ base_commit_hash }}"
git_pr_branch: "pullrequest_pr"
git_pr_commit_hash: "{{ pr_commit_hash }}"
git_pr_number: "1"
git_pr_number: 1
git_pr_title: "PR Title"
tasks:
- include: ../../tasks/api/pullrequest-deploy.yaml


- include: ../../checks/check-branch-sha.yaml
vars:
expected_head: "{{ pr_commit_hash }}"
expected_branch: "pr-1"
project: "{{ project }}"
url: "{{ check_url }}"

- include: ../../checks/check-pullrequest.yaml
vars:
url: "{{ check_url }}"
Expand Down Expand Up @@ -85,18 +78,11 @@
git_base_commit_hash: "{{ base_commit_hash }}"
git_pr_branch: "pullrequest_pr"
git_pr_commit_hash: "{{ pr_2nd_commit_hash }}"
git_pr_number: "1"
git_pr_number: 1
git_pr_title: "PR Title - UPDATE"
tasks:
- include: ../../tasks/api/pullrequest-deploy.yaml

- include: ../../checks/check-branch-sha.yaml
vars:
expected_head: "{{ pr_2nd_commit_hash }}"
expected_branch: "pr-1"
project: "{{ project }}"
url: "{{ check_url }}"

- include: ../../checks/check-pullrequest.yaml
vars:
url: "{{ check_url }}"
Expand Down

0 comments on commit 0c3c5e9

Please sign in to comment.