Evan Appleby
Evan Appleby

Reputation: 352

How can I launch an IronWorker with Docker without needing to pay for private Docker repositories, nor make my code public?

I have multiple Ruby applications that are run in crons using IronWorker. I am new to Docker and I want to test the application locally before pushing the code to Iron. How do I do that?

Upvotes: 1

Views: 277

Answers (1)

Evan Appleby
Evan Appleby

Reputation: 352

Your code can be stored privately on Iron.io and the image on Docker can include only the programming language and libraries and be made public. I've put together a "hello world" example showing how it can be done. I am using Alpine linux and the Ruby programming language along with Iron's dev packages. I also included the "pg" gem:

hello.rb

require 'pg'
puts "hello world"

Gemfile

source 'https://rubygems.org'
gem 'pg'

Dockerfile

FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
COPY hello.rb /
RUN apk add bash

Here are the steps to get this running:

  1. Create public repository on Docker

In this example, the name of the Docker username is testuser and the name of the Docker repository is testrepo.

  1. Build image

Run the following command in a Docker Terminal. I have added a tag "0.0.1". This should be incremented with each change to the image that is pushed to Docker.

docker build -t testuser/testrepo:0.0.1 .
  1. Test image

Since the Dockerfile did not include an ENTRYPOINT ["ruby", "hello.rb"] line, any terminal command can be included in a "docker run" command. To get into an image with a bash prompt, you would run:

docker run -it testuser/testrepo:0.0.1 /bin/bash

Once inside of bash, you can then see if the code can be executed:

ruby hello.rb

In this example, I received the following error:

`require': cannot load such file -- json (LoadError)

To fix that, update the Dockerfile to install json and then re-test the image. Here is the updated Dockerfile:

FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
RUN gem install json --no-ri --no-rdoc
COPY hello.rb /
RUN apk add bash

Now that we know the code will run correctly with the image, we can update the Dockerfile and push the image to Docker and the code to Iron.

  1. Remove hello.rb from folder and update Dockerfile

FROM iron/ruby-2.3:dev
RUN apk update && apk upgrade
RUN gem install pg --no-ri --no-rdoc
RUN gem install json --no-ri --no-rdoc
RUN apk add bash

  1. Re-build image

docker build -t testuser/testrepo:0.0.1 .

  1. Push image to Docker

docker push testuser/testrepo:0.0.1

  1. Register image with Iron (need iron.json file in current working directory)

iron register testuser/testrepo:0.0.1

  1. Zip IronWorker code

zip -r hello.zip hello.rb

  1. Upload worker to Iron (need iron.json file in current working directory)

iron worker upload --zip hello.zip --name hello testuser/testrepo:0.0.1 ruby hello.rb

Done! You can now schedule an IronWorker through the HUD or through their API.

Upvotes: 0

Related Questions