From: Szekeres, Balazs (Nokia - HU/Budapest) Date: Thu, 2 May 2019 11:13:58 +0000 (+0200) Subject: Added seed code for caas-cpupooler. X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fcaas-cpupooler.git;a=commitdiff_plain;h=615d289d61440f17b130a351510d1a2adcf40b80 Added seed code for caas-cpupooler. Added seed code for caas-cpupooler. Change-Id: If57a098216a71758b9a7e91e21320106d2de0227 Signed-off-by: Szekeres, Balazs (Nokia - HU/Budapest) --- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4959a5e --- /dev/null +++ b/LICENSE @@ -0,0 +1,179 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + diff --git a/ansible/playbooks/cpupooler.yaml b/ansible/playbooks/cpupooler.yaml new file mode 100644 index 0000000..0b930ed --- /dev/null +++ b/ansible/playbooks/cpupooler.yaml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Nokia +# +# 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. + +# cmframework.requires: pre_config_all.yaml, common.yaml, allocate-cpu-cores.yml +- hosts: caas_master + strategy: free + become: true + become_user: "{{ users.admin_user_name }}" + roles: + - cpupooler diff --git a/ansible/roles/cpupooler/defaults/main.yaml b/ansible/roles/cpupooler/defaults/main.yaml new file mode 100644 index 0000000..71b9e61 --- /dev/null +++ b/ansible/roles/cpupooler/defaults/main.yaml @@ -0,0 +1,22 @@ +--- +# Copyright 2019 Nokia +# +# 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. + +cpu_allocation_mapping: + caas_exclusive: + pool_name: exclusive_caas + caas_shared: + pool_name: shared_caas + platform: + pool_name: default diff --git a/ansible/roles/cpupooler/tasks/create_cpu_pools.yaml b/ansible/roles/cpupooler/tasks/create_cpu_pools.yaml new file mode 100644 index 0000000..e5af187 --- /dev/null +++ b/ansible/roles/cpupooler/tasks/create_cpu_pools.yaml @@ -0,0 +1,41 @@ +--- +# Copyright 2019 Nokia +# +# 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. + + - name: collect facts from all hosts + setup: + gather_subset: min + delegate_to: "{{ item }}" + delegate_facts: true + with_items: "{{ groups['all'] }}" + + - name: make cpu pooler configs + set_fact: + cpu_poolconfigs: "{{ lookup('template', 'ncir_cpu_pooler_config.yaml.j2') | from_yaml }}" + + - name: template cpu pooler fact file + copy: + content: "{{ cpu_poolconfigs | to_nice_json }}" + dest: "/etc/ansible/facts.d/ncir_cpu_pooler_config.fact" + become: true + become_user: root + register: cpu_pooler_template + + - name: sync to avoid IO issues + command: "sync" + + - name: reload facts + setup: + gather_subset: min + when: cpu_pooler_template | changed diff --git a/ansible/roles/cpupooler/tasks/main.yml b/ansible/roles/cpupooler/tasks/main.yml new file mode 100644 index 0000000..78c3fda --- /dev/null +++ b/ansible/roles/cpupooler/tasks/main.yml @@ -0,0 +1,17 @@ +--- +# Copyright 2019 Nokia +# +# 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. + +- name: create cpu pools + import_tasks: create_cpu_pools.yaml diff --git a/ansible/roles/cpupooler/templates/ncir_cpu_pooler_config.yaml.j2 b/ansible/roles/cpupooler/templates/ncir_cpu_pooler_config.yaml.j2 new file mode 100644 index 0000000..b9a6025 --- /dev/null +++ b/ansible/roles/cpupooler/templates/ncir_cpu_pooler_config.yaml.j2 @@ -0,0 +1,32 @@ +#jinja2: lstrip_blocks: True +{# +Copyright 2019 Nokia + +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. +#} +--- +{% for hostname, hostdata in hostvars.iteritems() %} + {% if hostname != "localhost" %} +{{ hostname }}: + pools: + {% set cpu_allocation = hostdata.get('ansible_local', {}).get('ncir_cpu_allocation', {}) %} + {% for allocation_name, allocation in cpu_allocation.iteritems() %} + {% if allocation_name in cpu_allocation_mapping %} + {{ cpu_allocation_mapping[allocation_name]['pool_name'] }}: + cpus: "{{ allocation.get('list', '') }}" + {% endif %} + {% endfor %} + nodeSelector: + nodename: "{{ hostdata['nodename'] | default('') }}" + {% endif %} +{% endfor %} diff --git a/docker-build/cpupooler/Dockerfile b/docker-build/cpupooler/Dockerfile new file mode 100644 index 0000000..33dad86 --- /dev/null +++ b/docker-build/cpupooler/Dockerfile @@ -0,0 +1,47 @@ +# Copyright 2019 Nokia +# +# 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. + +FROM alpine:3.9 +MAINTAINER Balazs Szekeres + +ARG DEPENDENCY_MANAGER +ENV DEP_VERSION=$DEPENDENCY_MANAGER +ARG CPUPOOLER +ENV CPUPOOLER_VERSION=$CPUPOOLER +ENV GOPATH /build +ENV PATH /usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +RUN apk update \ +&& apk upgrade \ +&& apk add --no-cache --virtual .build-deps build-base git mercurial go glide bash tar curl \ +&& mkdir -p $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 \ +&& chmod +x /usr/local/bin/dep \ +&& curl -fsSL -k https://github.com/nokia/CPU-Pooler/archive/v${CPUPOOLER_VERSION}.tar.gz | tar zx --strip-components=1 -C $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& cd $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& dep ensure --vendor-only \ +# cpu-device-plugin +&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cpu-device-plugin ./cmd/cpu-device-plugin \ +&& mv $GOPATH/src/github.com/nokia/CPU-Pooler/cpu-device-plugin /cpu-device-plugin \ +# cpu-setter +&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cpu-setter ./cmd/cpusetter \ +&& mv $GOPATH/src/github.com/nokia/CPU-Pooler/cpu-setter /cpu-setter \ +# cpu-webhook +&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o cpu-device-webhook ./cmd/webhook \ +&& mv $GOPATH/src/github.com/nokia/CPU-Pooler/cpu-device-webhook /cpu-device-webhook \ +&& apk del .build-deps \ +&& rm -rf $GOPATH \ +&& rm -rf /build \ +&& rm -rf /root/.glide + diff --git a/docker-build/cpupooler/bom.json b/docker-build/cpupooler/bom.json new file mode 100644 index 0000000..c1a314c --- /dev/null +++ b/docker-build/cpupooler/bom.json @@ -0,0 +1,190 @@ +{ + "bom": [ + { + "name": "alpine-linux-container", + "version": "3.9", + "source-url": "https://github.com/gliderlabs/docker-alpine/archive/c4f4c7a6e14d6efeb9a160da464717e03d2cc3ee.tar.gz", + "foss": "yes" + }, + { + "name": "musl", + "version": "1.1.20-r3", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/musl/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "busybox", + "version": "1.29.3-r10", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/busybox/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "alpine-baselayout", + "version": "3.1.0-r3", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-baselayout/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "alpine-keys", + "version": "2.1-r1", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/alpine-keys/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libcrypto1.1", + "version": "1.1.1a-r1", + "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libssl1.1", + "version": "1.1.1a-r1", + "source-url": "https://git.alpinelinux.org/aports/tree/main/openssl/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "ca-certificates-cacert", + "version": "20190108-r0", + "source-url": "https://git.alpinelinux.org/aports/tree/main/ca-certificates/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libtls-standalone", + "version": "2.7.4-r6", + "source-url": "https://git.alpinelinux.org/aports/tree/main/libtls-standalone/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "ssl_client", + "version": "1.29.3-r10", + "source-url": "https://git.alpinelinux.org/aports/tree/main/busybox/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "zlib", + "version": "1.2.11-r1", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/zlib/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "apk-tools", + "version": "2.10.3-r1", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/apk-tools/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "scanelf", + "version": "1.2.3-r0", + "source-url": "https://git.alpinelinux.org/aports/tree/main/pax-utils/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "musl-utils", + "version": "1.1.20-r3", + "source-url": "https://git.alpinelinux.org/aports/tree/main/musl/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libc-utils", + "version": "0.7.1-r0", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libc-dev/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libbz2", + "version": "1.0.6-r6", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/bzip2/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "expat", + "version": "2.2.6-r0", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/expat/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "libffi", + "version": "3.2.1-r6", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/libffi/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "gdbm", + "version": "1.13-r1", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/gdbm/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "ncurses-terminfo-base", + "version": "6.1_p20190105-r0", + "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "ncurses-terminfo", + "version": "6.1_p20190105-r0", + "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "ncurses-libs", + "version": "6.1_p20190105-r0", + "source-url": "https://git.alpinelinux.org/aports/tree/main/ncurses/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "readline", + "version": "7.0.003-r1", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/readline/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "sqlite-libs", + "version": "3.26.0-r3", + "source-url": "https://git.alpinelinux.org/aports/tree/main/sqlite/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "python2", + "version": "2.7.15-r3", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/python2/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "py-setuptools", + "version": "40.6.3-r0", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py-setuptools/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "py2-pip", + "version": "18.1-r0", + "source-url": "https://git.alpinelinux.org/cgit/aports/tree/main/py2-pip/APKBUILD?h=3.9-stable", + "foss": "yes" + }, + { + "name": "pip", + "version": "19.0.2", + "source-url": "https://github.com/pypa/pip/archive/19.0.2.tar.gz", + "foss": "yes" + }, + { + "name": "setuptools", + "version": "40.6.3.post20190116", + "source-url": "https://github.com/pypa/setuptools/archive/v40.6.3.tar.gz", + "foss": "yes" + }, + { + "name": "dep-linux", + "version": "0.5.0", + "source-url": "https://github.com/golang/dep/archive/v0.5.0.tar.gz", + "foss": "yes" + }, + { + "name": "cpupooler", + "version": "0.2.0", + "source-url": "https://github.com/nokia/CPU-Pooler/archive/v0.2.0.tar.gz", + "foss": "yes" + } + ] +} diff --git a/docker-build/process-starter/Dockerfile b/docker-build/process-starter/Dockerfile new file mode 100644 index 0000000..2f474e1 --- /dev/null +++ b/docker-build/process-starter/Dockerfile @@ -0,0 +1,54 @@ +# Copyright 2019 Nokia +# +# 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. + +FROM centos:7.6.1810 +MAINTAINER Balazs Szekeres + +ARG DEPENDENCY_MANAGER +ENV DEP_VERSION=$DEPENDENCY_MANAGER +ARG CPUPOOLER +ENV CPUPOOLER_VERSION=$CPUPOOLER +ENV GOPATH /build + +RUN yum update -y \ +&& yum install -y \ + go \ + git \ + bash \ + glide \ + libtool \ + autoconf \ + coreutils \ + curl \ + binutils \ + tar \ + grep \ + make \ + gcc \ + gcc-c++ \ +&& rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO \ +&& curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo \ +&& yum install -y golang \ +&& curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 \ +&& chmod +x /usr/local/bin/dep \ +&& mkdir -p $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& curl -fsSL -k https://github.com/nokia/CPU-Pooler/archive/v${CPUPOOLER_VERSION}.tar.gz | tar zx --strip-components=1 -C $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& cd $GOPATH/src/github.com/nokia/CPU-Pooler \ +&& dep ensure --vendor-only \ +# process-starter +&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' -o process-starter ./cmd/process-starter \ +&& mv $GOPATH/src/github.com/nokia/CPU-Pooler/process-starter /process-starter \ +&& rm -rf $GOPATH + + diff --git a/rpmbuild.spec b/rpmbuild.spec new file mode 100644 index 0000000..3700198 --- /dev/null +++ b/rpmbuild.spec @@ -0,0 +1,150 @@ +# Copyright 2019 Nokia +# +# 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. + +%define COMPONENT cpupooler +%define COMPONENT_PART process-starter +%define RPM_NAME caas-%{COMPONENT} +%define RPM_MAJOR_VERSION 0.2.0 +%define RPM_MINOR_VERSION 1 +%define DEPENDENCY_MANAGER_VERSION 0.5.0 +%define IMAGE_TAG %{RPM_MAJOR_VERSION}-%{RPM_MINOR_VERSION} +%define PROCESS_STARTER_INSTALL_PATH /opt/bin/ + +Name: %{RPM_NAME} +Version: %{RPM_MAJOR_VERSION} +Release: %{RPM_MINOR_VERSION}%{?dist} +Summary: Containers as a Service cpu-pooler component +License: %{_platform_license} and BSD 3-Clause License +URL: https://github.com/nokia/CPU-Pooler +BuildArch: x86_64 +Vendor: %{_platform_vendor} and Nokia +Source0: %{name}-%{version}.tar.gz + +Requires: docker-ce >= 18.09.2 +BuildRequires: docker-ce >= 18.09.2 + +# I was able to pack an executable via this. +# more info at https://fedoraproject.org/wiki/Packaging:Debuginfo +%global debug_package %{nil} + +%description +This RPM contains the cpu-pooler container image, process-starter binary and related deployment artifacts for the CaaS subsystem. + +%prep +%autosetup + +%build +# build the process-starter binary inside a builder conatiner +docker build \ + --network=host \ + --no-cache \ + --force-rm \ + --build-arg HTTP_PROXY="${http_proxy}" \ + --build-arg HTTPS_PROXY="${https_proxy}" \ + --build-arg NO_PROXY="${no_proxy}" \ + --build-arg http_proxy="${http_proxy}" \ + --build-arg https_proxy="${https_proxy}" \ + --build-arg no_proxy="${no_proxy}" \ + --build-arg DEPENDENCY_MANAGER="%{DEPENDENCY_MANAGER_VERSION}" \ + --build-arg CPUPOOLER="%{RPM_MAJOR_VERSION}" \ + --tag %{COMPONENT_PART}:builder \ + %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT_PART}/ + +# create a directory for process-starter binary +mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results + +# run the builder conatiner for process-starter binary +docker run \ + -id \ + --rm \ + --network=host \ + --privileged \ + -e HTTP_PROXY="${http_proxy}" \ + -e HTTPS_PROXY="${https_proxy}" \ + -e NO_PROXY="${no_proxy}" \ + -e http_proxy="${http_proxy}" \ + -e https_proxy="${https_proxy}" \ + -e no_proxy="${no_proxy}" \ + --entrypoint=/bin/sh \ + %{COMPONENT_PART}:builder + +# get the process-starter binary +docker cp $(docker ps | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }'):/process-starter %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/ + +# rm container +for container_ran in $(docker ps -a | grep "%{COMPONENT_PART}:builder" | awk -F' ' '{ print $1 }') +do + docker rm -f $container_ran +done + +# remove docker image +docker rmi -f %{COMPONENT_PART}:builder + +# build the cpu pooler +docker build \ + --network=host \ + --no-cache \ + --force-rm \ + --build-arg HTTP_PROXY="${http_proxy}" \ + --build-arg HTTPS_PROXY="${https_proxy}" \ + --build-arg NO_PROXY="${no_proxy}" \ + --build-arg http_proxy="${http_proxy}" \ + --build-arg https_proxy="${https_proxy}" \ + --build-arg no_proxy="${no_proxy}" \ + --build-arg DEPENDENCY_MANAGER="%{DEPENDENCY_MANAGER_VERSION}" \ + --build-arg CPUPOOLER="%{RPM_MAJOR_VERSION}" \ + --tag %{COMPONENT}:%{IMAGE_TAG} \ + %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-build/%{COMPONENT}/ + +# create a save folder +mkdir -p %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/ + +# save the cpu poooler container +docker save %{COMPONENT}:%{IMAGE_TAG} | gzip -c > %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar + +# remove docker image +docker rmi -f %{COMPONENT}:%{IMAGE_TAG} + +%install +mkdir -p %{buildroot}/%{_caas_container_tar_path}/ +rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/docker-save/%{COMPONENT}:%{IMAGE_TAG}.tar %{buildroot}/%{_caas_container_tar_path}/ + +mkdir -p %{buildroot}%{PROCESS_STARTER_INSTALL_PATH} +rsync -av %{_builddir}/%{RPM_NAME}-%{RPM_MAJOR_VERSION}/results/process-starter %{buildroot}/%{PROCESS_STARTER_INSTALL_PATH}/ + +mkdir -p %{buildroot}/%{_playbooks_path}/ +rsync -av ansible/playbooks/cpupooler.yaml %{buildroot}/%{_playbooks_path}/ + +mkdir -p %{buildroot}/%{_roles_path}/ +rsync -av ansible/roles/cpupooler %{buildroot}/%{_roles_path}/ + +%files +%{_caas_container_tar_path}/%{COMPONENT}:%{IMAGE_TAG}.tar +%{PROCESS_STARTER_INSTALL_PATH}/process-starter +%{_playbooks_path}/cpupooler.yaml +%{_roles_path}/cpupooler + +%preun + +%post +mkdir -p %{_postconfig_path}/ +ln -sf %{_playbooks_path}/cpupooler.yaml %{_postconfig_path}/ + +%postun +if [ $1 -eq 0 ]; then + rm -f %{_postconfig_path}/cpupooler.yaml +fi + +%clean +rm -rf ${buildroot}