Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initialization
  • Loading branch information
eko committed Jan 30, 2018
0 parents commit cb135e9
Show file tree
Hide file tree
Showing 12 changed files with 588 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.dist
@@ -0,0 +1,5 @@
ELEVENBOT_COACH_SPREADSHEET_ID=
ELEVENBOT_SLACK_TOKEN=

ELEVENBOT_SSH_USER=
ELEVENBOT_SSH_IP=
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
/config/client_secret.json
/.env
/vendor
97 changes: 97 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Gopkg.toml
@@ -0,0 +1,50 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/sirupsen/logrus"
version = "1.0.4"

[[constraint]]
branch = "master"
name = "golang.org/x/net"

[[constraint]]
branch = "master"
name = "golang.org/x/oauth2"

[[constraint]]
branch = "master"
name = "google.golang.org/api"

[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/robfig/cron"
version = "1.0.0"
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Rohan Chandra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 32 additions & 0 deletions Makefile
@@ -0,0 +1,32 @@
.PHONY: help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: ## Build binary
GOOS=linux GOARCH=amd64 go build -o elevenbot main.go

deploy: ## Deploys binary on a Google Cloud instance
@echo '>>> Deploy started'

ssh ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP} 'sudo systemctl stop elevenbot'
scp elevenbot ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP}:~
ssh ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP} 'sudo systemctl start elevenbot'

@echo '>>> done!'

prepare-deploy: ## Prepares bot to be deployed on a new instance
@echo '>>> Uploads config/ to server home directory'

scp config/ ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP}:~
ssh ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP} 'sudo mv config/elevenbot.service /etc/systemd/system/elevenbot.service'
ssh ${ELEVENBOT_SSH_USER}@${ELEVENBOT_SSH_IP} 'sudo systemctl daemon-reload'

@echo '>>> done!'

install: ## Installs dependencies
@echo '>>> Installs golang dependencies'

dep ensure

@echo '>>> done!'
53 changes: 53 additions & 0 deletions README.md
@@ -0,0 +1,53 @@
Coaching - Slack bot
====================

# Pre-requisites

You need to have `dep` tool installed to manage dependencies: [https://github.com/golang/dep](https://github.com/golang/dep).

# Installation

First, you need to install dependencies by running:

```
$ make install
```

Then, you have to create a `.env` file with your own values:

```
$ cp .env.dist .env
<edit .env file to fill your Slack token and google spreadsheet id>
$ source .env
```

You are almost ready to go! You need a last step: create a Google API OAuth 2.0 token:

You have to follow the instructions located in the link below in order to generate OAuth 2.0 Client ID keys: [https://cloud.google.com/genomics/downloading-credentials-for-api-access](https://cloud.google.com/genomics/downloading-credentials-for-api-access)

Once it's done, download the `client_secret.json` file from the interface and put it under `config/` folder.

On the first launch of the bot, you will also have to authenticate using OAuth2 with Google APIs. Just click on the link it outputs.

# Usage (on dev environment)

```
$ go run main.go
```

# Compilation

Run `make build` to build the source into a single `elevenbot` binary file.

# Prepare deployment on a new server

On first time deployment, you have to:

Edit your `.env` file in order to edit `ELEVENBOT_SSH_USER` and `ELEVENBOT_SSH_IP` environment variables.
Edit `config/elevenbot.service` file with environment variables and user name.

Then, run `make prepare-deploy` to prepare your instance.

# Deploy

Just run `make deploy`

0 comments on commit cb135e9

Please sign in to comment.