Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! server…
Browse files Browse the repository at this point in the history
…less initial commit
  • Loading branch information
davidcheung committed Dec 21, 2021
1 parent 85e155d commit 64dce94
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ github_actions_setup:
sh scripts/gha-setup.sh setup

serverless_setup:
ifeq ($(serverless), yes)
ifeq ($(backendApplicationHosting), serverless)
sh scripts/serverless-setup.sh
endif

Expand Down
2 changes: 1 addition & 1 deletion templates/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# - run smoke test against staging enviroment
# - deploy to production
name: CI Pipeline
<% if eq (index .Params `serverless`) "yes" -%>
<% if eq (index .Params `backendApplicationHosting`) "serverless" -%>
on:
workflow_dispatch # Manual dispatch, when CI flow is disabled for syntax completeness
# # uncomment `push` to use CI with Kubernetes Cluster
Expand Down
2 changes: 1 addition & 1 deletion templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ You now have a repo to start writing your backend logic! The Go api comes with a

# Deployment

<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
## AWS Serverless Application Model
Your application is deployed to AWS using [SAM](https://aws.amazon.com/serverless/sam/). The main building blocks includes
- API Gateway
Expand Down
4 changes: 2 additions & 2 deletions templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"graphql-combine": "^1.0.1",
<%- end %>
"aws-cloudfront-sign": "^2.2.0",
<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
"aws-xray-sdk": "^3.3.3",
"aws-xray-sdk-core": "^3.3.3",
<%- end %>
Expand All @@ -41,7 +41,7 @@
<%- else if eq (index .Params `database`) "mysql" %>
"mysql2": "^2.2.5",
<%- end %>
<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
"serverless-http": "^2.7.0",
<%- end %>
"sequelize": "^6.3.5"
Expand Down
6 changes: 3 additions & 3 deletions templates/src/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const dotenv = require("dotenv");
const express = require("express");
const morgan = require("morgan");
<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
// To wrap express in lambda compatible export
const serverless = require("serverless-http");
const AWSXRay = require('aws-xray-sdk');
Expand All @@ -24,7 +24,7 @@ const publicRoutes = require("./app/public");
dotenv.config();
const app = express();
app.use(morgan("combined"));
<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
app.use(AWSXRay.express.openSegment('<% .Name %>'));
<%- end %>
app.use(express.json());
Expand Down Expand Up @@ -75,7 +75,7 @@ const main = async () => {
});
};

<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
app.use(AWSXRay.express.closeSegment());
// Run traditional http server instead of lambda export
if (process.env.NODE_ENV === 'development') {
Expand Down
4 changes: 2 additions & 2 deletions templates/src/middleware/auth/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if eq (index .Params `serverless`) "yes" -%>
<% if eq (index .Params `backendApplicationHosting`) "serverless" -%>
// For Lambda Authorizer proxy passing JWT contenxt via to Lambda requestContext
const authMiddleware = (req, res, next) => {
// comes from authrozier's Context
Expand Down Expand Up @@ -43,7 +43,7 @@ const authAllowlist = ["/status/ready", "/status/alive", "/status/about"];
const inAllowlist = (path) => {
return authAllowlist.find(element => element === path);
}
<%- if eq (index .Params `serverless`) "yes" %>
<%- if eq (index .Params `backendApplicationHosting`) "serverless" %>
*/
<% end %>
module.exports = {
Expand Down
17 changes: 9 additions & 8 deletions zero-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ requiredCredentials:
- github

parameters:
- field: backendApplicationHosting
label: How do you want to host the backend of your application?
info: "Kubernetes is more complex and expensive, but significantly more feature-rich. The serverless approach can be cheaper but is limited in tooling.\nWe recommend Kubernetes for all but the most simple applications. See why: https://whyk8s.getzero.dev"
default: "kubernetes"
options:
"kubernetes": "Kubernetes using AWS EKS"
"serverless": "Serverless using AWS SAM/Lambda"
- field: useExistingAwsProfile
label: "Use credentials from an existing AWS profile?"
info: "You can choose either a currently existing profile if you've already configured your AWS CLI, or manually enter a pair of AWS access keys."
Expand Down Expand Up @@ -203,12 +210,6 @@ parameters:
"none": "none"
"memcached": "Memcached"
"redis": "Redis"
- field: serverless
label: "Use Lightweight Serverless setup instead of Kubernetes Cluster SaSS setup"
info: "Lightweight setup using AWS Serverless Applciation Model(SAM), less customizable and features offered compared to EKS, good for projects just starting out."
options:
"no": "No"
"yes": "Yes"
conditions:
- action: ignoreFile
matchField: fileUploads
Expand Down Expand Up @@ -256,8 +257,8 @@ conditions:
- src/app/billing
- scripts/stripe-example-setup.sh
- action: ignoreFile
matchField: serverless
whenValue: "no"
matchField: backendApplicationHosting
whenValue: "kubernetes"
data:
- auth
- .github/workflows/sam.yml
Expand Down

0 comments on commit 64dce94

Please sign in to comment.