canonical / rockcraft

Tool to create OCI Images using the language from Snapcraft and Charmcraft.
GNU General Public License v3.0
35 stars 43 forks source link

Building on Ubuntu with base bare image fails to add user and group #193

Closed arturo-seijas closed 1 year ago

arturo-seijas commented 1 year ago

Hi!

I currently have the following rockcraft.yaml where rockcraft pack is failing due to the files /etc/group and /etc/passwd not being present. Considering the I'm building on Ubuntu I would have expected those two files to be added to the bare image and staged.

name: indico-nginx
summary: Indico nginx rock
description: Nginx OCI image for the Indico charm
version: "1.0"
base: bare
build-base: ubuntu:22.04
license: Apache-2.0
platforms:
  amd64:
parts:
  add-user:
    plugin: nil
    overlay-script: |
      groupadd -R $CRAFT_OVERLAY --gid 2000 nginx
      useradd -R $CRAFT_OVERLAY --system --gid 2000 --uid 2000 --no-create-home nginx

Related to #23

Thank you

tigarmo commented 1 year ago

$CRAFT_OVERLAY has the mounted base, which in your case is bare. groupadd is complaining about the missing /etc, so you can fix that one:

    overlay-script: |
      mkdir $CRAFT_OVERLAY/etc
      chmod 755 $CRAFT_OVERLAY/etc
      groupadd -R $CRAFT_OVERLAY --gid 2000 nginx
      useradd -R $CRAFT_OVERLAY --system --gid 2000 --uid 2000 --no-create-home nginx

Because of the bare base, the resulting ROCK has just those two files (plus pebble).

arturo-seijas commented 1 year ago

That did the trick, thank you. I had tried adding the repository but it was failing due to the permission issues.