Skip to content

Commit

Permalink
Create GitHub Actions CI pipeline for the samples (#134)
Browse files Browse the repository at this point in the history
major rework of Makefiles and samples in the process
  • Loading branch information
baermat authored Aug 8, 2022
1 parent b04dfc5 commit eb25b2a
Show file tree
Hide file tree
Showing 42 changed files with 662 additions and 7,875 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Makefile CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '0 13 * * *' # 13:00 server time, meaning 14/15:00 our time. For regular commits in LS
- cron: '0 17 * * *' # 17:00 server time, meaning 18/19:00 our time. For the "This needs to be done today" folks.
- cron: '0 7 * * *' # 08:00 server time, meaning 09/10:00 our time. For the night owls and early birds.
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: 12

- name: Install LocalStack
run: pip install localstack awscli-local[ver1]

- name: Install Dependencies
run: |
pip install virtualenv
npm install -g serverless
- name: Setup config
run: |
echo "Configuring git for codecommit sample"
git config --global user.email "[email protected]"
git config --global user.name "Localstack Pro-Samples"
- name: Pull the latest docker image
run: docker pull localstack/localstack

- name: Execute tests
env:
LOCALSTACK_API_KEY: ${{ secrets.TEST_LOCALSTACK_API_KEY }}
DNS_ADDRESS: 127.0.0.1
DEBUG: 1
run: make test-ci-all
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules/
.classpath
.project
.settings/
.vscode/
target/

.idea/
Expand All @@ -27,3 +28,5 @@ testdata/

glacier-s3-select/*result.csv
azure-functions/.python_packages/

*/logs.txt
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ usage: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

install: ## Install dependencies for all projects
CMD='make install' make for-each-dir
MAKE_TARGET='install' make for-each-dir

lint: ## Run code linter for all projects
CMD='make lint' make for-each-dir
MAKE_TARGET='lint' make for-each-dir

start: ## Start LocalStack infrastructure
nohup localstack start &
localstack start -d

ready: ## Check if the LocalStack container is up and running.
localstack wait -t 20 && echo "LocalStack is ready to use!"

stop: ## Stop LocalStack infrastructure
localstack stop

for-each-dir:
for d in $$(ls -d */); do echo "Running tests in $$d"; (cd $$d; $(CMD)) || exit 1; done
./make-for-each.sh $$MAKE_TARGET $$CMD

test-ci-all:
CMD='test ! -e Makefile || make test-ci' make for-each-dir
MAKE_TARGET='test-ci' make for-each-dir

.PHONY: usage install lint start
.PHONY: usage install lint start ready stop for-each-dir test-ci-all
1 change: 1 addition & 0 deletions apigw-custom-domain/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./sslcert/*
29 changes: 22 additions & 7 deletions apigw-custom-domain/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export AWS_ACCESS_KEY_ID ?= test
export AWS_SECRET_ACCESS_KEY ?= test
export AWS_DEFAULT_REGION ?= us-east-1
export SERVICES ?= serverless,acm,route53


usage: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
Expand All @@ -11,7 +11,7 @@ install: ## Install dependencies
@which serverless || npm install -g serverless
@which localstack || pip install localstack
@which awslocal || pip install awscli-local

cert: ## Create test SSL certificate
mkdir -p sslcert
cd sslcert; \
Expand All @@ -22,7 +22,6 @@ cert: ## Create test SSL certificate
openssl x509 -req -in ssl.csr -CAcreateserial -out server.crt -sha256 -CAkey rootCA.key -CA rootCA.pem

run: ## Deploy the app locally and run an API GW test invocation
@make install; \
echo "Generating and importing test SSL certificate to ACM for Route53 domain test.example.com"; \
make cert; \
echo "Importing local test certificate into ACM API ..."; \
Expand All @@ -33,11 +32,27 @@ run: ## Deploy the app locally and run an API GW test invocation
SLS_DEBUG=1 npm run deploy && \
echo "Serverless app successfully deployed. Now trying to invoke the API Gateway endpoints with custom domains." && \
echo && echo "Invoking endpoint 1: http://test.example.com:4566/hello" && \
curl -H 'Host: test.example.com' http://localhost:4566/hello && \
response1=`curl -H 'Host: test.example.com' http://localhost:4566/hello` && \
../assert "$$response1" = "hello world" && \
echo && echo && echo "Invoking endpoint 2: http://test.example.com:4566/goodbye" && \
curl -H 'Host: test.example.com' http://localhost:4566/goodbye
response2=`curl -H 'Host: test.example.com' http://localhost:4566/goodbye` && \
../assert "$$response2" = "goodbye"

start:
localstack start -d

stop:
@echo
localstack stop
ready:
@echo Waiting on the LocalStack container...
@localstack wait -t 30 && echo Localstack is ready to use! || (echo Gave up waiting on LocalStack, exiting. && exit 1)

logs:
@localstack logs > logs.txt

test-ci:
make install && make run || true
make start install ready run; return_code=`echo $$?`;\
make logs; make stop; exit $$return_code;

.PHONY: usage install run cert
.PHONY: usage install run cert ready stop logs test-ci
Loading

0 comments on commit eb25b2a

Please sign in to comment.