From 93b1a1bfb9d3b34dd5b87ce45b759489fc164d8c Mon Sep 17 00:00:00 2001 From: stewie925 Date: Tue, 18 Dec 2018 13:17:34 -0800 Subject: [PATCH] Update Ranger Dockerfile and Makefile Create a new Makefile that builds separate docker for Ranger and Ranger Client (CLI). Also added rangercli.sh for use to test CLI command in Ranger Client (rangercli) container. Change-Id: Iaecf1a18227c599f0c9732b90b7c05a093a50376 --- Makefile | 39 ++++++++-- Makefile-Ranger-Client | 50 ------------- Dockerfile => images/ranger/Dockerfile | 0 .../rangercli/Dockerfile | 2 + tools/rangercli.sh | 73 +++++++++++++++++++ 5 files changed, 106 insertions(+), 58 deletions(-) delete mode 100644 Makefile-Ranger-Client rename Dockerfile => images/ranger/Dockerfile (100%) rename Dockerfile-Ranger-Client => images/rangercli/Dockerfile (99%) create mode 100755 tools/rangercli.sh diff --git a/Makefile b/Makefile index 43190edb..497a14fe 100644 --- a/Makefile +++ b/Makefile @@ -13,20 +13,27 @@ # limitations under the License. DOCKER_REGISTRY ?= quay.io -IMAGE_NAME ?= ranger +IMAGE_NAME := ranger rangercli IMAGE_PREFIX ?= attcomdev IMAGE_TAG ?= ocata HELM ?= helm LABEL ?= commit-id PROXY ?= http://proxy.foo.com:8000 NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local -USE_PROXY ?= false +USE_PROXY ?= true IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG} +IMAGE_DIR:=images/$(IMAGE_NAME) # Build ranger Docker image for this project .PHONY: images -images: build_$(IMAGE_NAME) +#Build all images in the list +images: $(IMAGE_NAME) +#sudo make images will build and run ranger and rangercli + $(IMAGE_NAME): + @echo + @echo "===== Processing [$@] image =====" + @make build_$@ IMAGE=${DOCKER_REGISTRY}/${IMAGE_PREFIX}/$@:${IMAGE_TAG} IMAGE_DIR=images/$@ IMAGE_NAME=$@ # Create tgz of the chart .PHONY: charts @@ -44,11 +51,11 @@ dry-run: clean tools/helm_tk.sh $(HELM) # Make targets intended for use by the primary targets above. -.PHONY: build_$(IMAGE_NAME) -build_$(IMAGE_NAME): +.PHONY: build_ranger +build_ranger: ifeq ($(USE_PROXY), true) - docker build --network host -t $(IMAGE) --label $(LABEL) -f Dockerfile \ + docker build --network host -t $(IMAGE) --label $(LABEL) -f $(IMAGE_DIR)/Dockerfile \ --build-arg http_proxy=$(PROXY) \ --build-arg https_proxy=$(PROXY) \ --build-arg HTTP_PROXY=$(PROXY) \ @@ -56,9 +63,25 @@ ifeq ($(USE_PROXY), true) --build-arg no_proxy=$(NO_PROXY) \ --build-arg NO_PROXY=$(NO_PROXY) . else - docker build --network host -t $(IMAGE) --label $(LABEL) -f Dockerfile . + docker build --network host -t $(IMAGE) --label $(LABEL) -f $(IMAGE_DIR)/Dockerfile . endif +.PHONY: build_rangercli +build_rangercli: + +ifeq ($(USE_PROXY), true) + docker build --network host -t $(IMAGE) --label $(LABEL) -f $(IMAGE_DIR)/Dockerfile \ + --build-arg http_proxy=$(PROXY) \ + --build-arg https_proxy=$(PROXY) \ + --build-arg HTTP_PROXY=$(PROXY) \ + --build-arg HTTPS_PROXY=$(PROXY) \ + --build-arg no_proxy=$(NO_PROXY) \ + --build-arg NO_PROXY=$(NO_PROXY) . +else + docker build --network host -t $(IMAGE) --label $(LABEL) -f $(IMAGE_DIR)/Dockerfile . +endif + + .PHONY: clean clean: rm -rf build @@ -66,7 +89,7 @@ clean: .PHONY: pep8 pep8: - tox -e pep8 + cd ../../; tox -e pep8 .PHONY: helm_lint helm_lint: clean diff --git a/Makefile-Ranger-Client b/Makefile-Ranger-Client deleted file mode 100644 index 64227438..00000000 --- a/Makefile-Ranger-Client +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright 2018 AT&T Intellectual Property. All other 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. - -DOCKER_REGISTRY ?= quay.io -IMAGE_NAME ?= ranger-client -IMAGE_PREFIX ?= attcomdev -IMAGE_TAG ?= ocata -LABEL ?= commit-id -PROXY ?= http://proxy.foo.com:8000 -NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local -USE_PROXY ?= false - -IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG} - -# Build ranger Docker image for this project -.PHONY: images -images: build_$(IMAGE_NAME) - - - -# Make targets intended for use by the primary targets above. -.PHONY: build_$(IMAGE_NAME) -build_$(IMAGE_NAME): - -ifeq ($(USE_PROXY), true) - docker build --network host -t $(IMAGE) --label $(LABEL) -f Dockerfile \ - --build-arg http_proxy=$(PROXY) \ - --build-arg https_proxy=$(PROXY) \ - --build-arg HTTP_PROXY=$(PROXY) \ - --build-arg HTTPS_PROXY=$(PROXY) \ - --build-arg no_proxy=$(NO_PROXY) \ - --build-arg NO_PROXY=$(NO_PROXY) . -else - docker build --network host -t $(IMAGE) --label $(LABEL) -f Dockerfile . -endif - -.PHONY: pep8 -pep8: - tox -e pep8 diff --git a/Dockerfile b/images/ranger/Dockerfile similarity index 100% rename from Dockerfile rename to images/ranger/Dockerfile diff --git a/Dockerfile-Ranger-Client b/images/rangercli/Dockerfile similarity index 99% rename from Dockerfile-Ranger-Client rename to images/rangercli/Dockerfile index 48d92385..8c2fa38d 100644 --- a/Dockerfile-Ranger-Client +++ b/images/rangercli/Dockerfile @@ -32,6 +32,8 @@ python-dev \ python-dateutil \ ca-certificates \ openstack-pkg-tools \ +vim \ +curl \ gcc \ g++ \ libffi-dev \ diff --git a/tools/rangercli.sh b/tools/rangercli.sh new file mode 100755 index 00000000..955dc1f5 --- /dev/null +++ b/tools/rangercli.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# Copyright 2018 AT&T Intellectual Property. All other 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. + +set -e + +# rangercli require /${HOME}/openrc environment file that contains all the +# required env variables to run the ranger CLI commands. +envfile="${HOME}/openrc" + +if [ ! -f $envfile ] +then + echo "Environment file $envfile not found." + exit 1 +fi + +# source the environment file if exists +. ${HOME}/openrc + +# User can run the script as they would execute the ranger CLI. +# For instance, to run the './orm cms create_customer' command, user can execute +# the following command after setting up the required environment variables: +# +# $ ./rangercli.sh ./orm cms create_customer /target/cms/create_basic_cms.json +# + +# NOTE: If user is executing the script from outside the cluster, e.g. from +# a remote jump server, then he/she will need to ensure that the DNS server +# is able to resolve the FQDN of the Ranger and Keystone public URL (both +# will be pointing to the IP of the Ingress Controller). If the DNS resolution +# is not available, the user will need to ensure that the /etc/hosts file is +# properly updated before running the script. + +### Additional variables required to run ranger cli commands: +# RANGERCLI_HOSTPATH: we'll always use '/target' as defined below +RANGERCLI_HOSTPATH=${RANGERCLI_HOSTPATH:-"/target"} +# RANGERCLI_JSONPATH = provide full path of your ranger CLI JSON files +RANGERCLI_JSONPATH=${RANGERCLI_JSONPATH} +# RANGERCLI_IMAGE = provide rangercli docker image name to use +RANGERCLI_IMAGE=${RANGERCLI_IMAGE} + +# Define Base Docker Command +base_docker_command=$(cat << EndOfCommand +sudo docker run -t --rm --net=host +-e http_proxy=${HTTP_PROXY} +-e https_proxy=${HTTPS_PROXY} +-e no_proxy=${NO_PROXY:-127.0.0.1,localhost,.svc.cluster.local} +-e RANGER_USERNAME=${RANGER_USERNAME:-ranger-admin} +-e RANGER_TENANT_NAME=${RANGER_TENANT_NAME:-service} +-e RANGER_PASSWORD=${RANGER_PASSWORD:-xxxxxxxx} +-e RANGER_AUTH_REGION=${RANGER_AUTH_REGION} +-e RANGER_CMS_BASE_URL=${RANGER_CMS_BASE_URL} +-e RANGER_FMS_BASE_URL=${RANGER_FMS_BASE_URL} +-e RANGER_IMS_BASE_URL=${RANGER_IMS_BASE_URL} +-e RANGER_RMS_BASE_URL=${RANGER_RMS_BASE_URL} +-e verify=False +-it +EndOfCommand +) + +# Execute Ranger CLI +${base_docker_command} -v "${RANGERCLI_JSONPATH}":"${RANGERCLI_HOSTPATH}" "${RANGERCLI_IMAGE}" $@