Create a “Hello World” ROCK#

Prerequisites#

Install Rockcraft#

Install Rockcraft on your host:

sudo snap install rockcraft --classic --edge

Project Setup#

Create a new directory and write the following into a text editor and save it as rockcraft.yaml:

name: hello
summary: Hello World
description: The most basic example of a ROCK.
version: "1.0"
base: ubuntu:20.04
license: Apache-2.0
cmd: [/usr/bin/hello, -t]
platforms:
  amd64:  # Make sure this value matches your computer's architecture

parts:
  hello:
    plugin: nil
    overlay-packages:
      - hello

Pack the ROCK with Rockcraft#

To build the ROCK, run:

rockcraft pack

The output should look as follows:

Launching instance...
Retrieved base ubuntu:20.04
Extracted ubuntu:20.04
Executed: pull hello
Executed: overlay hello
Executed: build hello
Executed: stage hello
Executed: prime hello
Executed parts lifecycle
Created new layer
Cmd set to ['/usr/bin/hello', '-t']
Labels and annotations set to ['org.opencontainers.image.version=1.0', 'org.opencontainers.image.title=hello', 'org.opencontainers.image.ref.name=hello', 'org.opencontainers.image.licenses=Apache-2.0', 'org.opencontainers.image.created=2022-06-30T09:07:38.124741+00:00']
Exported to OCI archive 'hello_1.0_amd64.rock'

At the end of the process, a file named hello_1.0_amd64.rock should be present in the current directory. That’s your ROCK, in oci-archive format (a tarball).

Run the ROCK in Docker#

First, import the recently created ROCK into Docker:

sudo /snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:hello_1.0_amd64.rock docker-daemon:hello:1.0

Now run the hello command from the ROCK:

docker run --rm hello:1.0

Which should print:

hello, world