how to deploy java web project using ant on gcloud vm instance - google-compute-engine

I have searched out for gcloud doc for java web project deployment but I got only maven project doc in result. Project already created in google cloud console and google sdk also installed.

One method is to simply connecting to the google cloud machine with sshexec & scp tasks in ant, and deposit a tarball and extract, an example might be..:
<target name="deploy-staging" description="Deploy to staging">
<input message="Staging Passphrase:" addproperty="my.password">
<handler classname="org.apache.tools.ant.input.SecureInputHandler" />
</input>
<!-- Create the new release folder on host-->
<sshexec trust="true"
host="hosthere"
username="username"
keyfile="${user.home}/.ssh/keyfile"
passphrase="${my.password}"
command="mkdir /var/www/releases/${git.revision}" />
<!-- Push the application tarball to the server-->
<scp trust="true"
file="${basedir}/build/${git.revision}.tar.gz"
todir="username#${hosthere}:/var/www/releases/${git.revision}"
keyfile="${user.home}/.ssh/keyfile"
passphrase="${my.password}"/>
<!-- Extract the tarball on the server-->
<sshexec trust="true"
host="${hosthere}"
username="username"
keyfile="${user.home}/.ssh/keyfile"
passphrase="${my.password}"
command="cd /var/www/releases/${git.revision}; tar -xvzf ${git.revision}.tar.gz" />
<sshexec trust="true"
host="${hosthere}"
username="username"
keyfile="${user.home}/.ssh/keyfile"
passphrase="${my.password}"
command="rm -rf /var/www/current" />
<sshexec trust="true"
host="${hosthere}"
username="username"
keyfile="${user.home}/.ssh/keyfile"
passphrase="${my.password}"
command="ln -s /var/www/releases/${git.revision} -T /var/www/current" />
</target>
The above isn't tested.. ended up using this whilst searching for a better way to handle gcloud instanced groups.

Related

Where to put "dotnet bundle" in .NET Core project (project.json replaced with *.csproj file)

Since the most recent .NET Core (I am actually using AspNetCore 1.1.2) has replace the project.json file with *.csproj it is still not clear to me where to put the "dotnet bundle", precompile option.
"scripts": {
"precompile": ["dotnet bundle"]
}
Prior the above block of json was found in the project.json file. Any clue where this goes? Is it already in some other configuration file? Below is a link that explains this change, and shows what the *.csproj file equivalent is to the project.json file:
https://learn.microsoft.com/en-us/dotnet/core/tools/project-json-to-csproj
As always, apologies for any incorrect vernacular here, .NET Core is new to me.
You can use Target and Exec to accomplish this in .csproj:
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
<Exec Command=”bower install” EnvironmentVariables=”Path=$(ExternalToolsPath)” />
<Exec Command="dotnet bundle" />
</Target>
See this answer on how to get dotnet bundle to work with new .csproj format.

How to include/copy static files inside final docker image using fabric8 tools

