-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
139 lines (107 loc) · 4.82 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
PACTICIPANT := "pactflow-example-provider-js-sns"
GITHUB_REPO := "pactflow/example-provider-js-sns"
CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID := "0278fe46-09be-4b9d-b037-559d2891f752"
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli:latest"
AWS_CLI:="docker run --rm -it -e AWS_ACCESS_KEY_ID=1234 -e AWS_SECRET_ACCESS_KEY=1234 amazon/aws-cli --region ap-southeast-2"
AWS_SNS_ENDPOINT := http://localhost:4566
AWS_REGION := ap-southeast-2
export AWS_SNS_ENDPOINT
export AWS_REGION
# Only deploy from master
ifeq ($(GIT_BRANCH),master)
DEPLOY_TARGET=deploy
else
DEPLOY_TARGET=no_deploy
endif
all: test
## ====================
## CI tasks
## ====================
ci: test can_i_deploy $(DEPLOY_TARGET)
# Run the ci target from a developer machine with the environment variables
# set as if it was on Github Actions.
# Use this for quick feedback when playing around with your workflows.
fake_ci: .env
CI=true \
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
make ci
ci_webhook: .env
npm run test
fake_ci_webhook:
CI=true \
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true \
make ci_webhook
## =====================
## Build/test tasks
## =====================
test: .env
npm run test
## =====================
## Deploy tasks
## =====================
deploy: deploy_app record_deployment
no_deploy:
@echo "Not deploying as not on master branch"
can_i_deploy: .env
"${PACT_CLI}" broker can-i-deploy --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --to-environment production
deploy_app:
@echo "Deploying to production"
record_deployment: .env
@"${PACT_CLI}" broker record-deployment --pacticipant ${PACTICIPANT} --version ${GIT_COMMIT} --environment production
## =====================
## PactFlow set up tasks
## =====================
# export the GITHUB_TOKEN environment variable before running this
create_github_token_secret:
curl -v -X POST ${PACT_BROKER_BASE_URL}/secrets \
-H "Authorization: Bearer ${PACT_BROKER_TOKEN}" \
-H "Content-Type: application/json" \
-H "Accept: application/hal+json" \
-d "{\"name\":\"githubToken\",\"description\":\"Github token\",\"value\":\"${GITHUB_TOKEN}\"}"
# NOTE: the github token secret must be created (either through the UI or using the
# `create_travis_token_secret` target) before the webhook is invoked.
create_or_update_contract_requiring_verification_published_webhook:
"${PACT_CLI}" \
broker create-or-update-webhook \
"https://api.github.com/repos/${GITHUB_REPO}/dispatches" \
--header 'Content-Type: application/json' 'Accept: application/vnd.github.everest-preview+json' 'Authorization: Bearer $${user.githubToken}' \
--request POST \
--data '{ "event_type": "contract_requiring_verification_published","client_payload": { "pact_url": "$${pactbroker.pactUrl}", "sha": "$${pactbroker.providerVersionNumber}", "branch":"$${pactbroker.providerVersionBranch}" , "message": "Verify changed pact for $${pactbroker.consumerName} version $${pactbroker.consumerVersionNumber} branch $${pactbroker.consumerVersionBranch} by $${pactbroker.providerVersionNumber} ($${pactbroker.providerVersionDescriptions})" } }' \
--uuid ${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID} \
--provider ${PACTICIPANT} \
--contract-requiring-verification-published \
--description "contract_requiring_verification_published for ${PACTICIPANT}"
test_contract_requiring_verification_published_webhook:
@curl -v -X POST ${PACT_BROKER_BASE_URL}/webhooks/${CONTRACT_REQUIRING_VERIFICATION_PUBLISHED_WEBHOOK_UUID}/execute -H "Authorization: Bearer ${PACT_BROKER_TOKEN}"
## ======================
## Misc
## ======================
.env:
touch .env
docker-logs:
@docker-compose -f sns.yml logs -f
docker-rm:
@docker-compose -f sns.yml rm -vfs
docker-stop:
@docker-compose -f sns.yml stop
docker:
@docker-compose -f sns.yml up -d --no-recreate
wait-for-localstack:
while [[ "`nc -zv 0.0.0.0 4566`" =~ "succeeded" ]]; do sleep 2; done
sleep 10
create-topic: wait-for-localstack
@IP=$(shell docker inspect -f '{{ .NetworkSettings.IPAddress }}' localstack_main); \
"${AWS_CLI}" --endpoint http://$$IP:4566 sns create-topic --name products
start: docker create-topic
npm start
create-product:
curl -v -X POST -H"Content-Type: application/json" localhost:8001/products -d '{"type":"pizza", "name":"food"}'
update-product:
curl -v -X PUT -H"Content-Type: application/json" localhost:8001/products/1 -d '{"type":"pizza", "name":"food", "version":"v1"}'
delete-product:
curl -v -X DELETE -H"Content-Type: application/json" localhost:8001/products/1 -d '{"type":"pizza", "name":"food", "version":"v1"}'
.PHONY: docker docker-stop docker-rm docker-logs