Updated build to create wheel and push to Pypi 31/26931/1
authordfilppi <dewayne@cloudify.co>
Tue, 26 Dec 2017 21:54:15 +0000 (21:54 +0000)
committerdfilppi <dewayne@cloudify.co>
Tue, 26 Dec 2017 21:59:19 +0000 (21:59 +0000)
Change-Id: I8cb80cf56ed5c0d459a64af8c6a9198c1c4f9fae
Issue-ID: SO-362
Signed-off-by: DeWayne Filppi <dewayne@cloudify.co>
aria/aria-rest-server/build.py [new file with mode: 0644]
aria/aria-rest-server/pom.xml
aria/aria-rest-server/src/main/python/aria-rest/setup.py

diff --git a/aria/aria-rest-server/build.py b/aria/aria-rest-server/build.py
new file mode 100644 (file)
index 0000000..6076c2f
--- /dev/null
@@ -0,0 +1,77 @@
+import subprocess
+import os
+import sys
+import glob
+import xml.etree.ElementTree as etree
+
+# create and enter venv
+def create_venv( name):
+    if subprocess.call("virtualenv {}".format(name), shell = True):
+        raise Exception("virtualenv create failed")
+    ret = subprocess.call(". {}/bin/activate && python {} run". \
+                    format(name,__file__), shell = True)
+    sys.exit(ret)
+
+def init_venv():
+    subprocess.call("pip install -U pip", shell = True)
+    subprocess.call("pip install -U setuptools", shell = True)
+    subprocess.call("pip install wheel", shell = True)
+    subprocess.call("pip install twine", shell = True)
+
+
+if len(sys.argv) == 1:
+    create_venv ("mavenvenv")
+else:
+    init_venv()
+
+    if os.environ['MVN_PHASE'] == 'package':
+        wheelname = os.environ['WHEEL_NAME']
+        inputdir = os.environ['INPUT_DIR']
+        outputdir = os.environ['OUTPUT_DIR']
+        savedir = os.getcwd()
+        os.chdir(inputdir)
+
+        if subprocess.call( [ "python",
+                             "setup.py",
+                             "bdist_wheel",
+                             "-d",
+                             outputdir
+                             ]):
+            sys.stderr("wheel create failed")
+            sys.exit(1)
+        f = glob.glob(outputdir+"/*.whl")[0]
+        os.rename(f , outputdir+"/"+ wheelname)
+
+    elif os.environ['MVN_PHASE'] == 'deploy':
+
+        it = etree.iterparse(os.environ['SETTINGS_FILE'])
+        for _, el in it:
+            el.tag = el.tag.split('}', 1)[1]  # strip namespace
+        settings = it.root
+
+        username = settings.find('.//server[id="{}"]/username'.format(
+                                os.environ['PYPI_SERVERID'])).text
+        password = settings.find('.//server[id="{}"]/password'.format(
+                                os.environ['PYPI_SERVERID'])).text
+
+        try:
+            if subprocess.call( [ "twine",
+                             "upload",
+                             "--username",
+                             username,
+                             "--password",
+                             password,
+                             "--repository-url",
+                             os.environ["PYPI_SERVER_BASEURL"],
+                             os.environ["WHEEL_PATH"]
+                             ] ):
+                sys.stderr.write("pypi upload failed")
+                sys.exit(1)
+        finally:
+            subprocess.call("rm -rf mavenvenv", shell = True)
+
+        sys.exit(0)
+    else:
+        sys.stderr.write("Unrecognized phase '{}'\n".format(
+            os.environ('MVN_PHASE')))
+        sys.exit(1)
index 7af381c..cf39f26 100644 (file)
     <version>1.1.0-SNAPSHOT</version>
   </parent>
 
-  <pluginRepositories>
-    <pluginRepository>
-      <id>jitpack.io</id>
-      <url>https://jitpack.io</url>
-    </pluginRepository> 
-  </pluginRepositories>
-
   <properties>
-    <python_version>2.7</python_version>
+    <python_version>2</python_version>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <wheel.name>${project.artifactId}-${python_version}-py2-none-any.whl</wheel.name>
+    <wheel.name>${project.artifactId}-${project.version}-py${python_version}-none-any.whl</wheel.name>
     <python.sourceDirectory>${project.basedir}/src/main/python/aria-rest</python.sourceDirectory>
