add podman capability during packaging
Allow the pulls and saves during packaging to be done using podman which will allow the docker.io repos to be proxied
Change-Id: I1f6f056aba333d32056ff312b0ef31db97c6943c
Signed-off-by: afenner <andrew.fenner@est.tech>
diff --git a/package.sh b/package.sh
index 87777a4..e2e78c9 100755
--- a/package.sh
+++ b/package.sh
@@ -26,6 +26,8 @@
#-------------------------------------------------------------------------------
STACK_ROOT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
export STACK_ROOT_DIR
+# set default command to use for container command
+CONTAINER_TOOL="${CONTAINER_TOOL:-"docker"}"
#-------------------------------------------------------------------------------
# Start packaging process
@@ -33,7 +35,7 @@
echo "Info : Start packaging process"
echo "-------------------------------------------------------------------------"
cd "${ENGINE_PATH}"
-ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
+ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" -e containertool="${CONTAINER_TOOL}" \
-i "${ENGINE_PATH}/engine/inventory/localhost.ini" \
"${STACK_ROOT_DIR}/playbooks/package.yaml"
echo "-------------------------------------------------------------------------"
diff --git a/playbooks/roles/package/files/pull-images.sh b/playbooks/roles/package/files/pull-images.sh
index 737b96d..cafdd68 100755
--- a/playbooks/roles/package/files/pull-images.sh
+++ b/playbooks/roles/package/files/pull-images.sh
@@ -33,9 +33,10 @@
# shellcheck disable=SC2086
cat <<EOF
-Usage: $(basename ${0}) [-l <file with list of docker images>] [-p <number in parallel>] [-v] [-h]
+Usage: $(basename ${0}) [-l <file with list of docker images>] [-p <number in parallel>] [-c <container-tool>] [-v] [-h]
-l: File with list of docker images. (Default /tmp/docker-list.tmp)
+ -c: container command. (Default docker)
-p: number in parallel. (Default 4)
-v: Increase verbosity and keep logs for troubleshooting. (Default false)
-h: This message.
@@ -64,16 +65,18 @@
LISTOFDOCKERIMAGES=${LISTOFDOCKERIMAGES:-"/tmp/docker-list.tmp"}
PARALLELNU=${PARALLELNU:-4}
VERBOSITY="false"
+ CONTAINER_TOOL="docker"
# TODO (fdegir): This function is left here so we can introduce additional
# arguments when we introduce support for other stacks than Kubernetes only
# get values passed as command line arguments, overriding the defaults or
# the ones set by using env variables
- while getopts ":hl:p:v" o; do
+ while getopts ":hl:p:c:v" o; do
case "${o}" in
h) usage ;;
l) LISTOFDOCKERIMAGES="${OPTARG}" ;;
p) PARALLELNU="${OPTARG}" ;;
+ c) CONTAINER_TOOL="${OPTARG}" ;;
v) VERBOSITY="true" ;;
*) echo "ERROR: Invalid option '-${OPTARG}'"; usage ;;
esac
@@ -83,8 +86,9 @@
export LISTOFDOCKERIMAGES="${LISTOFDOCKERIMAGES}"
export PARALLELNU="${PARALLELNU}"
export VERBOSITY="${VERBOSITY}"
+ export CONTAINER_TOOL="${CONTAINER_TOOL}"
}
parse_cmdline_opts "$@"
-xargs -n 1 -P "$PARALLELNU" docker pull < "$LISTOFDOCKERIMAGES"
+xargs -n 1 -P "$PARALLELNU" "$CONTAINER_TOOL" pull < "$LISTOFDOCKERIMAGES"
diff --git a/playbooks/roles/package/files/save-images.sh b/playbooks/roles/package/files/save-images.sh
index a753cc9..8228b7c 100644
--- a/playbooks/roles/package/files/save-images.sh
+++ b/playbooks/roles/package/files/save-images.sh
@@ -18,7 +18,6 @@
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
-
set -o nounset
set -o errexit
set -o pipefail
@@ -33,9 +32,10 @@
# shellcheck disable=SC2086
cat <<EOF
-Usage: $(basename ${0}) [-l <file with list of docker images>] [-p <number in parallel>] [-v] [-h]
+Usage: $(basename ${0}) [-l <file with list of docker images>] [-p <number in parallel>] [-i <container-tool>] [-v] [-h]
-l: File with list of docker images. (Default /tmp/docker-list.tmp)
+ -i: container command. (Default docker)
-p: number in parallel. (Default 4)
-v: Increase verbosity and keep logs for troubleshooting. (Default false)
-c: Directory to save inmages in
@@ -46,7 +46,6 @@
}
-
#-------------------------------------------------------------------------------
# Parse the arguments that are passed to the script
# If an argument is not specified, default values for those are set
@@ -66,15 +65,17 @@
CONTAINERDIR=${CONTAINERDIR:-"/tmp/"}
PARALLELNU=${PARALLELNU:-4}
VERBOSITY="false"
+ CONTAINER_TOOL="docker"
# TODO (fdegir): This function is left here so we can introduce additional
# arguments when we introduce support for other stacks than Kubernetes only
# get values passed as command line arguments, overriding the defaults or
# the ones set by using env variables
- while getopts "hl:p:c:v" o; do
+ while getopts "hl:p:c:i:v" o; do
case "${o}" in
h) usage ;;
l) LISTOFDOCKERIMAGES="${OPTARG}" ;;
+ i) CONTAINER_TOOL="${OPTARG}" ;;
p) PARALLELNU="${OPTARG}" ;;
c) CONTAINERDIR="${OPTARG}" ;;
v) VERBOSITY="true" ;;
@@ -86,9 +87,10 @@
export LISTOFDOCKERIMAGES="${LISTOFDOCKERIMAGES}"
export PARALLELNU="${PARALLELNU}"
export VERBOSITY="${VERBOSITY}"
+ export CONTAINER_TOOL="${CONTAINER_TOOL}"
}
parse_cmdline_opts "$@"
cd "$CONTAINERDIR"
-xargs -n 3 -P "$PARALLELNU" docker save < "$LISTOFDOCKERIMAGES"
+xargs -n 3 -P "$PARALLELNU" "$CONTAINER_TOOL" save < "$LISTOFDOCKERIMAGES"
diff --git a/playbooks/roles/package/tasks/containers.yaml b/playbooks/roles/package/tasks/containers.yaml
index 96d86eb..a7f7053 100644
--- a/playbooks/roles/package/tasks/containers.yaml
+++ b/playbooks/roles/package/tasks/containers.yaml
@@ -38,7 +38,7 @@
changed_when: false
- name: pull images
- script: pull-images.sh -l {{ dockerpullfile.path }} -p 2
+ script: pull-images.sh -l {{ dockerpullfile.path }} -p 2 -c {{ containertool }}
become: true
changed_when: false
@@ -58,7 +58,7 @@
changed_when: false
- name: save images
- script: save-images.sh -l {{ dockersavefile.path }} -c {{ containers_folder }}
+ script: save-images.sh -l {{ dockersavefile.path }} -c {{ containers_folder }} -i {{ containertool }}
become: true
changed_when: false
diff --git a/playbooks/roles/package/tasks/install-debian-podman.yaml b/playbooks/roles/package/tasks/install-debian-podman.yaml
new file mode 100644
index 0000000..826c0eb
--- /dev/null
+++ b/playbooks/roles/package/tasks/install-debian-podman.yaml
@@ -0,0 +1,50 @@
+---
+# ============LICENSE_START=======================================================
+# Copyright (C) 2020 The Nordix Foundation. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+- name: Add podman apt key
+ apt_key:
+ url: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_{{ ansible_distribution_version }}/Release.key"
+ state: present
+ become: true
+
+# NOTE(fdegir): ansible apt_repository gives segmentation fault so failling back to command
+- name: Add podman apt repository
+ command: |-
+ add-apt-repository \
+ "deb [arch=amd64] https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_{{ ansible_distribution_version }}/ /"
+ changed_when: false
+ become: true
+
+- name: Run apt update
+ apt:
+ update_cache: true
+ become: true
+
+- name: Install packages
+ apt:
+ name: "podman"
+ state: "{{ item }}"
+ force: true
+ install_recommends: true
+ autoremove: true
+ update_cache: true
+ with_items:
+ - absent
+ - present
+ become: true
diff --git a/playbooks/roles/package/tasks/install-packages-Debian.yml b/playbooks/roles/package/tasks/install-packages-Debian.yml
index b69f4bd..053ebb0 100644
--- a/playbooks/roles/package/tasks/install-packages-Debian.yml
+++ b/playbooks/roles/package/tasks/install-packages-Debian.yml
@@ -58,4 +58,8 @@
state: restarted
become: true
+- name: Install podman when required
+ include_tasks: install-debian-podman.yaml
+ when: containertool == "podman"
+
# vim: set ts=2 sw=2 expandtab: