Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
multi-env tests
Browse files Browse the repository at this point in the history
Signed-off-by: Phil Prasek <[email protected]>
  • Loading branch information
prasek committed Jun 26, 2021
1 parent 06829e2 commit 01492b5
Show file tree
Hide file tree
Showing 17 changed files with 456 additions and 102 deletions.
17 changes: 14 additions & 3 deletions .scripts/get-env.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#!/bin/bash

eval "$(cat graph-api.env)"
if [[ -z "${APOLLO_KEY}" ]]; then
if ls graph-api.env > /dev/null 2>&1; then
eval "$(cat graph-api.env)"
fi

if [[ -z "${APOLLO_KEY}" || -z "${APOLLO_GRAPH_REF}" ]]; then
source "$(dirname $0)/graph-api-env.sh"
eval "$(cat graph-api.env)"

if [[ -z "${APOLLO_KEY}" ]]; then
echo -------------------------------------------------------------------------------------------
echo environment keyfile required, run: make graph-api-key
echo APOLLO_KEY not found, run: make graph-api-env
echo -------------------------------------------------------------------------------------------
exit 1
fi

if [[ -z "${APOLLO_GRAPH_REF}" ]]; then
echo -------------------------------------------------------------------------------------------
echo APOLLO_GRAPH_REF not found, run: make graph-api-env
echo -------------------------------------------------------------------------------------------
exit 1
fi
fi

export APOLLO_KEY=$APOLLO_KEY
export APOLLO_GRAPH_REF=$APOLLO_GRAPH_REF
8 changes: 8 additions & 0 deletions .scripts/get-graph-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ echo "then copy your Graph NAME and optionally @<VARIANT> and enter it at the pr
echo "@<VARIANT> will default to @current, if omitted."
echo ""
echo "Enter the <NAME>@<VARIANT> of a federated graph in Apollo Studio:"
if [[ -n "$APOLLO_GRAPH_REF" ]]; then
echo ""
echo "press <enter> for default: $APOLLO_GRAPH_REF"
fi
read -p "> " graph
if [[ -z "$graph" ]]; then
if [[ -n "$APOLLO_GRAPH_REF" ]]; then
graph=$APOLLO_GRAPH_REF
else
>&2 echo "Error: no graph ref specified."
exit 1
fi
fi

export graph=$graph
40 changes: 40 additions & 0 deletions .scripts/graph-api-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

if ls graph-api.env > /dev/null 2>&1; then
eval "$(cat graph-api.env)"
fi

echo -------------------------------------------------------------------------------------------
echo Enter your Graph API Key
echo -------------------------------------------------------------------------------------------
echo "Go to your graph settings in https://studio.apollographql.com/"
echo "then create a Graph API Key with Contributor permissions"
echo "(for metrics reporting) and enter it at the prompt below."

if [[ -n "$APOLLO_KEY" ]]; then
echo ""
echo "press <enter> to use existing key: *************** (from ./graph-api.env)"
fi

read -s -p "> " key
echo
if [[ -z "$key" ]]; then
if [[ -n "$APOLLO_KEY" ]]; then
key=$APOLLO_KEY
else
>&2 echo "Error: no key specified."
exit 1
fi
fi

echo "APOLLO_KEY=${key}" > graph-api.env

# --------------------------------------------------------------------------
# APOLLO_GRAPH_REF
# --------------------------------------------------------------------------
echo ""
if [[ -z "${graph}" ]]; then
source "$(dirname $0)/get-graph-ref.sh"
fi

echo "APOLLO_GRAPH_REF=${graph}" >> graph-api.env
2 changes: 1 addition & 1 deletion .scripts/k8s-ci.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

.scripts/k8s-up.sh $1
.scripts/k8s-smoke.sh
.scripts/k8s-smoke.sh $1
code=$?
.scripts/k8s-down.sh
exit $code
5 changes: 4 additions & 1 deletion .scripts/k8s-smoke.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

env="${1:-dev}"
port="${2:-80}"

retry=60
code=1
until [[ $retry -le 0 || $code -eq 0 ]]
do
kubectl get all
.scripts/smoke.sh 80
( cd ./test/${env}; ./smoke.sh $port )

code=$?

Expand Down
20 changes: 19 additions & 1 deletion .scripts/query.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

PORT="${1:-4000}"

read -r -d '' QUERY <<"EOF"
{
allProducts {
id,
sku,
createdBy {
email,
totalProductsCreated
}
}
}
EOF

QUERY=$(echo "${QUERY}" | awk -v ORS= -v OFS= '{$1=$1}1')

echo -------------------------------------------------------------------------------------------
(set -x; curl -X POST -H 'Content-Type: application/json' --data '{ "query": "{ allProducts { id, sku, createdBy { email, totalProductsCreated } } }" }' http://localhost:$PORT/)
ACT=$(set -x; curl -X POST -H 'Content-Type: application/json' --data '{ "query": "'"${QUERY}"'" }' http://localhost:$PORT/)
echo ""
echo "Result:"
echo "$ACT"
echo -------------------------------------------------------------------------------------------
22 changes: 0 additions & 22 deletions .scripts/smoke.sh

This file was deleted.

30 changes: 22 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: default
default: demo-k8s
default: demo

.PHONY: demo-k8s
demo-k8s: k8s-up-dev k8s-smoke k8s-down
.PHONY: demo
demo: k8s-up-dev smoke k8s-down

.PHONY: k8s-up
k8s-up:
Expand All @@ -20,13 +20,25 @@ k8s-up-stage:
k8s-up-prod:
.scripts/k8s-up.sh prod

.PHONY: k8s-query
k8s-query:
.PHONY: query
query:
.scripts/query.sh 80

.PHONY: k8s-smoke
k8s-smoke:
.scripts/k8s-smoke.sh 80
.PHONY: smoke
smoke:
.scripts/k8s-smoke.sh

.PHONY: smoke-dev
smoke-dev:
.scripts/k8s-smoke.sh dev

.PHONY: smoke-stage
smoke-stage:
.scripts/k8s-smoke.sh stage

.PHONY: smoke-prod
smoke-prod:
.scripts/k8s-smoke.sh prod

.PHONY: k8s-nginx-dump
k8s-nginx-dump:
Expand Down Expand Up @@ -99,9 +111,11 @@ promote-dev-stage:
cp infra/dev/kustomization.yaml infra/stage
cp subgraphs/dev/kustomization.yaml subgraphs/stage
cp router/dev/kustomization.yaml router/stage
cp test/dev/smoke.sh test/stage

.PHONY: promote-stage-prod
promote-stage-prod:
cp infra/stage/kustomization.yaml infra/prod
cp subgraphs/stage/kustomization.yaml subgraphs/prod
cp router/stage/kustomization.yaml router/prod
cp test/stage/smoke.sh test/prod
Loading

0 comments on commit 01492b5

Please sign in to comment.