IronWorker Getting Started 3-Step Docker Workflow
Offload your tasks to the parallel-processing power of the elastic cloud. Write your code, then queue tasks against it—no servers to manage, no scaling to worry about.
Whats New? Why Docker?
- Development ENV == Local ENV Test workers locally in the exact same environment as when it’s running on the IronWorker cloud.
- Fast testing. No more wasted time like the older process of write code, upload (wait for build if doing remote build), queue a task, wait for it to run, view logs in HUD, repeat… Now you can test your worker locally in milliseconds.
- No Ruby dependency for the cli tool.
- No .worker file required. The .worker file defined all your dependencies, this is no longer required since you’re dependencies will be contained in your working directory.
- No cli tool magic. The previous cli tool did a lot of magic behind the scenes, packaging up dependencies and wrapping up your code to make it easy to run.
Note: The Docker Workflow is in BETA. Meaning changes to how the workflow and tool should be expected.
Setup
Before starting, you’ll need to setup a couple of things. You only need to do this once.
Hello World Worker
This is a very simple hello world example worker in Ruby. You don’t even need Ruby installed to try this example so give it a go! All languages follow the same process so you’ll get an idea of how things work regardless.
Create a file called helloworld.rb
containing:
Now let’s run it in one of the Iron stack containers:
The fact that it runs means it’s all good to run on IronWorker, so lets upload it and queue up a task for it so it runs on the IronWorker platform.
Let’s package it up first:
Then upload it:
Notice the –image parameter is the same as the Docker container we used above.
And finally queue up a job for it!
The --wait
parameter waits for the job to finish, then prints the output.
You will also see a link to HUD where you can see all the rest of the task details along with the log output.
That’s it, you’ve ran a worker on the IronWorker cloud platform!
Now let’s get into more detail.
1. Write and Test your Worker
IronWorker’s environment is a Linux Docker container that your task is executed in. Anything you write that runs inside of our published Docker images, or stacks should run just the same as on IronWorker. The key here is getting it to run with the Docker commands below and sample payloads.
The primary Docker command is:
- Replacing MY_STACK with one of our supported stacks
- Replace MY_COMMAND with what you’d like to execute. For instance, if your worker was a Ruby script called
myworker.rb
, you’d replace MY_COMMAND withruby myworker.rb
. If it was a Go program, you’d change it to./myworker
. - Replace MY_PAYLOAD with the name of an example payload file to test with. This payload file is the format that you’ll use to queue up jobs/tasks for your worker after it’s uploaded.
This command may seem simple at first glance, but the main thing is that it will force you to vendor all your dependencies along with your worker. You’ll find links to an example repository showing how to do this for various languages.
2. Package and Upload your Worker
Packing is pretty straightforward knowing that you got it working with the docker run
command above, just zip it up.
Then upload the zip you just created:
3. Queue Tasks for your Worker
Now you get to queue up tasks/jobs for your Worker!
Typically you’d use the IronWorker API to actually queue up tasks from other systems. The cli queue command above is primarily for testing purposes.