Skip to content

Commit

Permalink
Ubuntu 22 support (#770)
Browse files Browse the repository at this point in the history
- Added ubuntu 20 and 22 prerequisite installer scripts.
- Added ubuntu 22 to install script tests.
- Fixed ansible setup in install script.
  • Loading branch information
jonpugh authored Aug 29, 2023
1 parent 4bb0ca8 commit 3b6c8c3
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
# @TODO: Put back if it works.
# - 'ubuntu1804'
- 'ubuntu2004'
- 'ubuntu2204'

env:
OS: "${{ matrix.os }}"
Expand Down
105 changes: 105 additions & 0 deletions docker/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# DevShop Role Container Dockerfile Template
#
ARG DEVSHOP_CONTAINER_FROM=ubuntu:22.04
FROM $DEVSHOP_CONTAINER_FROM
ARG DEVSHOP_CONTAINER_FROM

LABEL maintainer="Jon Pugh"
RUN echo "Building container from Dockerfile.ubuntu2204, from $DEVSHOP_CONTAINER_FROM ..."

ARG DEBIAN_FRONTEND=noninteractive

# Fix for https://github.com/pypa/pip/issues/10219
ARG LANG="en_US.UTF-8"
ARG LC_ALL="en_US.UTF-8"

# For "run-quiet".
ENV OUTPUT all

# Copy devshop source to DEVSHOP_PATH.
ENV DEVSHOP_PATH /usr/share/devshop
ENV PATH="${DEVSHOP_PATH}/bin:${DEVSHOP_PATH}/scripts:${PATH}"

# Prepare server for services and ansible.
RUN echo "Running docker-systemd-prepare to install ansible and prepare container for services ...\n"
ENV DEVSHOP_ANSIBLE_PATH /etc/ansible

# Tell devshop-ansible-playbook what playbookfile to use.
ENV ANSIBLE_PLAYBOOK $DEVSHOP_PATH/roles/devshop.server/play.yml
ENV ANSIBLE_CONFIG $DEVSHOP_PATH/ansible.cfg

# Options passed to ansible-playbook during docker build.ENV DEVSHOP_ANSIBLE_BUILDTIME_OPTIONS "-vv --skip-tags runtime"
ENV DEVSHOP_ANSIBLE_BUILDTIME_OPTIONS ""

# Options passed to ansible-playbook during docker run or exec.
ENV DEVSHOP_ANSIBLE_RUNTIME_OPTIONS ""

# The command to run on container build
ENV DEFAULT_DEVSHOP_DOCKER_COMMAND_BUILD $DEVSHOP_PATH/scripts/devshop-ansible-playbook \
$DEVSHOP_ANSIBLE_BUILDTIME_OPTIONS

# Set DEVSHOP_DOCKER_COMMAND_BUILD from the Default so we can unset it later.
ENV DEVSHOP_DOCKER_COMMAND_BUILD $DEFAULT_DEVSHOP_DOCKER_COMMAND_BUILD

# The command to run when the container starts.
ENV DEFAULT_DEVSHOP_DOCKER_COMMAND_RUN $DEVSHOP_PATH/scripts/devshop-ansible-playbook \
$DEVSHOP_ANSIBLE_RUNTIME_OPTIONS

# Set DEVSHOP_DOCKER_COMMAND_RUN from the Default so we can unset it later.
ENV DEVSHOP_DOCKER_COMMAND_RUN $DEFAULT_DEVSHOP_DOCKER_COMMAND_RUN

# Run ansible-playbook again with build-time options.
ARG ANSIBLE_TAGS_ARG
ENV ANSIBLE_TAGS ${ANSIBLE_TAGS_ARG:-buildtime}

# Run ansible-playbook again with build-time options.
ARG ANSIBLE_EXTRA_VARS_ARG
ENV ANSIBLE_EXTRA_VARS ${ANSIBLE_EXTRA_VARS_ARG}

# Run ansible-playbook again with build-time options.
ARG ANSIBLE_PLAYBOOK_COMMAND_OPTIONS_ARG
ENV ANSIBLE_PLAYBOOK_COMMAND_OPTIONS ${ANSIBLE_PLAYBOOK_COMMAND_OPTIONS_ARG:-$ANSIBLE_PLAYBOOK_COMMAND_OPTIONS}

ARG DEVSHOP_DOCKER_COMMAND_BUILD_ARG
ENV DEVSHOP_DOCKER_COMMAND_BUILD ${DEVSHOP_DOCKER_COMMAND_BUILD_ARG:-$DEVSHOP_DOCKER_COMMAND_BUILD}

RUN rm -rf $DEVSHOP_PATH
COPY ./ $DEVSHOP_PATH
RUN echo "Copied DevShop Source into container."

ENV OUTPUT err

# Replace ansible inventory with symlink to devshop.server inventory.
RUN mkdir -p ${DEVSHOP_ANSIBLE_PATH}
RUN rm -rf ${DEVSHOP_ANSIBLE_PATH}/hosts && ln -s ${DEVSHOP_PATH}/roles/devshop.server/inventory ${DEVSHOP_ANSIBLE_PATH}/hosts

RUN ${DEVSHOP_PATH}/scripts/run-quiet ${DEVSHOP_PATH}/docker/bin/docker-systemd-prepare
RUN ${DEVSHOP_PATH}/scripts/run-quiet ${DEVSHOP_PATH}/install/devshop-install-prerequisites.sh

RUN echo "Running $DEVSHOP_ANSIBLE_INVENTORY_INFO_COMMAND ...\n" && \
$DEVSHOP_ANSIBLE_INVENTORY_INFO_COMMAND

RUN \
echo "Ansible Directory: `ls -la ${DEVSHOP_ANSIBLE_PATH}`" &&\
echo "Ansible Inventory: `cat ${DEVSHOP_ANSIBLE_PATH}/hosts`" &&\
echo "Ansible Inventory: `ansible-inventory --yaml --list`" &&\
echo "Ansible Playbook: `cat ${ANSIBLE_PLAYBOOK}`" &&\
echo "Environment: `env`"


# Run the docker build command.
RUN echo "Running $DEVSHOP_DOCKER_COMMAND_BUILD ...\n" && \
$DEVSHOP_DOCKER_COMMAND_BUILD

# Set ANSIBLE_TAGS back to runtime so the new container uses it.
ENV ANSIBLE_TAGS=runtime

# VOLUME ["/sys/fs/cgroup", "/tmp", "/run"]

WORKDIR /var/aegir

ENV INIT_COMMAND /lib/systemd/systemd
ENTRYPOINT [/usr/share/devshop/docker/bin/docker-systemd-entrypoint]

RUN devshop-logo 'DevShop Server build finished.'
53 changes: 53 additions & 0 deletions docker/bin/docker-systemd-prepare
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ get_distribution() {
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
}

# From https://github.com/geerlingguy/docker-ubuntu2204-ansible/blob/master/Dockerfile
prepare_ubuntu2204() {
PYTHON_DEFAULT=/usr/bin/python3
DEBIAN_FRONTEND=noninteractive
pip_packages="ansible"

apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
curl \
git \
locales \
libffi-dev \
libssl-dev \
libyaml-dev \
python3-dev \
python3-setuptools \
python3-pip \
python3-yaml \
python-is-python3 \
software-properties-common \
rsyslog systemd systemd-cron sudo iproute2 \
&& apt-get clean \
&& rm -Rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man

locale-gen en_US.UTF-8
sed -i 's/^\($ModLoad imklog\)/#\1/' /etc/rsyslog.conf

# Install the initctl faker script from @geerlingguy
initctl_faker_url="https://raw.githubusercontent.com/geerlingguy/docker-ubuntu2204-ansible/master/initctl_faker"
initctl_faker_path="/sbin/initctl"

curl -ksSL $initctl_faker_url -o $initctl_faker_path
chmod +x $initctl_faker_path

rm -f /lib/systemd/system/systemd*udev* \
&& rm -f /lib/systemd/system/getty.target

# Set Python3 to be the default (allow users to call "python" and "pip" instead of "python3" "pip3"
update-alternatives --install /usr/bin/python python /usr/bin/python3 1

pip3 install $pip_packages
}

# From https://github.com/geerlingguy/docker-ubuntu2004-ansible/blob/master/Dockerfile
prepare_ubuntu2004() {
PYTHON_DEFAULT=/usr/bin/python3
Expand Down Expand Up @@ -168,6 +215,9 @@ case "$lsb_dist" in
"20.04")
dist_version_name="focal"
;;
"22.04")
dist_version_name="jammy"
;;
esac
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
Expand Down Expand Up @@ -220,6 +270,9 @@ case "$lsb_dist $dist_version" in
"ubuntu 20.04")
prepare_ubuntu2004
;;
"ubuntu 22.04")
prepare_ubuntu2204
;;
"ubuntu 18.04")
prepare_ubuntu1804
;;
Expand Down
33 changes: 33 additions & 0 deletions install/Dockerfile.ubuntu2204
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# DevShop Role Container Dockerfile Template
#
FROM ubuntu:22.04
LABEL maintainer="Jon Pugh"

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
locales \
software-properties-common \
rsyslog systemd systemd-cron sudo iproute2 \
&& apt-get clean \
&& rm -Rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man

