diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..712a5a6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,39 @@ +name: CI +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-18.04 + steps: + - name: Checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Install ruby + uses: actions/setup-ruby@v1 + - name: Install aws-sam-cli + run: sudo pip install aws-sam-cli + # - name: Install aws sam cli + # run: | + # sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)" + # brew --version + # sudo brew tap aws/tap + # brew install aws-sam-cli + # sam --version + - name: Build local layer + run: make create_layer + # - name: Build local and package local lambda + # run: make build_lambda + # - name: Run show local files + # run: ls -an ./Examples/SquareNumber/ + # - name: Package local lambda + # run: make package_lambda + - name: test local lambda + run: make test_layer + \ No newline at end of file diff --git a/.gitignore b/.gitignore index b8e9a4e..94f375a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.build /Packages /*.xcodeproj +/.swiftpm lambda.zip -swift-shared-libs -swift-lambda-runtime.zip \ No newline at end of file +swift-lambda-runtime +swift-lambda-runtime.zip diff --git a/Makefile b/Makefile index 5e1019b..840c31a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ EXAMPLE_LAMBDA=SquareNumber EXAMPLE_EXECUTABLE=SquareNumber EXAMPLE_PROJECT_PATH=Examples/SquareNumber + # EXAMPLE_LAMBDA=SyntaxHighlighter # EXAMPLE_EXECUTABLE=SyntaxHighlighter # EXAMPLE_PROJECT_PATH=Examples/SyntaxHighlighter @@ -8,9 +9,14 @@ EXAMPLE_PROJECT_PATH=Examples/SquareNumber # EXAMPLE_EXECUTABLE=RESTCountries # EXAMPLE_PROJECT_PATH=Examples/RESTCountries LAMBDA_ZIP=lambda.zip -SHARED_LIBS_FOLDER=swift-shared-libs +LAYER_FOLDER=swift-lambda-runtime LAYER_ZIP=swift-lambda-runtime.zip -SWIFT_DOCKER_IMAGE=swift:5.1 +SHARED_LIBS_FOLDER=$(LAYER_FOLDER)/swift-shared-libs +SWIFT_DOCKER_IMAGE=swift:5.1.1 + +# System specific configuration + +UNAME_S := $(shell uname -s) clean_lambda: rm $(LAMBDA_ZIP) || true @@ -34,8 +40,11 @@ clean_layer: rm $(LAYER_ZIP) || true rm -r $(SHARED_LIBS_FOLDER) || true -package_layer: clean_layer +create_layer: clean_layer + mkdir -p $(LAYER_FOLDER) mkdir -p $(SHARED_LIBS_FOLDER)/lib + cp ./bootstrap "$(LAYER_FOLDER)/bootstrap" + chmod 755 "$(LAYER_FOLDER)/bootstrap" docker run \ --rm \ --volume "$(shell pwd)/:/src" \ @@ -104,5 +113,11 @@ package_layer: clean_layer /usr/lib/x86_64-linux-gnu/libstdc++.so.6 \ /usr/lib/x86_64-linux-gnu/libtasn1.so.6 \ /usr/lib/x86_64-linux-gnu/libunistring.so.2 \ - /usr/lib/x86_64-linux-gnu/libwind.so.0 + /usr/lib/x86_64-linux-gnu/libwind.so.0 \ + /usr/lib/x86_64-linux-gnu/libxml2.so.2 + +test_layer: package_lambda + echo '{"number": 9 }' | sam local invoke --force-image-build -v . "SquareNumberFunction" + +package_layer: create_layer zip -r $(LAYER_ZIP) bootstrap $(SHARED_LIBS_FOLDER) diff --git a/template.yaml b/template.yaml new file mode 100644 index 0000000..ac2b031 --- /dev/null +++ b/template.yaml @@ -0,0 +1,37 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: > + sam-app + + Sample SAM Template for sam-app + +# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst +Globals: + Function: + Timeout: 3 + +Resources: + + SwiftLayer: + Type: AWS::Serverless::LayerVersion + Properties: + ContentUri: swift-lambda-runtime/ + # ContentUri: + # Bucket: de.fabianfett.denkan.app.sam + # Key: swift-lambda-runtime.zip + + SquareNumberFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: lambda.zip + Handler: "SquareNumber.squareNumber" + Runtime: provided + Layers: + - !Ref SwiftLayer + Events: + HelloWorld: + Type: Api + Properties: + Path: /hello + Method: get +