Skip to content

Commit

Permalink
Compliation and deployment, get the endpoint verification working
Browse files Browse the repository at this point in the history
  • Loading branch information
joffotron committed Apr 12, 2020
1 parent 9bdcda1 commit 5a656bc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .buildkite/bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -eo pipefail

cd "/var/task/reservation-bot"
bundle config set deployment true
bundle install --without test development
5 changes: 5 additions & 0 deletions .buildkite/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker-compose build
docker-compose run --rm compile

docker-compose run --rm -w "/opt/app/" serverless sls deploy --verbose

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ atlassian-ide-plugin.xml
.env
.rvmrc

# Generated by the compilation for deployment
vendor
.bundle
.serverless
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM lambci/lambda:build-ruby2.7

ENV BASE=/var/task/reservation-bot/

RUN mkdir ${BASE}
WORKDIR ${BASE}
COPY . ${BASE}
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ services:
AWS_SECRET_ACCESS_KEY:
AWS_SESSION_TOKEN:
AWS_SECURITY_TOKEN:
#
# lambda_tests:
# build:
# context: .
# dockerfile: Dockerfile.rspec
# volumes:
# - .:/var/task/

compile:
build:
context: .
volumes:
- .:/var/task/
command: .buildkite/bundle.sh
16 changes: 12 additions & 4 deletions handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ class Handler
# 'event_time': 1496764428
# }
def self.action(event:, context:)
p event.inspect
payload = JSON.parse(event['body'])
p payload

{
response = {
statusCode: 200,
body: JSON.generate({ challenge: event['challenge'] }),
headers: JSON.generate({ 'X-Slack-No-Retry': 1 })
body: { challenge: payload['challenge'] }.to_json
}
p response

response

rescue StandardError => e
puts e.message
puts e.backtrace.inspect
{ statusCode: 500, body: {error: e.message, trace: e.backtrace&.join("\n")}.to_json }
end
end
10 changes: 7 additions & 3 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ provider:
functions:
reservationbot:
memorySize: 256
name: ${opt:stage}-reservation-bot
name: ${self:service}
handler: handler.Handler.action
events:
- http:
path: "/action"
method: post
response:
headers:
Content-Type: "application/json"
X-Slack-No-Retry: "1"
environment:
VERIFICATION_TOKEN: ${ssm:/reservationbot/slack_verification_token}
BOT_TOKEN: ${ssm:/reservationbot/slack_bot_token}
VERIFICATION_TOKEN: ${ssm:/reservationbot/slack.verification.token}
BOT_TOKEN: ${ssm:/reservationbot/slack.bot.oauth.token}

0 comments on commit 5a656bc

Please sign in to comment.