I'm using the Fabric8 Maven tool chain to build and deploy my Camel app on top of Openshift. I'm using the Camel Boot approach... My Mvn profile perform the following goals: clean install docker:build fabric8:json fabric8:appl.
Everything is ok! Except that I'm serving a static file (index.html) using Jetty as part of Camel route app. That file is located in $MY_PROJECT_DIR/src/main/resources. So, it goes to the app's classpath after a normal mvn build. But when using fabric8 build workflow, My app (Camel route) can't find that static content on filesystem classpath?
How can I specify fabric8 plugins to copy my static content inside /deployments of th final build image? Thus my camel endpoints ca refer to it on filesystem. I'm looking for something like maven-resources-plugin.
Well, digging into the src code I discovery you have two option to achieve this...
hawt-app-maven-plugin
if you are using hawt-app-maven-plugin [1], like me, you can use the hawt-app.source config property
during the package/build process all the contents of directory (which defaults to src/main/hawt-app) specified in hawt-app.source will be copied to the ${project.build.directory}/hawt-app/.
docker-maven-plugin
using the fabric8's docker-maven-plugin assembly configuration [2], you can pass a custom maven assembly descriptor. Like this one:
project's pom.xml
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.maven.plugin.version}</version>
<configuration>
<images>
<image>
<name>${docker.image}</name>
<build>
<from>${docker.from}</from>
<assembly>
<basedir>/deployments</basedir>
<!-- descriptorRef>hawt-app</descriptorRef -->
<descriptor>${project.basedir}/src/main/resources/hawt-app-custom-assembly.xml</descriptor>
</assembly>
hawt-app-custom-assembly.xml
<assembly ...>
<id>hawt-app</id>
<fileSets>
<fileSet>
<includes>
<include>bin/*</include>
</includes>
<directory>${project.build.directory}/hawt-app</directory>
<outputDirectory>.</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<includes>
<include>lib/*</include>
</includes>
<directory>${project.build.directory}/hawt-app</directory>
<outputDirectory>.</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
<!-- assembly extention... -->
<fileSet>
<includes>
<include>static-content/*</include>
</includes>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory>.</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
</assembly>
[1] https://github.com/fabric8io/fabric8/tree/master/hawt-app-maven-plugin
[2] https://maven.fabric8.io/#fabric8:build
[3] http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

Unable to add include ANE File in ANT Script

I wanted to create an ANT Script to create build in one click for my Flex Mobile Project.
My app using some native extension file (.ane file). When I tried to run the ANT script it saying -
An implementation for native extension 'com.example.mobile.extensions.NativeFeature' required by the application was not found for the target platform
I'm using the following code to include ane file in ANT Script.
<compiler.external-library-path dir="${basedir}/ane" append="true">
<include name="**/*.ane"/>
</compiler.external-library-path>
Also added the same extensionId in myApp-app.xml file which I used in my extension.xml file.
Solved this problem. Basically I need to add -extdr argument in ADT command. By adding -extdir ${basedir}/ane in ADT command I am able to resolve the problem. Added sample code below.
<target name="package.android" >
<echo message="Packaging for Android"/>
<exec executable="${ADT}" dir="${build.dir}/android">
<arg line="-package
-target apk
-storetype ${build.storetype}
-keystore ${android.cert}
-storepass ${android.cert.password}
${app.name}
${app.name}-app.xml
${app.name}.swf
-extdir ${basedir}/ane
"/>
</exec>
</target>

Developer Licence error when running WinRT unit tests using vstest.console.exe from the command line

I'm getting the following error when I try to execute WinRT MSTests from the command line:
EXEC : error : Could not start test run for unit tests for Windows Store app: No valid developer license found for running unit tests for Windows Store apps. Please install/renew your developer license..
This used to work, but has suddenly started failing. The odd thing is that they execute fine from within visual studio.
I'm using the following MSBuild task.
<Target Name="UnitTest" DependsOnTargets="Compile" >
<ItemGroup>
<TestAppx Include="$(SolutionDir)\**\*x86*\**\*Tests*.appx" />
</ItemGroup>
<Message Importance="high" Text="Running tests for %(TestAppx.Identity)" />
<Exec Command='"$(VSINSTALLDIR)\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" %(TestAppx.Identity) /InIsolation /platform:x86 /Logger:trx /UseVsixExtensions:true'
WorkingDirectory="$(SolutionDir)"/>
</Target>
Still not exactly sure why VisualStudio and vstest were out-of-sync, but I found a solution.
Open PowerShell as an administrator
Execute: Unregister-WindowsDeveloperLicense
Open the solution in visual studio
Log in to your live account when prompted to re-create your developer licence
Source: http://msdn.microsoft.com/en-us/library/windows/apps/hh974578.aspx#getting_a_developer_license_at_a_command_prompt

phing with phpdoc2 doesn't run

So I have a jenkins job to update a copy of my code and generate the phpdoc for my library, this is all done with phing
When I use these line in de build.xml it generates jsut fine (but with phpdocumentor 1.4.4)
<target name="phpdoc">
<echo msg="PHP Documentor..." />
<phpdoc title="API Documentation"
destdir="/var/www/corelib"
sourcecode="yes"
output="HTML:Smarty:PHP">
<fileset dir="./library/Core">
<include name="**/*.php" />
</fileset>
</phpdoc>
</target>
I want to use the new version of phpdocumentor so i installed it with pear
pear install phpdoc/phpDocumentor-alpha
But when I run this command (I found this in the phing docs), jenkins prints "PHP documentor" and then directly marks the build as failed
<target name="phpdoc">
<echo msg="PHP Documentor..." />
<phpdoc2 title="API Documentation" destdir="/var/www/corelib" template="responsive">
<fileset dir="./library/Core">
<include name="**/*.php" />
</fileset>
</phpdoc2>
</target>
I have zendserver installed on this server but that can't be a problem because phpdoc 1.4.4 runs fine
So how do i solve this?
Ok i found the solution, so i post it for future reference
With some help of the people on the irc channel of phpdocumentor
so this a bug with the latest build of phing in combination with the latest version of phpdocumentor. To fix this problem just revert the instalation of phpdocumentor2 to this version
phpDocumentor 2.0.0a3
This will fix the problem with phing and the documentation gets generated with no problem