Enable offline deployment 49/4749/1
authorFatih Degirmenci <fdegir@gmail.com>
Tue, 12 May 2020 08:43:18 +0000 (08:43 +0000)
committerFatih Degirmenci <fdegir@gmail.com>
Tue, 12 May 2020 13:33:42 +0000 (13:33 +0000)
Change-Id: Ic7f72a203f96b1b890d0a3da1b7115f04fe2703c

install.sh
playbooks/prepare-artifacts.yaml [new file with mode: 0644]
playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml
playbooks/roles/prepare-artifacts/tasks/main.yaml [new file with mode: 0644]

index 79e30c849b6f4a2ac4bdd35611fc026fa22a110d..e8614145bcc4b40657b67fe05b323ff5bbc61d68 100755 (executable)
@@ -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 (file)
index 0000000..0132d65
--- /dev/null
@@ -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:
index 55bddd0a81d2775eb40e6917b08a513320d048e4..55e3e6cfa6f8637908f9160092745010a1f548de 100644 (file)
@@ -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 (file)
index 0000000..f55b044
--- /dev/null
@@ -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 }}\|<none>' | 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: