From 9ddfd8f69a25bf0959a03e21a8bf35a5d8958ee4 Mon Sep 17 00:00:00 2001 From: "Yasin, Siraj (SY495P)" Date: Tue, 30 Jun 2020 11:31:52 -0500 Subject: [PATCH] Update zuul gates to use docker-image * use the docker image to lint and test * install docker on image instead of checking for go, the docker image itself is created from a golang base image Change-Id: I4b1342862973031734a1f1af887fd85ceae325da --- .zuul.yaml | 4 +- playbooks/airshipui-lint/run.yaml | 4 +- playbooks/airshipui-test/run.yaml | 4 +- .../{install-go.yaml => install-docker.yaml} | 4 +- roles/docker-install/defaults/main.yaml | 28 ++++++ roles/docker-install/tasks/main.yaml | 91 +++++++++++++++++++ .../templates/http-proxy-conf.j2 | 4 + roles/docker-install/tests/main.yml | 25 +++++ tools/install_js_linter | 4 +- 9 files changed, 159 insertions(+), 9 deletions(-) rename playbooks/{install-go.yaml => install-docker.yaml} (92%) create mode 100644 roles/docker-install/defaults/main.yaml create mode 100644 roles/docker-install/tasks/main.yaml create mode 100644 roles/docker-install/templates/http-proxy-conf.j2 create mode 100644 roles/docker-install/tests/main.yml diff --git a/.zuul.yaml b/.zuul.yaml index 1abff94..9f477b1 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -32,12 +32,12 @@ - job: name: airshipui-test - pre-run: playbooks/install-go.yaml + pre-run: playbooks/install-docker.yaml run: playbooks/airshipui-test/run.yaml - job: name: airshipui-lint - pre-run: playbooks/install-go.yaml + pre-run: playbooks/install-docker.yaml run: playbooks/airshipui-lint/run.yaml - job: diff --git a/playbooks/airshipui-lint/run.yaml b/playbooks/airshipui-lint/run.yaml index 60e284e..588f59b 100644 --- a/playbooks/airshipui-lint/run.yaml +++ b/playbooks/airshipui-lint/run.yaml @@ -14,9 +14,9 @@ - hosts: all name: Run linter tasks: - - name: make lint + - name: make docker-image-lint make: - target: lint + target: docker-image-lint chdir: "{{ zuul.project.src_dir }}" environment: PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin" diff --git a/playbooks/airshipui-test/run.yaml b/playbooks/airshipui-test/run.yaml index a133c4b..1b57c9e 100644 --- a/playbooks/airshipui-test/run.yaml +++ b/playbooks/airshipui-test/run.yaml @@ -14,9 +14,9 @@ - hosts: all name: Run tests tasks: - - name: make test + - name: make docker-image-unit-tests make: - target: test + target: docker-image-unit-tests chdir: "{{ zuul.project.src_dir }}" environment: PATH: "{{ ansible_env.PATH }}:/usr/local/go/bin" diff --git a/playbooks/install-go.yaml b/playbooks/install-docker.yaml similarity index 92% rename from playbooks/install-go.yaml rename to playbooks/install-docker.yaml index 734a61b..62548f2 100644 --- a/playbooks/install-go.yaml +++ b/playbooks/install-docker.yaml @@ -12,6 +12,6 @@ --- - hosts: all - name: Install Go + name: Install Docker roles: - - ensure-go + - docker-install diff --git a/roles/docker-install/defaults/main.yaml b/roles/docker-install/defaults/main.yaml new file mode 100644 index 0000000..623143c --- /dev/null +++ b/roles/docker-install/defaults/main.yaml @@ -0,0 +1,28 @@ +# 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. + +docker_config_path: "/etc/docker" + +docker_config_log_driver: "journald" +docker_config_log_opts: {} + +docker_config: | + { + "log-driver": "{{ docker_config_log_driver }}", + "log-opts": {{ docker_config_log_opts | to_json }} + } + +proxy: + enabled: false + http: + https: + noproxy: diff --git a/roles/docker-install/tasks/main.yaml b/roles/docker-install/tasks/main.yaml new file mode 100644 index 0000000..428d333 --- /dev/null +++ b/roles/docker-install/tasks/main.yaml @@ -0,0 +1,91 @@ +# 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: Ensuring docker and support packages are present + become: yes + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' + yum: + name: + - docker.io + - runc + update_cache: yes + state: present + +- name: Ensuring docker and support packages are present + become: yes + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + apt: + name: + - docker.io + - runc + update_cache: yes + state: present + +- name: Ensure docker group exists + group: + name: docker + state: present + +- name: Add user "{{ ansible_user }}" to docker group + become: yes + user: + name: "{{ ansible_user }}" + groups: + - docker + append: yes + +- name: Reset ssh connection to add docker group to user + meta: reset_connection + ignore_errors: true + +- block: + - name: Create docker directory + file: + path: /etc/systemd/system/docker.service.d/ + state: directory + mode: '0755' + + - name: Configure proxy for docker if enabled + template: + src: http-proxy-conf.j2 + dest: /etc/systemd/system/docker.service.d/http-proxy.conf + when: proxy.enabled|bool == true + become: yes + +- name: Create docker directory + file: + path: "{{ docker_config_path }}" + state: directory + mode: '0755' + become: yes + +- name: Save docker daemon configuration + copy: + content: "{{ docker_config | to_nice_json }}" + dest: "{{ docker_config_path }}/daemon.json" + become: yes + +- name: Start docker + become: yes + systemd: + name: docker + state: restarted + daemon_reload: yes + enabled: true + +- name: Change group ownership on docker sock + become: yes + file: + path: /var/run/docker.sock + group: docker + diff --git a/roles/docker-install/templates/http-proxy-conf.j2 b/roles/docker-install/templates/http-proxy-conf.j2 new file mode 100644 index 0000000..90d8e1d --- /dev/null +++ b/roles/docker-install/templates/http-proxy-conf.j2 @@ -0,0 +1,4 @@ +[Service] +Environment="HTTP_PROXY={{ proxy.http }}" +Environment="HTTPS_PROXY={{ proxy.https }}" +Environment="NO_PROXY={{ proxy.noproxy }}" diff --git a/roles/docker-install/tests/main.yml b/roles/docker-install/tests/main.yml new file mode 100644 index 0000000..70b7a4b --- /dev/null +++ b/roles/docker-install/tests/main.yml @@ -0,0 +1,25 @@ +# 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: install docker + include_role: + name: docker-install + +- name: check if docker is installed + shell: "docker version" + register: docker_version + +- name: verify docker is installed + assert: + that: + - docker_version.rc == 0 + diff --git a/tools/install_js_linter b/tools/install_js_linter index e093cef..620ea65 100755 --- a/tools/install_js_linter +++ b/tools/install_js_linter @@ -3,6 +3,7 @@ set -x tools_bin_dir="${BASH_SOURCE%/*}" node_version=v12.16.3 +npm_user=${USER:-root} if [[ ! -d $tools_bin_dir/node-$node_version ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then @@ -40,9 +41,10 @@ if [[ ! -d $tools_bin_dir/node-$node_version ]]; then # npm will write to a node_modules even with the --directory flag it's better to be in the root of where you want this to live cd web + npm config set user ${npm_user} if ! npm install eslint-plugin-html@latest --save-dev; then printf "Something went wrong while installing eslint-plugin-html\n" 1>&2 exit 1 fi cd .. -fi \ No newline at end of file +fi