Create a ROCK from a PyPI package¶
By the end of this tutorial you will be able to run pyfiglet via docker:
$ docker run --rm -it pyfiglet:0.7.6 exec pyfiglet hello
_ _ _
| |__ ___| | | ___
| '_ \ / _ \ | |/ _ \
| | | | __/ | | (_) |
|_| |_|\___|_|_|\___/
Prerequisites¶
snap enabled system (https://snapcraft.io)
LXD installed (https://linuxcontainers.org/lxd/getting-started-cli/)
skopeo installed (https://github.com/containers/skopeo). Skopeo will also be automatically installed as a Rockcraft dependency
Docker installed (https://snapcraft.io/docker)
Rockcraft installed
a text editor
Project Setup¶
To create a new Rockcraft project, create a new directory and change into it:
mkdir pyfiglet-rock && cd pyfiglet-rock
Next, create a file called rockcraft.yaml
with the following contents:
name: pyfiglet
base: ubuntu:22.04
version: '0.7.6' # Note: should match `pyfiglet` below
summary: A ROCK for pyfiglet
description: A ROCK for pyfiglet
license: Apache-2.0
platforms:
amd64:
parts:
pyfiglet:
plugin: python
source: .
python-packages:
- pyfiglet==0.7.6 # Note: should match `version` above
stage-packages:
- python3-venv
Pack the ROCK with Rockcraft¶
To build the ROCK, run:
rockcraft
Run the ROCK in Docker¶
First, import the recently created ROCK into Docker:
sudo /snap/rockcraft/current/bin/skopeo --insecure-policy copy oci-archive:pyfiglet_0.7.6_amd64.rock docker-daemon:pyfiglet:0.7.6
Now run the pyfiglet
command from the ROCK:
docker run --rm pyfiglet:0.7.6 exec pyfiglet it works!
Which should print:
_ _ _ _
(_) |_ __ _____ _ __| | _____| |
| | __| \ \ /\ / / _ \| '__| |/ / __| |
| | |_ \ V V / (_) | | | <\__ \_|
|_|\__| \_/\_/ \___/|_| |_|\_\___(_)
Explore the running container¶
Since the ROCK uses an ubuntu base, you can poke around in a running container using bash, via:
$ docker run --rm -it pyfiglet:0.7.6 exec bash
root@14d1812a2681:/# pyfiglet hi
_ _
| |__ (_)
| '_ \| |
| | | | |
|_| |_|_|