@spacemakerai/serverless-ingress v3.0.1
Serverless Ingress Plugin
This is a serverless plugin that configures and deploys Kubernetes Ingress resources. The plugin is currently only designed to be used in combination with S3 buckets defined in serverless.
This plugin allows you to define the host and pathname that should point to your statically hosted site on S3.
Example
To get started, install the following packages:
yarn add --dev serverless serverless-s3-sync @spacemakerai/serverless-ingress serverless-scriptable-plugin
Only serverless
and @spacemakerai/serverless-ingress
are strictly required. Using serverless-s3-sync
will make deployment simpler, replacing aws s3 sync
, and with serverless-scriptable-plugin
you can define a pre-deployment hook to build your app.
After installing the above packages, create serverless.yaml
:
service: sm-app-auth # Replace auth with your app name
provider:
name: aws
region: eu-west-1
plugins:
- serverless-s3-sync
- serverless-scriptable-plugin
- '@spacemakerai/serverless-ingress'
custom:
bucketName: sm-app-auth
path: /auth # The path that your app should be served under
ingress:
host: app.spacemaker.ai
path: ${self:custom.path}
disableAuth: false # Set this to true to disable authentication. Disabled authentication only works if the S3 bucket is set to public
singlePageApplication: true # Serves index file for any path that is not a static file (any path that does not contain a ".")
index: index.html # Path in bucket to file that should be served for all paths that do not match static files
scriptHooks:
before:package:createDeploymentArtifacts: yarn build # This is run before deploy. Remove if you want to run build manually
s3Sync: # S3 syncing. Removed if you would rather deploy with aws cli
- bucketName: ${self:custom.bucketName}
localDir: build # The local folder that should be synced to the bucket. Change if build outputs to another folder
resources:
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.bucketName}
Deployment
Deployment is initiated with yarn run sls deploy
. If you deploy through CircleCI, you can add an extra step that deploys this in addition to your old bucket.
Local configuration
For deploying, you need AWS credentials set and you need S3 and CloudFormation permissions. In addition to this, you need kubernetes credentials with permissions to create resources.
CircleCI configuration
CircleCI needs permissions in order to deploy the generated Kubernetes Ingress. You need to run the following commands in your CircleCI deployment before yarn run sls deploy
:
mkdir -p $HOME/.kube
echo $KUBE_CONFIG | base64 -d > $HOME/.kube/config
You also need to ensure that this CircleCI task is run in the org-global context so that it gets access to the KUBE_CONFIG
environment variable.