[Tutorial] Build your centos7 lxd image and use it with juju

Building a custom centos7 image for use with juju

This is a walkthrough I made in my effort in trying to write centos7 charms which requires some actions to deploy with juju. This guide helps you set up a starting point for development with centos7 charms on lxd.

Lxd images displayed from “lxc list images:” are found here https://jenkins.linuxcontainers.org - I’m using the centos7 build definitions from there and modify them to fit juju. This is what it looks like on the build site. You can get both images and yaml files which is great! Thanx linuxcontainers for this!

Juju picks up lxd images aliased as ‘juju/<series>/amd64’ so, when adding machines with “–series centos7” your centos7 alias will be used. lxc list images: shows you the situation. You could probably try centos6 and centos8 aswell and test with “juju add-machine --series centos8” for example.

Mods needed

The upstream images needs to be the ‘cloud’ variant and needs to be modified
for juju to be happy:

  • We need to add the openssh-server & sudo packages.

But first, lets get the tool we need to build our images with.

Install distrobuilder

We need distrobuilder to create our lxd image.

snap install distrobuilder --classic

Get the image.yaml från https://jenkins.linuxcontainers.org

The yaml I used was this:

wget https://jenkins.linuxcontainers.org/view/Images/job/image-centos/architecture=amd64,release=7,variant=cloud/lastSuccessfulBuild/artifact/image.yaml

[edit] @Heitor seems to have had luck with this
https://github.com/lxc/lxc-ci/blob/master/images/centos.yaml

add sudo and openssh-server to the package list in the image.yaml.

packages:
  manager: yum
  update: true
  cleanup: true
  sets:
  - packages:
    - cronie
    - cronie-noanacron
    - curl
    - dhclient
    - initscripts
    - openssh-clients
    - passwd
    - policycoreutils
    - rootfiles
    - rsyslog
    - vim-minimal
    - openssh-server
    - sudo
    action: install

Build with correct options (architecture, release, variant)

sudo distrobuilder build-lxd image.yaml -o image.architecture=x86_64 -o image.release=7 -o image.variant=cloud

Import the image to your lxd (iceberg in my case)

lxc image import lxd.tar.xz rootfs.squashfs iceberg: --alias juju/centos7/amd64

Deploy a tinly centos7 charm (does nothing)

juju deploy cs:~erik-lonroth/tiny-bash-centos

If everything is ok you should also be able to
juju ssh tiny-bash/0

8 Likes

This file doesn’t seem to exist anymore … do you know where we can find that image.yaml file for centos7?

1 Like

I found this centos.yaml on GitHub: https://github.com/lxc/lxc-ci/blob/master/images/centos.yaml
But i’m not sure if it is the centos7 one.

1 Like

I can confirm that the centos.yaml from GitHub is the one to use here :slight_smile:

https://github.com/lxc/lxc-ci/blob/master/images/centos.yaml

2 Likes