From 5a656bcdfb61f9b2bb2e423ad89be535ee03613f Mon Sep 17 00:00:00 2001 From: Joseph Miller Date: Sun, 12 Apr 2020 16:07:41 +1000 Subject: [PATCH] Compliation and deployment, get the endpoint verification working --- .buildkite/bundle.sh | 7 +++++++ .buildkite/notes.txt | 5 +++++ .gitignore | 4 ++++ Dockerfile | 7 +++++++ docker-compose.yml | 14 +++++++------- handler.rb | 16 ++++++++++++---- serverless.yml | 10 +++++++--- 7 files changed, 49 insertions(+), 14 deletions(-) create mode 100755 .buildkite/bundle.sh create mode 100644 .buildkite/notes.txt create mode 100644 Dockerfile diff --git a/.buildkite/bundle.sh b/.buildkite/bundle.sh new file mode 100755 index 0000000..7834e5e --- /dev/null +++ b/.buildkite/bundle.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -eo pipefail + +cd "/var/task/reservation-bot" +bundle config set deployment true +bundle install --without test development diff --git a/.buildkite/notes.txt b/.buildkite/notes.txt new file mode 100644 index 0000000..8cd380e --- /dev/null +++ b/.buildkite/notes.txt @@ -0,0 +1,5 @@ +docker-compose build +docker-compose run --rm compile + +docker-compose run --rm -w "/opt/app/" serverless sls deploy --verbose + diff --git a/.gitignore b/.gitignore index 524ee8c..9e4bfed 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,7 @@ atlassian-ide-plugin.xml .env .rvmrc +# Generated by the compilation for deployment +vendor +.bundle +.serverless diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..068dd59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM lambci/lambda:build-ruby2.7 + +ENV BASE=/var/task/reservation-bot/ + +RUN mkdir ${BASE} +WORKDIR ${BASE} +COPY . ${BASE} diff --git a/docker-compose.yml b/docker-compose.yml index 60c17f3..b67f468 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/handler.rb b/handler.rb index 4300df1..695bbef 100644 --- a/handler.rb +++ b/handler.rb @@ -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 diff --git a/serverless.yml b/serverless.yml index 1ab7f1c..e2808aa 100644 --- a/serverless.yml +++ b/serverless.yml @@ -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}