demo: use unshare for rootless invocations

Use `buildah unshare` to invoke `buildah mount` when demos are invoked
from rootless environments

* buildah_mult_stage: only unshare on needed steps
* buildah-scratch-demo: unshare entire script since it uses pkg managers
  commands which don't work well in rootless session without unshare.

[NO NEW TESTS NEEDED]

Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
Aditya R 2022-06-20 14:56:28 +05:30
parent ddc4ea603a
commit 404852be4a
No known key found for this signature in database
GPG Key ID: 8E5A8A19DF7C8673
3 changed files with 41 additions and 1 deletions

View File

@ -25,7 +25,15 @@ This demo builds a container image from scratch. The container is going to injec
Please make sure you have installed Buildah and Podman. Also this demo uses Quay.io to push the image to that registry when it is completed. If you are not logged in then it will fail at that step and finish. If you wish to login to Quay.io before running the demo, then it will push to your repository successfully. Please make sure you have installed Buildah and Podman. Also this demo uses Quay.io to push the image to that registry when it is completed. If you are not logged in then it will fail at that step and finish. If you wish to login to Quay.io before running the demo, then it will push to your repository successfully.
$ sudo buildah login quay.io ```bash
# Rootful session
$ sudo buildah login quay.io
#
# or
#
# Rootless session
$ buildah login quay.io
```
There are several variables you will want to set that are listed at the top of the script. The name for the container image, your quay.io username, your name, and the Fedora release number: There are several variables you will want to set that are listed at the top of the script. The name for the container image, your quay.io username, your name, and the Fedora release number:

View File

@ -7,6 +7,22 @@
# buildah login quay.io # buildah login quay.io
# Set some of the variables below # Set some of the variables below
#################
# is_rootless # Check if we run as normal user
#################
function is_rootless() {
[ "$(id -u)" -ne 0 ]
}
## Steps in this demo use pkg-managers like dnf and yum which
## must be invoked as root. Similarly `buildah mount` only work
## as root. The `buildah unshare` command switches your user
## session to root within the user namespace.
if is_rootless; then
buildah unshare $0
exit
fi
demoimg=myshdemo demoimg=myshdemo
quayuser=ipbabble quayuser=ipbabble
myname=WilliamHenry myname=WilliamHenry

View File

@ -5,6 +5,22 @@
# Assumptions install buildah and podman # Assumptions install buildah and podman
# Set some of the variables below # Set some of the variables below
#################
# is_rootless # Check if we run as normal user
#################
function is_rootless() {
[ "$(id -u)" -ne 0 ]
}
## The `buildah mount` only work as root so use
## `buildah unshare` command which switches your
## user session to root within the user namespace.
if is_rootless; then
buildah unshare $0
exit
fi
demoimg=mymultidemo demoimg=mymultidemo
quayuser=myquayuser quayuser=myquayuser
myname=MyName myname=MyName