# Fix potential UTF-8 errors with ansible-test.
RUN locale-gen en_US.UTF-8

RUN sed -i 's/^\($ModLoad imklog\)/#\1/' /etc/rsyslog.conf

COPY initctl_faker .
RUN chmod +x initctl_faker && rm -fr /sbin/initctl && ln -s /initctl_faker /sbin/initctl

# Remove unnecessary getty and udev targets that result in high CPU usage when using
# multiple containers with Molecule (https://github.com/ansible/molecule/issues/1104)
RUN rm -f /lib/systemd/system/systemd*udev* \
&& rm -f /lib/systemd/system/getty.target

CMD ["/lib/systemd/systemd"]
35 changes: 35 additions & 0 deletions install/devshop-install-prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ get_distribution() {
echo "$lsb_dist"
}

# From https://github.com/geerlingguy/docker-ubuntu2204-ansible/blob/master/Dockerfile
prepare_ubuntu2204() {
PYTHON_DEFAULT=/usr/bin/python3
DEBIAN_FRONTEND=noninteractive
pip_packages="ansible"

apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
git \
locales \
libffi-dev \
libssl-dev \
libyaml-dev \
python3-dev \
python3-setuptools \
python3-pip \
python3-yaml \
python-is-python3 \
software-properties-common \
rsyslog systemd systemd-cron sudo iproute2 \
&& apt-get clean \
&& rm -Rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man

# Set Python3 to be the default (allow users to call "python" and "pip" instead of "python3" "pip3"
update-alternatives --install /usr/bin/python python /usr/bin/python3 1

pip3 install $pip_packages
}

