Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offer built-in support for Ubuntu and ubuntu-toolbox image definitions #1284

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions images/ubuntu/16.04/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM docker.io/library/ubuntu:16.04

LABEL com.github.containers.toolbox="true" \
name="ubuntu-toolbox" \
version="16.04" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Ubuntu toolbox containers" \
maintainer="Ievgen Popovych <jmennius@gmail.com>"

# Remove apt configuration optimized for containers
# Remove docker-gzip-indexes to help with "command-not-found"
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Enable myhostname nss plugin for clean hostname resolution without patching
# hosts (at least for sudo), add it right after 'files' entry. We expect that
# this entry is not present yet. Do this early so that package postinst (which
# adds it too late in the order) skips this step
RUN sed -Ei 's/^(hosts:.*)(\<files\>)\s*(.*)/\1\2 myhostname \3/' /etc/nsswitch.conf

# Install ubuntu-minimal & ubuntu-standard
# Ask resolvconf maintainer script not to touch resolve.conf file
# Install extra packages as well as libnss-myhostname
COPY extra-packages /
RUN apt-get update && \
echo "resolvconf resolvconf/linkify-resolvconf boolean false" | debconf-set-selections && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ubuntu-minimal ubuntu-standard \
libnss-myhostname \
$(cat extra-packages | xargs) && \
rm -rd /var/lib/apt/lists/*
RUN rm /extra-packages

# Allow authentication with empty password, promptless
RUN sed -i '/^auth.*pam_unix.so/s/nullok_secure/try_first_pass nullok/' /etc/pam.d/common-auth

# Fix empty bind-mount to clear selinuxfs (see #337)
RUN mkdir /usr/share/empty
8 changes: 8 additions & 0 deletions images/ubuntu/16.04/extra-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
curl
git
gnupg2
keyutils
tree
unzip
zip
zsh
37 changes: 37 additions & 0 deletions images/ubuntu/18.04/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM docker.io/library/ubuntu:18.04

LABEL com.github.containers.toolbox="true" \
name="ubuntu-toolbox" \
version="18.04" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Ubuntu toolbox containers" \
maintainer="Ievgen Popovych <jmennius@gmail.com>"

# Remove apt configuration optimized for containers
# Remove docker-gzip-indexes to help with "command-not-found"
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Enable myhostname nss plugin for clean hostname resolution without patching
# hosts (at least for sudo), add it right after 'files' entry. We expect that
# this entry is not present yet. Do this early so that package postinst (which
# adds it too late in the order) skips this step
RUN sed -Ei 's/^(hosts:.*)(\<files\>)\s*(.*)/\1\2 myhostname \3/' /etc/nsswitch.conf

# Restore documentation but do not upgrade all packages
# Install extra packages as well as libnss-myhostname
COPY extra-packages /
RUN sed -Ei '/apt-get (update|upgrade)/s/^/#/' /usr/local/sbin/unminimize && \
apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard \
libnss-myhostname \
$(cat extra-packages | xargs) && \
rm -rd /var/lib/apt/lists/*
RUN rm /extra-packages

# Allow authentication with empty password, promptless
RUN sed -i '/^auth.*pam_unix.so/s/nullok_secure/try_first_pass nullok/' /etc/pam.d/common-auth

# Fix empty bind-mount to clear selinuxfs (see #337)
RUN mkdir /usr/share/empty
8 changes: 8 additions & 0 deletions images/ubuntu/18.04/extra-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
curl
git
gnupg2
keyutils
tree
unzip
zip
zsh
41 changes: 41 additions & 0 deletions images/ubuntu/20.04/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM docker.io/library/ubuntu:20.04

LABEL com.github.containers.toolbox="true" \
name="ubuntu-toolbox" \
version="20.04" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Ubuntu toolbox containers" \
maintainer="Ievgen Popovych <jmennius@gmail.com>"

# Remove apt configuration optimized for containers
# Remove docker-gzip-indexes to help with "command-not-found"
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Enable myhostname nss plugin for clean hostname resolution without patching
# hosts (at least for sudo), add it right after 'files' entry. We expect that
# this entry is not present yet. Do this early so that package postinst (which
# adds it too late in the order) skips this step
RUN sed -Ei 's/^(hosts:.*)(\<files\>)\s*(.*)/\1\2 myhostname \3/' /etc/nsswitch.conf

# Restore documentation but do not upgrade all packages
# Install ubuntu-minimal & ubuntu-standard
# Install extra packages as well as libnss-myhostname
COPY extra-packages /
RUN sed -Ei '/apt-get (update|upgrade)/s/^/#/' /usr/local/sbin/unminimize && \
apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard \
libnss-myhostname \
$(cat extra-packages | xargs) && \
rm -rd /var/lib/apt/lists/*
RUN rm /extra-packages

# Allow authentication with empty password, promptless
RUN sed -i '/^auth.*pam_unix.so/s/nullok_secure/try_first_pass nullok/' /etc/pam.d/common-auth

# Fix empty bind-mount to clear selinuxfs (see #337)
RUN mkdir /usr/share/empty

# Add flatpak-spawn to /usr/bin
RUN ln -s /usr/libexec/flatpak-xdg-utils/flatpak-spawn /usr/bin/
9 changes: 9 additions & 0 deletions images/ubuntu/20.04/extra-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl
flatpak-xdg-utils
git
gnupg2
keyutils
tree
unzip
zip
zsh
38 changes: 38 additions & 0 deletions images/ubuntu/22.04/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM docker.io/library/ubuntu:22.04

LABEL com.github.containers.toolbox="true" \
name="ubuntu-toolbox" \
version="22.04" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Ubuntu toolbox containers" \
maintainer="Ievgen Popovych <jmennius@gmail.com>"

# Remove apt configuration optimized for containers
# Remove docker-gzip-indexes to help with "command-not-found"
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Enable myhostname nss plugin for clean hostname resolution without patching
# hosts (at least for sudo), add it right after 'files' entry. We expect that
# this entry is not present yet. Do this early so that package postinst (which
# adds it too late in the order) skips this step
RUN sed -Ei 's/^(hosts:.*)(\<files\>)\s*(.*)/\1\2 myhostname \3/' /etc/nsswitch.conf

# Restore documentation but do not upgrade all packages
# Install ubuntu-minimal & ubuntu-standard
# Install extra packages as well as libnss-myhostname
COPY extra-packages /
RUN sed -Ei '/apt-get (update|upgrade)/s/^/#/' /usr/local/sbin/unminimize && \
apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard \
libnss-myhostname \
$(cat extra-packages | xargs) && \
rm -rd /var/lib/apt/lists/*
RUN rm /extra-packages

# Fix empty bind-mount to clear selinuxfs (see #337)
RUN mkdir /usr/share/empty

# Add flatpak-spawn to /usr/bin
RUN ln -s /usr/libexec/flatpak-xdg-utils/flatpak-spawn /usr/bin/
9 changes: 9 additions & 0 deletions images/ubuntu/22.04/extra-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl
flatpak-xdg-utils
git
gnupg2
keyutils
tree
unzip
zip
zsh
38 changes: 38 additions & 0 deletions images/ubuntu/22.10/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM docker.io/library/ubuntu:22.10

LABEL com.github.containers.toolbox="true" \
name="ubuntu-toolbox" \
version="22.10" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Ubuntu toolbox containers" \
maintainer="Ievgen Popovych <jmennius@gmail.com>"

# Remove apt configuration optimized for containers
# Remove docker-gzip-indexes to help with "command-not-found"
RUN rm /etc/apt/apt.conf.d/docker-gzip-indexes /etc/apt/apt.conf.d/docker-no-languages

# Enable myhostname nss plugin for clean hostname resolution without patching
# hosts (at least for sudo), add it right after 'files' entry. We expect that
# this entry is not present yet. Do this early so that package postinst (which
# adds it too late in the order) skips this step
RUN sed -Ei 's/^(hosts:.*)(\<files\>)\s*(.*)/\1\2 myhostname \3/' /etc/nsswitch.conf

# Restore documentation but do not upgrade all packages
# Install ubuntu-minimal & ubuntu-standard
# Install extra packages as well as libnss-myhostname
COPY extra-packages /
RUN sed -Ei '/apt-get (update|upgrade)/s/^/#/' /usr/local/sbin/unminimize && \
apt-get update && \
yes | /usr/local/sbin/unminimize && \
DEBIAN_FRONTEND=noninteractive apt-get -y install \
ubuntu-minimal ubuntu-standard \
libnss-myhostname \
$(cat extra-packages | xargs) && \
rm -rd /var/lib/apt/lists/*
RUN rm /extra-packages

# Fix empty bind-mount to clear selinuxfs (see #337)
RUN mkdir /usr/share/empty

# Add flatpak-spawn to /usr/bin
RUN ln -s /usr/libexec/flatpak-xdg-utils/flatpak-spawn /usr/bin/
9 changes: 9 additions & 0 deletions images/ubuntu/22.10/extra-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
curl
flatpak-xdg-utils
git
gnupg2
keyutils
tree
unzip
zip
zsh
55 changes: 55 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"syscall"
"time"
"unicode/utf8"

"github.com/acobaugh/osrelease"
"github.com/containers/toolbox/pkg/shell"
Expand Down Expand Up @@ -108,6 +109,12 @@ var (
getFullyQualifiedImageRHEL,
parseReleaseRHEL,
},
"ubuntu": {
"ubuntu-toolbox",
"ubuntu-toolbox",
getFullyQualifiedImageUbuntu,
parseReleaseUbuntu,
},
}
)

Expand Down Expand Up @@ -343,6 +350,11 @@ func getFullyQualifiedImageRHEL(image, release string) string {
return imageFull
}

func getFullyQualifiedImageUbuntu(image, release string) string {
imageFull := "quay.io/toolbx-images/" + image
return imageFull
}

// GetGroupForSudo returns the name of the sudoers group.
//
// Some distros call it 'sudo' (eg. Ubuntu) and some call it 'wheel' (eg. Fedora).
Expand Down Expand Up @@ -672,6 +684,49 @@ func parseReleaseRHEL(release string) (string, error) {
return release, nil
}

func parseReleaseUbuntu(release string) (string, error) {
releaseParts := strings.Split(release, ".")
if len(releaseParts) != 2 {
return "", &ParseReleaseError{"The release must be in the 'YY.MM' format."}
}

releaseYear, err := strconv.Atoi(releaseParts[0])
if err != nil {
logrus.Debugf("Parsing release year %s as an integer failed: %s", releaseParts[0], err)
return "", &ParseReleaseError{"The release must be in the 'YY.MM' format."}
}

if releaseYear < 4 {
return "", &ParseReleaseError{"The release year must be 4 or more."}
}

releaseYearLen := utf8.RuneCountInString(releaseParts[0])
if releaseYearLen > 2 {
return "", &ParseReleaseError{"The release year cannot have more than two digits."}
} else if releaseYear < 10 && releaseYearLen == 2 {
return "", &ParseReleaseError{"The release year cannot have a leading zero."}
}

releaseMonth, err := strconv.Atoi(releaseParts[1])
if err != nil {
logrus.Debugf("Parsing release month %s as an integer failed: %s", releaseParts[1], err)
return "", &ParseReleaseError{"The release must be in the 'YY.MM' format."}
}

if releaseMonth < 1 {
return "", &ParseReleaseError{"The release month must be between 01 and 12."}
} else if releaseMonth > 12 {
return "", &ParseReleaseError{"The release month must be between 01 and 12."}
}

releaseMonthLen := utf8.RuneCountInString(releaseParts[1])
if releaseMonthLen != 2 {
return "", &ParseReleaseError{"The release month must have two digits."}
}

return release, nil
}

// PathExists wraps around os.Stat providing a nice interface for checking an existence of a path.
func PathExists(path string) bool {
if _, err := os.Stat(path); !os.IsNotExist(err) {
Expand Down
Loading