Rouzbahan Rashidi-Tabrizi | 7b1bab9 | 2016-11-21 14:28:50 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
Rouzbahan Rashidi-Tabrizi | 663f01a | 2016-11-17 11:39:02 -0500 | [diff] [blame] | 17 | PROTO_FILES := $(wildcard *.proto) $(wildcard third_party/google/api/*proto) |
| 18 | PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f))) |
| 19 | PROTO_DESC_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,.desc,$(f))) |
| 20 | |
| 21 | PROTOC_PREFIX := /usr/local |
| 22 | PROTOC_LIBDIR := $(PROTOC_PREFIX)/lib |
| 23 | |
| 24 | PROTOC := $(PROTOC_PREFIX)/bin/protoc |
| 25 | |
khenaidoo | 079a776 | 2017-10-26 21:42:05 -0400 | [diff] [blame^] | 26 | PROTOC_VERSION := "3.3.0" |
Rouzbahan Rashidi-Tabrizi | 663f01a | 2016-11-17 11:39:02 -0500 | [diff] [blame] | 27 | PROTOC_DOWNLOAD_PREFIX := "https://github.com/google/protobuf/releases/download" |
| 28 | PROTOC_DIR := protobuf-$(PROTOC_VERSION) |
| 29 | PROTOC_TARBALL := protobuf-python-$(PROTOC_VERSION).tar.gz |
| 30 | PROTOC_DOWNLOAD_URI := $(PROTOC_DOWNLOAD_PREFIX)/v$(PROTOC_VERSION)/$(PROTOC_TARBALL) |
| 31 | PROTOC_BUILD_TMP_DIR := "/tmp/protobuf-build-$(shell uname -s | tr '[:upper:]' '[:lower:]')" |
| 32 | |
Rouzbahan Rashidi-Tabrizi | 64b6834 | 2016-12-08 11:10:50 -0500 | [diff] [blame] | 33 | TOKEN_FILE := vagrant-token |
| 34 | TOKEN := `cat $(TOKEN_FILE)` |
| 35 | |
| 36 | VAGRANT_VOLTHA_BASE_INFO="$(shell vagrant box list | grep voltha-base | tail -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 2)" |
| 37 | CURRENT_VERSION=`echo $(VAGRANT_VOLTHA_BASE_INFO) | cut -d ')' -f 1` |
| 38 | CURRENT_VERSION_DYNAMIC=`echo $$(vagrant box list | grep voltha-base | tail -n 1 | cut -d ',' -f 2 | cut -d ' ' -f 2) | cut -d ')' -f 1` |
| 39 | TIME := $(shell date +"%y%m%d.%H%M%S.0") |
| 40 | VERSION := `echo $(TIME)` |
| 41 | VERSION_DYNAMIC := `echo $$(date +"%y%m%d.%H%M%S.0")` |
| 42 | |
| 43 | default: build |
| 44 | |
| 45 | build: add-update-voltha-base build-core |
| 46 | |
| 47 | print-info: |
| 48 | @echo "TOKEN ----------------------> "$(TOKEN) |
| 49 | @echo "TIME -----------------------> "$(TIME) |
| 50 | @echo "VERSION --------------------> "$(VERSION) |
| 51 | @echo "VERSION_DYNAMIC ------------> "$(VERSION_DYNAMIC) |
| 52 | @echo "CURRENT_VERSION ------------> "$(CURRENT_VERSION) |
| 53 | @echo "CURRENT_VERSION_DYNAMIC ----> "$(CURRENT_VERSION_DYNAMIC) |
| 54 | |
| 55 | help: |
| 56 | @echo |
| 57 | @echo "Usage: make [<target>] [VERSION='X.X.X']" |
| 58 | @echo "where available targets are:" |
| 59 | @echo |
| 60 | @echo "help : Print this help" |
| 61 | @echo "build : Build the Voltha-base vagrant box and upload it to Vagrant Cloud (default target)" |
| 62 | @echo "build-core : Execute the main tasks to build theVoltha-base vagrant box and upload it to Vagrant Cloud (default target)" |
| 63 | @echo "clean : Stop/Remove the Voltha-base virtual machine" |
| 64 | @echo "start-message : Print Voltha-base banner" |
| 65 | @echo "update-voltha-base : Update the Voltha-base (voltha/voltha-base) box to the latest version" |
| 66 | @echo "test-voltha-base : Test the Voltha-base vagrant image" |
| 67 | @echo "run-voltha-base : Run the Voltha-base (vagrant up)" |
| 68 | @echo "package-voltha-base : Package the Voltha-base vagrant image to a .box package" |
| 69 | @echo "create-version : Create a new version on Vagrant Cloud" |
| 70 | @echo "create-provider : Create & assign an provider to a version on Vagrant Cloud" |
| 71 | @echo "upload-package : Upload a package.box file to Vagrant Cloud and assign it to a version and provider" |
| 72 | @echo "release-version : Release a verson as the available version of the Voltha-base on Vagrant Cloud" |
| 73 | @echo |
| 74 | |
Rouzbahan Rashidi-Tabrizi | 663f01a | 2016-11-17 11:39:02 -0500 | [diff] [blame] | 75 | $(PROTOC): |
| 76 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 77 | @echo "It looks like you don't have protocol buffer tools installed." |
| 78 | @echo "To install the protocol buffer toolchain, you can run:" |
| 79 | @echo " make install-protoc" |
| 80 | @echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" |
| 81 | |
| 82 | install-protoc: $(PROTOC) |
| 83 | @echo "Downloading and installing protocol buffer support." |
| 84 | @echo "Installation will require sodo priviledges" |
| 85 | @echo "This will take a few minutes." |
| 86 | mkdir -p $(PROTOC_BUILD_TMP_DIR) |
| 87 | @echo "We ask for sudo credentials now so we can install at the end"; \ |
| 88 | sudo echo "Thanks"; \ |
| 89 | cd $(PROTOC_BUILD_TMP_DIR); \ |
| 90 | wget $(PROTOC_DOWNLOAD_URI); \ |
| 91 | tar xzvf $(PROTOC_TARBALL); \ |
| 92 | cd $(PROTOC_DIR); \ |
| 93 | ./configure --prefix=$(PROTOC_PREFIX); \ |
| 94 | make; \ |
Rouzbahan Rashidi-Tabrizi | 64b6834 | 2016-12-08 11:10:50 -0500 | [diff] [blame] | 95 | sudo make install |
| 96 | |
| 97 | build-core: banner run-voltha-base package-voltha-base create-version create-provider upload-package release-version clean update-voltha-base |
| 98 | |
| 99 | add-update-voltha-base: |
| 100 | @echo "Adding/Updating voltha-base vagrant box"; \ |
| 101 | vagrant box update --box voltha/voltha-base || vagrant box add voltha/voltha-base |
| 102 | |
| 103 | update-voltha-base: |
| 104 | @echo "Updating voltha-base vagrant box"; \ |
| 105 | vagrant box update --box voltha/voltha-base |
| 106 | |
| 107 | add-voltha-base: |
| 108 | @echo "Adding voltha-base vagrant box"; \ |
| 109 | vagrant box add voltha/voltha-base |
| 110 | |
| 111 | remove-voltha-base: |
| 112 | @echo "Removing all the voltha-base vagrant box versions"; \ |
| 113 | vagrant box remove voltha/voltha-base --all |
| 114 | |
| 115 | banner: |
| 116 | @echo |
| 117 | @echo "|------------------------------------------------------------------------|" |
| 118 | @echo "| _ ______ __ ________ ______ ____ ______ _____ ____ |" |
| 119 | @echo "| | | / / __ \/ / /_ __/ / / / /| | / ___ \/ ___ / ____/ ___| |" |
| 120 | @echo "| | | / / / / / / / / / /_/ / /_| | ___ / /__/ / /__/ / /___ /___ |" |
| 121 | @echo "| | |/ / /_/ / /___/ / / __ / ___ | |___| / /__/ / ___ \__ / /____ |" |
| 122 | @echo "| |___/\____/_____/_/ /_/ /_/_/ |__| /______/_/ /_/\____/_______| |" |
| 123 | @echo "| |" |
| 124 | @echo "|------------------------------------------------------------------------|" |
| 125 | @echo "| MAKING & UPLOADING VOLTHA-BASE VAGRANT BOX |" |
| 126 | @echo "|------------------------------------------------------------------------|" |
| 127 | @echo |
| 128 | @echo "VERSION ----> $(VERSION)" |
| 129 | |
| 130 | test-voltha-base: |
| 131 | @echo "Testing the recently created voltha-base"; \ |
| 132 | vagrant up; \ |
| 133 | ./test_script.sh |
| 134 | |
| 135 | run-voltha-base: |
| 136 | @echo "Running voltha-base vagrant box" |
| 137 | @echo "Stopping any running voltha-base vagrant box"; \ |
| 138 | vagrant halt; \ |
| 139 | vagrant destroy -f; \ |
| 140 | vagrant up |
| 141 | |
| 142 | package-voltha-base: |
| 143 | @echo "Packaging vagrant VM" |
| 144 | @echo "Removing previous package.box, if exists"; \ |
| 145 | rm package.box; \ |
| 146 | vagrant package |
| 147 | |
| 148 | create-version: |
| 149 | @echo "Creating a new version on Vagrant Cloud" |
| 150 | @echo "Version: $(VERSION)" |
| 151 | curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/versions \ |
| 152 | -X POST -H "X-Atlas-Token: $(TOKEN)" \ |
| 153 | -d version[version]=$(VERSION) \ |
| 154 | -d version[description]='This is the new version' | jq |
| 155 | |
| 156 | create-provider: |
| 157 | @echo "Creating a provider for the new version on Vagrant Cloud" |
| 158 | @echo "We have virtualbox as provider"; \ |
| 159 | curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/providers \ |
| 160 | -X POST -H "X-Atlas-Token: $(TOKEN)" \ |
| 161 | -d provider[name]='virtualbox' | jq |
| 162 | |
| 163 | upload-package: |
| 164 | @echo "Uploading the new package.box on Vagrant Cloud"; \ |
| 165 | echo $(VERSION); \ |
| 166 | url=$(shell curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/provider/virtualbox/upload?access_token=$(TOKEN) | jq '.["upload_path"]'); \ |
| 167 | echo $$url; \ |
| 168 | echo 'WAIT FOR IT....'; \ |
| 169 | curl -X PUT --upload-file package.box $$url |
| 170 | |
| 171 | release-version: |
| 172 | @echo "Releasing the version, so the box will be accessible to all users"; \ |
| 173 | curl https://atlas.hashicorp.com/api/v1/box/voltha/voltha-base/version/$(VERSION)/release \ |
| 174 | -X PUT -H "X-Atlas-Token: $(TOKEN)" | jq |
| 175 | |
| 176 | clean: |
| 177 | @echo "Cleaning up the voltha-base vagrant image"; \ |
| 178 | vagrant halt; \ |
| 179 | vagrant destroy -f |