operable / cog-book

Cog's Documentation in book form
https://operable.github.io/cog-book/
Other
13 stars 10 forks source link

Add gem install instruction #27

Closed so0k closed 7 years ago

so0k commented 7 years ago

just in case reader is really unfamiliar with Ruby?

CLAassistant commented 7 years ago

CLA assistant check
All committers have signed the CLA.

so0k commented 7 years ago

at the Dockerfile stage, should add Gemfile instructions

so0k commented 7 years ago

running locally, echo Twitter vars to .secret load .secret to env for testing locally:

export $(cat .secret | xargs)

Changed my Dockerfile as follows (notice --standalone flag for bundler and re-order layers):

FROM alpine:3.4

RUN apk --no-cache add bash build-base ca-certificates \
                       ruby ruby-dev ruby-bundler ruby-io-console

RUN adduser -D bundle
USER bundle
WORKDIR /home/bundle

COPY Gemfile .
RUN bundle install --standalone

COPY . /home/bundle

Added bundle/bundler/setup to tweet.rb

#!/usr/bin/env ruby

require_relative 'bundle/bundler/setup'
require 'twitter'

client = Twitter::REST::Client.new(
  consumer_key: ENV["TWITTER_CONSUMER_KEY"],
  consumer_secret: ENV["TWITTER_CONSUMER_SECRET"],
  access_token: ENV["TWITTER_ACCESS_TOKEN"],
  access_token_secret: ENV["TWITTER_ACCESS_TOKEN_SECRET"])

message = ARGV.join(" ")

tweet = client.update(message)

puts <<-EOM
Message: #{message}
URL:     #{tweet.url}
EOM

build container image:

docker build -t vincentdesmet/twitter_example:0.0.1 .

run test container:

docker run -it --rm --env-file=.secret vincentdesmet/twitter_example:0.0.1 /bin/sh

this drops you in a ash shell (Alpine), from which you may run ./tweet.rb with arguments or wrapper with env vars

so0k commented 7 years ago

Todo:

so0k commented 7 years ago

2nd paragraph of https://cog-book.operable.io/#_authorization_rules has a broken link, the link should be: http://docs.operable.io/docs/command-execution-rules

kevsmith commented 7 years ago

@so0k Apologies for the slow review. We'll have some feedback for you soon.