+    <onap.nexus.pypiserver.baseurl>http://192.168.33.1:8081/repository/pypi-internal/</onap.nexus.pypiserver.baseurl>
+    <onap.nexus.pypiserver.serverid>ecomp-snapshots</onap.nexus.pypiserver.serverid>
   </properties>
   <build>
     <plugins>
              <failIfNoMatch>false</failIfNoMatch>
            </configuration>
          </execution>
-         <execution>
-           <id>attach-artifacts</id>
-           <phase>package</phase>
-           <goals>
-             <goal>attach-artifact</goal>
-           </goals>
-           <configuration>
-             <artifacts>
-               <artifact>
-                 <file>${project.build.directory}/maven-python/dist/${wheel.name}</file>
-                 <type>whl</type>
-               </artifact>
-             </artifacts>
-           </configuration>
-         </execution>
        </executions>
       </plugin>
       <plugin>
-       <groupId>com.github.UltimateDogg</groupId>
-       <artifactId>maven-python-distribute-plugin</artifactId>
-       <version>0.2.0</version>
-       <configuration>
-         <packageVersion>${python_version}</packageVersion>
-         <sourceDirectory>${python.sourceDirectory}</sourceDirectory>
-         <distributionType>wheel</distributionType>
-       </configuration>
+       <groupId>org.codehaus.mojo</groupId>
+       <artifactId>exec-maven-plugin</artifactId>
+       <version>1.6.0</version>
        <executions>
          <execution>
-           <id>package</id>
-           <phase>prepare-package</phase>
-           <goals>
-             <goal>package</goal>
-           </goals>
-         </execution>
-         <execution>
-           <id>process</id>
-           <phase>process-sources</phase>
-           <goals>
-             <goal>process-sources</goal>
-           </goals>
+            <id>package</id>
+           <phase>package</phase>
+           <goals><goal>exec</goal></goals>
+           <configuration>
+              <executable>python</executable>
+              <arguments>
+               <argument>${session.executionRootDirectory}/build.py</argument>
+             </arguments>
+             <environmentVariables>
+               <MVN_PHASE>package</MVN_PHASE>
+               <WHEEL_NAME>${wheel.name}</WHEEL_NAME>
+               <INPUT_DIR>${session.executionRootDirectory}/src/main/python/aria-rest</INPUT_DIR>
+               <OUTPUT_DIR>${project.build.directory}</OUTPUT_DIR>
+              </environmentVariables>
+           </configuration>
          </execution>
-       </executions>
+          <execution>
+            <id>deploy</id>
+           <phase>deploy</phase>
+           <goals><goal>exec</goal></goals>
+           <configuration>
+              <executable>python</executable>
+             <arguments>
+               <argument>${session.executionRootDirectory}/build.py</argument>
+             </arguments>
+             <environmentVariables>
+               <MVN_PHASE>deploy</MVN_PHASE>
+                <PROJECT_VERSION>${project.version}</PROJECT_VERSION>
+               <DOCKERREGISTRY_SNAPSHOT>${onap.nexus.dockerregistry.snapshot}</DOCKERREGISTRY_SNAPSHOT>
+               <DOCKERREGISTRY_RELEASE>${onap.nexus.dockerregistry.release}</DOCKERREGISTRY_RELEASE>
+                <PYPI_SERVER_BASEURL>${onap.nexus.pypiserver.baseurl}</PYPI_SERVER_BASEURL>
+               <PYPI_SERVERID>${onap.nexus.pypiserver.serverid}</PYPI_SERVERID>
+               <WHEEL_PATH>${project.build.directory}/${wheel.name}</WHEEL_PATH>
+             </environmentVariables>
+           </configuration>
+          </execution>   
+        </executions>
       </plugin>
     </plugins>
   </build>
index 81beb0f..84e9a19 100644 (file)
@@ -34,6 +34,7 @@ setup(
     license='LICENSE',
     description='Aria REST API for ONAP',
     install_requires=[
+        'distribute',
         'Flask==0.12.2',
         'flask-autodoc==0.1.2',
         'apache-ariatosca==0.1.1'