Browse Source

add support for ic.dev

Lionel Suss 4 years ago
parent
commit
890c63eeea
6 changed files with 89 additions and 2 deletions
  1. 16 2
      README.md
  2. 2 0
      aws/brick/.gitignore
  3. 10 0
      aws/brick/brick.yaml
  4. 18 0
      aws/brick/build.sh
  5. 36 0
      aws/brick/index.ic
  6. 7 0
      aws/brick/params.icp

+ 16 - 2
README.md

@@ -9,10 +9,10 @@ Inspired by
 [How I hacked Slack into a community platform with Typeform](https://levels.io/slack-typeform-auto-invite-sign-ups/)
 and Socket.io's Slack page.
 
-This project supports Heroku, Azure, Cloud Foundry, and Amazon Web Services (AWS).
+This project supports Heroku, Azure, Cloud Foundry, Amazon Web Services (AWS), and [ic.dev](https://ic.dev).
 
 [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
-[![Deploy to Azure](http://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)
+[![Deploy to Azure](https://azuredeploy.net/deploybutton.png)](https://azuredeploy.net/)
 
 ## Settings
 
@@ -81,6 +81,20 @@ Instead of editing `config.js`, take these steps:
 3. Run `aws/deploy.sh` to create the CloudFormation stack and deploy your application, outputting the URL
 4. (Optional) For a friendlier URL, log into the AWS web console and establish a custom domain pointing to the API Gateway stage deployed in step 3.
 
+### [ic.dev](https://ic.dev)
+
+If you haven't already installed the IC CLI, please refer to the [documentation](https://docs.ic.dev/setup-and-usage).
+
+Deploy the `lsuss.slack_inviter` brick directly from the IC Public Index:
+```shell
+$ ic aws up lsuss.slack_inviter slack_inviter --params community_name='Your Community Name',slack_url=yourcommunity.slack.com,slack_token=xoxp-xxx-xxx-xxx-xxx
+```
+
+Retreive the id and url of the API:
+```shell
+$ ic aws value slack_inviter
+```
+
 ## Run
 [Node.js](http://nodejs.org/) is required.
 

+ 2 - 0
aws/brick/.gitignore

@@ -0,0 +1,2 @@
+lambda.zip
+build/

+ 10 - 0
aws/brick/brick.yaml

@@ -0,0 +1,10 @@
+name: lsuss.slack_inviter
+version: v0.1.2
+license: MIT
+description: |
+  A serverless web application to invite users into your Slack
+main: :brick
+require:
+  iclab.simple: v0.2.0
+assets:
+- lambda.zip

+ 18 - 0
aws/brick/build.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# "set -e" makes it so if any step fails, the script aborts:
+set -e
+
+cd "${BASH_SOURCE%/*}"
+
+# Build Lambda package
+rm -rf build
+mkdir build
+cd ../..
+cp -r app.js config.js lib locales package-lock.json package.json public routes views aws/brick/build
+cd aws/brick/build
+cp ../../src/* .
+npm install
+npm install aws-serverless-express
+cd ../build
+zip -r ../lambda.zip .

+ 36 - 0
aws/brick/index.ic

@@ -0,0 +1,36 @@
+from iclab import simple
+from . import assets
+
+
+@resource
+def brick(
+    community_name,
+    slack_url,
+    slack_token,
+    invite_token="",
+    recaptcha_site_key="",
+    recaptcha_secret_key="",
+    locale="en",
+):
+    api = simple.api("api", "express", "0.1.2")
+    func = simple.function(
+        "func",
+        "nodejs8.10",
+        assets["lambda.zip"],
+        handler="lambda.handler",
+        memory_size=1024,
+        timeout=10,
+        environ=dict(
+            COMMUNITY_NAME=community_name,
+            SLACK_URL=slack_url,
+            SLACK_TOKEN=slack_token,
+            INVITE_TOKEN=invite_token,
+            RECAPTCHA_SITE=recaptcha_site_key,
+            RECAPTCHA_SECRET=recaptcha_secret_key,
+            LOCALE=locale,
+        ),
+    )
+    func.http(api, "any", "/{proxy+}", binary_media="*/*")
+    func.http(api, "any", "/", binary_media="*/*")
+
+    return dict(api=dict(id=api["api"]["ref"], url=f'{api["url"]}/'))

+ 7 - 0
aws/brick/params.icp

@@ -0,0 +1,7 @@
+community_name = "Your Community Name"
+slack_url = "yourcommunity.slack.com"
+slack_token = "xoxp-xxx-xxx-xxx-xxx"
+# invite_token = util.sensitive("")
+# recaptcha_site_key = util.sensitive("")
+# recaptcha_secret_key = util.sensitive("")
+# locale = "en"