rr3tt / rumbda

Run ruby scripts on aws lambda.
MIT License
105 stars 18 forks source link

Dockerized rumbda #6

Open bradleyjames opened 7 years ago

bradleyjames commented 7 years ago

TODO:

This creates a Docker image that encapsulates rumbda's dependencies to reduce the burden of running rumbda (i.e. ruby 2.2.2 and specific bundler version). It unfortunately results in a large image.

To build rumbda:

% gem build rumbda.gemspec 
WARNING:  no email specified
WARNING:  See http://guides.rubygems.org/specification-reference/ for help
  Successfully built RubyGem
  Name: rumbda
  Version: 1.2.0.SNAPSHOT
  File: rumbda-1.2.0.SNAPSHOT.gem

% docker build --build-arg VERSION=1.2.0.SNAPSHOT -t rumbda .
Sending build context to Docker daemon  461.8kB
Step 1/10 : FROM ruby:2.2.2
 ---> 81404453979d
Step 2/10 : RUN apt-get update &&     apt-get install zip unzip &&     gem uninstall -a bundler &&     gem install bundler -v 1.9.9
 ---> Using cache
 ---> c18b950704ef
Step 3/10 : ARG VERSION
 ---> Using cache
 ---> 0223c3d9223e
Step 4/10 : COPY rumbda-${VERSION}.gem /tmp
 ---> 6c8f393089b1
Removing intermediate container b7c321501639
Step 5/10 : WORKDIR /tmp
 ---> 2b7ca30d968e
Removing intermediate container a1fe7c8c7aeb
Step 6/10 : RUN gem install rumbda-${VERSION}.gem
 ---> Running in 5ab38d216553
Successfully installed thor-0.20.0
Successfully installed rumbda-1.2.0.SNAPSHOT
2 gems installed
 ---> 9620a748d4da
Removing intermediate container 5ab38d216553
Step 7/10 : RUN rm -rf /tmp
 ---> Running in 4e05a4dae6be
 ---> 73d4e84bdd5a
Removing intermediate container 4e05a4dae6be
Step 8/10 : VOLUME /src
 ---> Running in c5ba256a1053
 ---> 8d0ce5efe841
Removing intermediate container c5ba256a1053
Step 9/10 : WORKDIR /src
 ---> 2de72674d222
Removing intermediate container 913079c8fe6d
Step 10/10 : ENTRYPOINT rumbda
 ---> Running in d063782ad686
 ---> 04281af5d77d
Removing intermediate container d063782ad686
Successfully built 04281af5d77d
Successfully tagged rumbda:latest

To run rumbda:

 % docker run --rm -it -v "$PWD":/src rumbda:latest init
Created: /src/source
Created: /src/source/main.rb
Created: /src/.ruby-version
Created: /src/.gitignore
bradleyjames commented 7 years ago

On utility script topic I'm thinking of releasing a new project. All it would contain is the below bash script. The reason being that with multiple gemsets, as is the norm these days, if we relied on a ruby gem to install the utility script it would only be available when that gemset is enabled. This is just messy. So I'm thinking of creating an npm module instead with the guidance to install globally.

The below script allows for the setting of the version, defaulting to latest. The user could alias this to rumbda for a transparent migration to docker.

#!/bin/bash
#
# If wanting a specific version set VERSION
#
# Ex: 
#     VERSION=1.1 rumbda-docker help

if [ -z "$VERSION" ]; then
  # Default to the latest
  VERSION=latest
fi  

docker run --rm -it rumbda:$VERSION "$@"