From 223f9beb41172dfb37af6e77a94e808f926e0fc9 Mon Sep 17 00:00:00 2001 From: Fatih Degirmenci Date: Tue, 12 May 2020 08:43:18 +0000 Subject: [PATCH] Enable offline deployment Change-Id: Ic7f72a203f96b1b890d0a3da1b7115f04fe2703c --- install.sh | 15 +++++ playbooks/prepare-artifacts.yaml | 30 +++++++++ .../tasks/configure-offline-deployment.yaml | 2 +- .../roles/prepare-artifacts/tasks/main.yaml | 62 +++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 playbooks/prepare-artifacts.yaml create mode 100644 playbooks/roles/prepare-artifacts/tasks/main.yaml diff --git a/install.sh b/install.sh index 79e30c8..e861414 100755 --- a/install.sh +++ b/install.sh @@ -39,6 +39,21 @@ echo "-------------------------------------------------------------------------" # shellcheck disable=SC1090 source "${ENGINE_PATH}/engine/provisioner/provision.sh" +#------------------------------------------------------------------------------- +# Provision local apt repo, docker registry, and ntp server services +#------------------------------------------------------------------------------- +# shellcheck source=engine/library/engine-services.sh +source "${ENGINE_PATH}/engine/library/engine-services.sh" + +#------------------------------------------------------------------------------- +# Prepare artifacts for offline deployment +#------------------------------------------------------------------------------- +cd "${ENGINE_PATH}" +ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ + -i "${ENGINE_PATH}/engine/inventory/inventory.ini" \ + engine/stack/kubernetes/playbooks/prepare-artifacts.yaml +echo "-------------------------------------------------------------------------" + #------------------------------------------------------------------------------- # Install the stack using the selected installer #------------------------------------------------------------------------------- diff --git a/playbooks/prepare-artifacts.yaml b/playbooks/prepare-artifacts.yaml new file mode 100644 index 0000000..0132d65 --- /dev/null +++ b/playbooks/prepare-artifacts.yaml @@ -0,0 +1,30 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 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========================================================= + +- hosts: jumphost + gather_facts: true + become: false + + tasks: + - name: Prepare artifacts for offline deployment + include_role: + name: prepare-artifacts + when: execution_mode == "offline-deployment" + +# vim: set ts=2 sw=2 expandtab: diff --git a/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml b/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml index 55bddd0..55e3e6c 100644 --- a/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml +++ b/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml @@ -50,7 +50,7 @@ git: repo: "{{ engine_workspace }}/offline/git/engine-{{ installer_type }}" dest: "{{ engine_workspace }}/offline/git/engine/engine/installer" - version: "{{ installer[installer_type].version }}" + version: "{{ installers[installer_type].version }}" force: true - name: Copy engine installer vars file into group_vars diff --git a/playbooks/roles/prepare-artifacts/tasks/main.yaml b/playbooks/roles/prepare-artifacts/tasks/main.yaml new file mode 100644 index 0000000..f55b044 --- /dev/null +++ b/playbooks/roles/prepare-artifacts/tasks/main.yaml @@ -0,0 +1,62 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 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: Get list of k8s container image tarfiles + find: + path: "{{ engine_workspace }}/offline/containers" + patterns: '*.tar' + register: container_image + +# NOTE (fdegir): the user may not be member of docker group so we need root +# TODO (fdegir): we can perhaps skip loading already existing images here +- name: Load k8s container images from tarfiles + shell: docker load < {{ item.path }} + loop: "{{ container_image.files }}" + changed_when: false + become: true + +# NOTE (fdegir): the escape of curly brackets in ansible is really messy unfortunately +# we also shouldn't attempt to tag and push container images that are already on local registry +# NOTE (fdegir): we do not push any image that is already on engine.local and any image without tag +- name: Get list of loaded k8s container images to push + shell: | + set -o pipefail + docker images --format '{{ '{{' }}.Repository{{ '}}' }}':'{{ '{{' }}.Tag{{ '}}' }}' | grep -v '{{ server_fqdn }}\|' | sort + args: + executable: /bin/bash + changed_when: false + become: true + register: container_images + +- name: Create dict of k8s container images to tag and push + set_fact: + container_images_dict: "{{ ( container_images_dict | default({}) ) | combine({item: item | regex_replace('.*?.io/', '')}) }}" + loop: "{{ container_images.stdout_lines }}" + +# TODO (fdegir): it is messy to use ansible module for tagging and pushing but we can still look into it +# TODO (fdegir): we can perhaps skip tagging & pushing already existing images here +- name: Tag and push k8s container images to local registry + shell: | + docker tag {{ item.key }} {{ server_fqdn }}/{{ item.value }} + docker push {{ server_fqdn }}/{{ item.value }} + with_dict: "{{ container_images_dict }}" + changed_when: false + become: true + +# vim: set ts=2 sw=2 expandtab: -- 2.25.1