Skip to content

Commit

Permalink
Allow easily runnings tests against AWS
Browse files Browse the repository at this point in the history
  • Loading branch information
tiago-loureiro committed Oct 8, 2018
1 parent 4792d88 commit 00c4507
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,22 @@ tools/api-simulations/reports
.DS_Store
brig-schema.yaml
brig.yaml
brig.integration-aws.yaml
cannon.yaml
cannon.integration-aws.yaml
cargohold.yaml
cargohold.integration-aws.yaml
galley-schema.yaml
galley.yaml
galley.integration-aws.yaml
gundeck-schema.yaml
gundeck.yaml
gundeck.integration-aws.yaml
proxy.yaml
proxy.integration-aws.yaml
spar.yaml
spar.integration-aws.yaml
integration-aws.yaml
DOCKER_ID*
swagger-ui
services/spar/spar.cabal
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
LANG := en_US.UTF-8
SHELL := /usr/bin/env bash
LANG := en_US.UTF-8
HASKELL_SERVICES := proxy cannon cargohold brig galley gundeck
SERVICES := $(HASKELL_SERVICES) nginz
DOCKER_USER ?= wireserver
Expand Down Expand Up @@ -38,6 +39,16 @@ integration: fast
$(MAKE) -C services/gundeck i-fake-aws
$(MAKE) -C services/spar i

.PHONY: integration-aws
integration-aws: fast
# We run "i" instead of "integration" to avoid useless rebuilds
# (since after "fast" everything will be built already)
$(MAKE) -C services/cargohold i-aws
$(MAKE) -C services/galley i-aws
$(MAKE) -C services/brig i-aws
$(MAKE) -C services/gundeck i-aws
$(MAKE) -C services/spar i-aws

.PHONY: haddock
haddock:
WIRE_STACK_OPTIONS="--haddock --haddock-internal" make fast
Expand Down
4 changes: 4 additions & 0 deletions services/brig/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ $(DEB_INDEX): install
i:
../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-aws
i-aws:
INTEGRATION_USE_REAL_AWS=1 ../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-list
i-list:
$(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml -l
Expand Down
4 changes: 4 additions & 0 deletions services/cargohold/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ $(DEB_IT):
i:
../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-aws
i-aws:
INTEGRATION_USE_REAL_AWS=1 ../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-list
i-list:
$(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml -l
Expand Down
3 changes: 0 additions & 3 deletions services/cargohold/cargohold.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ cargohold:
port: 8084

aws:
# TODO: Check AWS loadCredentialsFromEnv
keyId: dummykey # <-- insert-key-id-here
secretKey: dummysecret # <-- insert-secret-key-here
s3Bucket: dummy-bucket # <-- insert-bucket-name-here
s3Endpoint: http://localhost:4570 # https://s3-eu-west-1.amazonaws.com:443
# If you want to use cloudfront for asset downloads
Expand Down
3 changes: 0 additions & 3 deletions services/cargohold/src/CargoHold/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ newEnv o = do

initAws :: Opts -> Logger -> Manager -> IO AwsEnv
initAws o l m = do
-- TODO: The AWS package can also load them from the env, check the latest API
-- https://hackage.haskell.org/package/aws-0.17.1/docs/src/Aws-Core.html#loadCredentialsFromFile
-- which would avoid the need to specify them in a config file when running tests
let awsOpts = o^.optAws
amz <- Aws.newEnv l m $ liftM2 (,) (awsOpts^.awsKeyId) (awsOpts^.awsSecretKey)
sig <- newCloudFrontEnv (o^.optAws.awsCloudFront) (o^.optSettings.setDownloadLinkTTL)
Expand Down
4 changes: 4 additions & 0 deletions services/galley/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ $(DEB_JOURNALER):
i:
../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-aws
i-aws:
INTEGRATION_USE_REAL_AWS=1 ../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-list
i-list:
$(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml -l
Expand Down
19 changes: 19 additions & 0 deletions services/gen-aws-conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/" && pwd )"

# Ensure that we have a file named integration-aws.yaml in the current
# dir. If not, fetch it from a known location on S3
if [ ! -f "${DIR}/integration-aws.yaml" ]
then
echo "Could not find AWS config file to override settings, specify a location on S3 to download the file or add one at ${DIR}/integration-aws.yaml and retry: "
read location
aws s3 cp s3://$location .
fi

services=( brig cargohold galley gundeck cannon proxy spar )
for service in "${services[@]}"; do
yaml merge ${DIR}/integration-aws.yaml ${DIR}/${service}/${service}.integration.yaml > ${DIR}/${service}/${service}.integration-aws.yaml
done
4 changes: 4 additions & 0 deletions services/gundeck/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ bench: install
i:
../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-aws
i-aws:
INTEGRATION_USE_REAL_AWS=1 ../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-list
i-list:
$(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml -l
Expand Down
26 changes: 19 additions & 7 deletions services/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,32 @@ orange=3
yellow=11
purpleish=13

if [[ $INTEGRATION_USE_REAL_AWS -eq 1 ]]; then
echo 'Attempting to run integration tests using real AWS services!'
[ -z "$AWS_REGION" ] && echo "Need to set AWS_REGION in your environment" && exit 1;
[ -z "$AWS_ACCESS_KEY_ID" ] && echo "Need to set AWS_ACCESS_KEY_ID in your environment" && exit 1;
[ -z "$AWS_SECRET_ACCESS_KEY" ] && echo "Need to set AWS_SECRET_ACCESS_KEY in your environment" && exit 1;
${TOP_LEVEL}/services/gen-aws-conf.sh
integration_file_extension='-aws.yaml'
else
# brig,gundeck,galley use the amazonka library's 'Discover', which expects AWS credentials
# even if those are not used/can be dummy values with the fake sqs/ses/etc containers used
# (see deploy/docker-ephemeral/docker-compose.yaml )
echo 'Running tests using mocked AWS services'
export AWS_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=dummykey
export AWS_SECRET_ACCESS_KEY=dummysecret
integration_file_extension='.yaml'
fi

function run() {
service=$1
colour=$2
export LOG_LEVEL=$3
(cd ${DIR}/${service} && ${TOP_LEVEL}/dist/${service} -c ${service}.integration.yaml || kill_all) \
(cd ${DIR}/${service} && ${TOP_LEVEL}/dist/${service} -c ${service}.integration${integration_file_extension} || kill_all) \
| sed -e "s/^/$(tput setaf ${colour})[${service}] /" -e "s/$/$(tput sgr0)/" &
}

# brig,gundeck,galley use the amazonka library's 'Discover', which expects AWS credentials
# even if those are not used/can be dummy values with the fake sqs/ses/etc containers used (see deploy/docker-ephemeral/docker-compose.yaml )
export AWS_REGION=eu-west-1
export AWS_ACCESS_KEY_ID=dummykey
export AWS_SECRET_ACCESS_KEY=dummysecret

check_prerequisites

run brig ${green} Warn
Expand Down
4 changes: 4 additions & 0 deletions services/spar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ $(DEB_SCHEMA): install
i:
../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-aws
i-aws:
INTEGRATION_USE_REAL_AWS=1 ../integration.sh $(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml

.PHONY: i-list
i-list:
$(EXE_IT) -s $(NAME).integration.yaml -i ../integration.yaml -l
Expand Down

0 comments on commit 00c4507

Please sign in to comment.