# From https://github.com/geerlingguy/docker-ubuntu2004-ansible/blob/master/Dockerfile
prepare_ubuntu2004() {
PYTHON_DEFAULT=/usr/bin/python3
Expand Down Expand Up @@ -191,6 +223,9 @@ echo "OS Detected: $lsb_dist $dist_version ($dist_version_name)"

# Break out preparation into separate functions.
case "$lsb_dist $dist_version" in
"ubuntu 22.04")
prepare_ubuntu2204
;;
"ubuntu 20.04")
prepare_ubuntu2004
;;
Expand Down
53 changes: 47 additions & 6 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SCRIPT_DEVSHOP_VERSION_REF="${LOAD_SCRIPT_DEVSHOP_VERSION_REF}"
# The version and git repo to install.
# Default to 1.x if $SCRIPT_DEVSHOP_VERSION is empty.
# Used as the `devshop_version` ansible variable, which will change the checked out version.
DEVSHOP_VERSION="${SCRIPT_DEVSHOP_VERSION_REF:-1.x}"
DEVSHOP_VERSION="${SCRIPT_DEVSHOP_VERSION_REF}"
DEVSHOP_SOURCE="${LOAD_DEVSHOP_SOURCE:-http://github.com/opendevshop/devshop.git}"

# Version of Ansible to install
Expand All @@ -67,6 +67,9 @@ while [ $# -gt 0 ]; do
--hostname=*)
HOSTNAME_FQDN="${1#*=}"
;;
--version=*)
DEVSHOP_VERSION="${1#*=}"
;;
--install-path=*)
DEVSHOP_INSTALL_PATH="${1#*=}"
;;
Expand Down Expand Up @@ -107,6 +110,8 @@ while [ $# -gt 0 ]; do
shift $(( $# > 0 ? 1 : 0 ))
done

DEVSHOP_VERSION=${DEVSHOP_VERSION:-1.x}

# Initial Ansible Variables
# Generate host specific vars to be injected into inventory.
# All command line options that are ansible variables should be saved here.
Expand Down Expand Up @@ -226,6 +231,38 @@ get_distribution_version() {
echo "$dist_version"
}

# From https://github.com/geerlingguy/docker-ubuntu2204-ansible/blob/master/Dockerfile
prepare_ubuntu2204() {
PYTHON_DEFAULT=/usr/bin/python3
DEBIAN_FRONTEND=noninteractive
pip_packages="ansible"

apt-get update \
&& apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
git \
locales \
libffi-dev \
libssl-dev \
libyaml-dev \
python3-dev \
python3-setuptools \
python3-pip \
python3-yaml \
python-is-python3 \
software-properties-common \
rsyslog systemd systemd-cron sudo iproute2 \
&& apt-get clean \
&& rm -Rf /var/lib/apt/lists/* \
&& rm -Rf /usr/share/doc && rm -Rf /usr/share/man

# Set Python3 to be the default (allow users to call "python" and "pip" instead of "python3" "pip3"
update-alternatives --install /usr/bin/python python /usr/bin/python3 1

pip3 install $pip_packages
}

# From https://github.com/geerlingguy/docker-ubuntu2004-ansible/blob/master/Dockerfile
prepare_ubuntu2004() {
PYTHON_DEFAULT=/usr/bin/python3
Expand Down Expand Up @@ -300,9 +337,9 @@ prepare_centos7() {

ansible_prepare_server() {
ANSIBLE_HOME=$(dirname "$ANSIBLE_DEFAULT_HOST_LIST")
if [[ ! -d "$ANSIBLE_HOME" ]]; then
if [[ ! -d "$ANSIBLE_HOME/host_vars/$HOSTNAME_FQDN" ]]; then
echo "No ansible home directory found at $ANSIBLE_HOME. Preparing..."
mkdir --parent "$ANSIBLE_HOME"
mkdir --parent "$ANSIBLE_HOME/host_vars/$HOSTNAME_FQDN"
fi
if [[ ! -f "$ANSIBLE_DEFAULT_HOST_LIST" ]]; then
echo "No ansible inventory found at $ANSIBLE_DEFAULT_HOST_LIST. Preparing inventory..."
Expand All @@ -327,11 +364,12 @@ ansible_prepare_server_inventory() {
devshop_server:
hosts:
$HOSTNAME_FQDN:
vars:" > $ANSIBLE_DEFAULT_HOST_LIST
" > $ANSIBLE_DEFAULT_HOST_LIST

# Write all extra vars to the file.
ANSIBLE_DEFAULT_HOST_VARS_FILE="/etc/ansible/host_vars/${HOSTNAME_FQDN}/devshop"
for i in ${ANSIBLE_EXTRA_VARS[@]}; do
echo -e " $i" >> $ANSIBLE_DEFAULT_HOST_LIST
echo -e "$i" >> $ANSIBLE_DEFAULT_HOST_VARS_FILE
done
echo $LINE
echo "Wrote static inventory to $ANSIBLE_DEFAULT_HOST_LIST:";
Expand Down Expand Up @@ -473,6 +511,9 @@ echo $LINE
echo " Installing prerequisites (ansible, git etc)..."

case "$lsb_dist $dist_version" in
"ubuntu 22.04")
prepare_ubuntu2204 > /dev/null
;;
"ubuntu 20.04")
prepare_ubuntu2004 > /dev/null
;;
Expand Down Expand Up @@ -568,7 +609,7 @@ ansible_prepare_server

# Run the playbook.
echo $LINE
echo " Installing with Ansible..."
echo " Installing with devshop-ansible-playbook..."
echo $LINE

# If ansible playbook fails syntax check, report it and exit.
Expand Down
1 change: 1 addition & 0 deletions roles/devshop.server/play.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- "Tags: {{ ansible_run_tags }}"
- "ansible_nodename: {{ ansible_nodename }}"
- "OS: {{ ansible_distribution }} {{ ansible_distribution_version }} / {{ ansible_os_family }}"
- "server_hostname: {{ server_hostname }}"


vars_files:
Expand Down

0 comments on commit 3b6c8c3

Please sign in to comment.