Having Multiple buildpacks in cloudfoundry - java

I need to specify multiple buildpacks in my springboot application.
I have created a file multi-buildpack.yml in the root dir of my application where i have specified the 2 buildpacks.
multi-buildpack.yml File
buildpacks:
- https://github.com/cloudfoundry/python-buildpack
- https://github.com/cloudfoundry/java-buildpack
But i am getting the below error while pushing my app:
ERROR A multi-buildpack.yml file must be provided at your app root to use this buildpack.
Can anyone please help!
Thanks

Run the following command to ensure that you are using the cf CLI v6.38 or later:
$ cf version
To push your app with multiple buildpacks, specify each buildpack with a -b flag:
$ cf push YOUR-APP -b BUILDPACK-NAME-1 -b BUILDPACK-NAME-2 ... -b FINAL-BUILDPACK-NAME
The last buildpack you specify is the final buildpack, which can modify the launch environment and set the start command.
To see a list of available buildpacks, run cf buildpacks
More: https://docs.cloudfoundry.org/buildpacks/use-multiple-buildpacks.html

Unless you're on an older version of CloudFoundry, you shouldn't use the multi-buildpack buildpack anymore. True multi-buildpack support is available in the platform. Use that instead.
https://docs.cloudfoundry.org/buildpacks/use-multiple-buildpacks.html
This is currently a two step process due to some limitations with the current cf cli:
cf push YOUR-APP --no-start -b binary_buildpack
cf v3-push YOUR-APP -b BUILDPACK-NAME-1 -b BUILDPACK-NAME-2
That should go away at some point in the future and be just one command.
If you really want to use the multi-buildpack buildpack, double check the location of the multi-buildpack.yml file and the format of it. You can compare to one of the fixture tests here. Maybe even run one of the fixture tests to get a baseline test that works (or at least, should work).
Hope that helps!

Related

CloudFoundry and JDK

I'm struggling with the deployment of a spring app that needs to compile java code during runtime. My app calls the javac command when a user submits a solution to a problem, so it can later run java
I'm deploying to cloud foundry and using the java-buildpack, but unfortunately, it doesn't come with JDK, only JRE is available and that thing has no javac or java commands available.
Do you guys know a way on how to add JDK to cloud foundry, without having to write my own custom buildpack.
Thanks
I would suggest you use multi-buildpack support and use the apt-buildpack to install a JDK. It should work fine alongside the JBP. It just needs to be first in the list.
https://github.com/cloudfoundry/apt-buildpack
Example:
Create an apt.yml.
---
packages:
- openjdk-11-jdk-headless
Bundle that into your JAR, jar uf path/to/your/file.jar apt.yml. It should be added to the root of the JAR, so if you jar tf path/to/your/file.jar you should see just apt.yml and nothing prefixed to it.
Update your manifest.yml. Add the apt-buildpack first in the list.
---
applications:
- name: spring-music
memory: 1G
path: build/libs/spring-music-1.0.jar
buildpacks:
- https://github.com/cloudfoundry/apt-buildpack#v0.2.2
- java_buildpack
Then cf push. You should see the apt-buildpack run and install the JDK. It'll then be installed under ~/deps/0/lib/jvm/java-11-openjdk-amd64. It does not appear to end up on the PATH either, so use a full path to javac or update the path.

How do I install Spring Boot CLI in Ubuntu?

I am trying to install Spring Boot CLI in Ubuntu. I am new to spring boot and was trying to learn it. I have already installed Gradle and groovy but did not find anything online to install Spring boot CLI.
please follow the code
sudo apt install unzip zip
curl -s https://get.sdkman.io | bash
source "/home/username/.sdkman/bin/sdkman-init.sh"=
sdk install springboot
spring version
The Spring boot CLI install guide link
Spring boot CLI
You can read the docs for installation steps:
Manual installation:
Download the Spring CLI distribution: you can find the latest version link here.
Extract the downloaded zip file to any path of your choice.
Prerequisite: Make sure you have Java JDK v1.8 or above (check INSTALL.txt file from extracted archive in Step-1). You can check your JDK version using command: java --version.
Add the spring CLI script's path to $PATH environment variable:
For example, you can add below lines to your .bashrc file in *nix systems:
export SPRING_HOME=/path/to/your/extracted-spring-cli/spring-2.4.0
export PATH=$SPRING_HOME/bin:$PATH
After saving the .bashrc file, run $ source .bashrc to reload the environment variables you just added.
(optional; and not for Windows user) Shell auto-completion scripts are provided for BASH and ZSH with the extracted archive in Step-1. Add symlinks to the appropriate
location for your environment. For example, something like:
ln -s /path/to/your/extracted-spring-cli/spring-2.4.0/shell-completion/bash/spring /etc/bash_completion.d/spring
ln -s /path/to/your/extracted-spring-cli/spring-2.4.0/shell-completion/zsh/_spring /usr/local/share/zsh/site-functions/_spring
To check if you are using BASH or ZSH, run the command: $ echo $SHELL.
DONE: To test if you have successfully installed the CLI you can run the following command: spring --version.
Here is detailed instruction on how to do it, much more useful than official one, at least for manual installation. One more thing - to make path change permanent you might need to logout - login, as "source /etc/profile" will be effective only for currently opened terminal.
Use this link to get a detailed instruction on how to download the Spring framework successfully, It really helped me a lot after long time of making research.
https://www.decodejava.com/download-and-install-spring-framework.htm

Launch java application from inside eclipse with root privileges [duplicate]

I'm running in to an error when I try to run my server application from Eclipse. The error is java.net.BindException: Permission denied. I think this is because I am using port 443 to set up an SSL connection. I can get around this problem if I run my code on the command line using java and sudo. Is there a way to set up Eclipse so that when I hit the run button, my application is executed with sudo?
You can follow these steps to compile/debug applications as superuser.
Rename your java-application
sudo mv /usr/lib/jvm/java-6-openjdk/jre/bin/java /usr/lib/jvm/java-6-openjdk/jre/bin/java.ori
Create following script and store it as /usr/lib/jvm/java-6-openjdk/jre/bin/java
#!/bin/bash
# file: /usr/lib/jvm/java-6-openjdk/jre/bin/java
# descr: Starter for jdk. Runs jdk as root when
# cmd-line-arg "--run-as-root" is specified.
#
jre="/usr/lib/jvm/java-6-openjdk/jre/bin/java.ori"
run_as_root=false
args=
# Filter command-line argument
for arg in "$#"
do
case "$arg" in
--run-as-root) run_as_root=true
;;
*) args="$args $arg"
;;
esac
done
# Remove leading whitespaces
args=$(echo $args | sed -e 's/^[ \t]*//')
if $run_as_root
then
echo "WARNING: Running as root!"
gksu "$jre $args"
else
$jre $args
fi
Change the permissions to make it executable
sudo chmod 0755 /usr/lib/jvm/java-6-openjdk/jre/bin/java
Startup eclipse
Go to Window->Preferences->Java->Installed JREs
Duplicate java-6-openjdk to java-6-openjdk-root
Edit JRE and add "--run-as-root" as Default VM Argument
To run projects as root you need to follow these steps:
Go to Project->Properties->Java Build Path
Double-Click the JRE System Library and choose in Alternate JRE "java-6-openjdk-root"
Note: The idea is from http://www.eclipse.org/forums/index.php/mv/msg/87353/724852/#msg_724852
Assuming you are on Linux (*nix),
How about starting your eclipse session via a sudo command?
Such as
sudo ~/eclipse/eclipse
Now whatever you do from eclipse will have the sudo context?
As mentioned in this thread:
In order to open a port below 1024 on Unix/Linux systems you need to be
"root".
I also used the argument -Dorg.eclipse.equinox.http.jetty.port=8080 to change the listen port, but this seems to be ignored (according to the stacktrace)
Please use "-Dorg.osgi.service.http.port=8080".
As mentioned in HTTP Service:
org.osgi.service.http.port - specifies the port number to use for the http serving. The default value for this property is 80 (which requires root permission), as per the OSGi specification.
org.osgi.service.http.port.secure - specifies the port number to use for secure http serving. The default value for this property is 443 (which requires root permission), as per the OSGi specification.
Maybe if you try to modify that last property to a value above 1024 it could work without requiring any special privilege.
Another option would be to use iptables or ipfilter to forward port 80 to a port above 1024.
(Can someone contribute a link to a practical and easy-to-understand explanation ?)
A better answer, perhaps, if this serves your needs AND is possible, could be simple port redirection on your router.
Instead of trying to force your linux/unix to open a reserved port, when you are only developing this now (not installing) and you want to run it in a debugger,
set your router to redirect incoming (external) port 443 to a port that is more convenient for your current needs (say 4443).
I think most routers support this, and if yours doesn't it gives your mum a good christmas or birthday present idea!
I am writing C not Java but this should work in either case.
I use remote debug - define a "remote" connection to LOCALHOST which allows you to specify the user you will connect with, specify ROOT. Then define a Remote Application in debug configuration connection: LOCALHOST. Be sure to check "skip download to target path" at the bottom of the main tab as well as under the connection properties window.
You can use Remote Java Application mechanism for this.
Create Debug configuration for Remote Java Application
section in Run -> Debug configurations...
Set your project name
Choose Connection type as Standard (Socket Attach)
Configure Connection properties parameters for your binding
(for you it will be localhost and 443).
Set breakpoint in your app (e.g. at the beginning of the main method)
Run your app from terminal as superuser with following command: java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=443 MyApp
Hit debug button in Eclipse for early created Remote Java Application
You code should be stopped on breakpoint in Eclipse!
If you use External tools (Run menu/External tools or an icon next to the Run/Debug icons on the toolbar), you can use any scripts or whatever you like. The scripts may give you elevated rights, or whatever.
On the other hand, this way debugging the application can become very hard, as neither the Run nor Debug commands get associated with this External tool configuration. Maybe it is possible to connect the Eclipse debugger of the application, but I don't know, how that is possible.
You may go this way
create a Makefile with javac calls
add the following line:
setcap 'cap_net_admin=+ep' Server
configure sudo to allow your Eclipse user to run setcap.
So you will have a transparent debugging (no sudo wrapper - gdb ok).
Cons: it is a local security breach.
Solution:
put this to /opt/my-stupid-eclipse
#!/bin/sh
setcap 'cap_net_admin=+ep cap_net_raw=+ep' $1
chmod +x this script and whitelist it on sudo config.
username ALL=(ALL) NOPASSWD: /opt/my-stupid-eclipse
Add it to your makefile, specify path to your Server binary.
Now you have pretty strange but secure script, that cannot be changed by other users... and still a little breach for replacing Server binary with any malicious code, that will gain caps, so no filename check/stricts will help.. can $1 be contaminated with bash commands, no? Guess, no.

Local embedded HTTP server that can respond to git commands?

I'm building a Git client in Java and would like to write automated tests that verify if Git commands running on an HTTP(s) server are running correctly. I've seen any number of local small Java HTTP servers, but it's unclear to me what would be involved in making them respond correctly to Git commands. I'm trying to avoid installing a local HTTP server because I'd like these automated tests to run anywhere. Can anyone point me in the right direction?
FYI, for ssh remote testing, I'm having fantastic success with the sshd mina system, and using its built-in GitPackCommandFactory. Something similar to HTTP(s) would be wonderful.
The smart HTTP protocol of git is implemented in git-http-backend. This is a CGI binary that can be used in combination with some web-servers. Unfortunately it ignores the content-length of the request and relies on the server to close its input, which makes it incompatible with some CGI servers.
If you have python available, an easy way to run it would be using the CGIHTTPServer. This one is affected by the mentioned incompatibility. With a rather ugly workaround you can nevertheless make it work:
$ python -c 'import CGIHTTPServer; CGIHTTPServer.CGIHTTPRequestHandler.have_fork = False; CGIHTTPServer.test()' 8000
Or with python 3:
$ python3 -c 'import http.server; http.server.CGIHTTPRequestHandler.have_fork = False; http.server.test(HandlerClass=http.server.CGIHTTPRequestHandler, port=8000)'
These set the internal have_fork of CGIHTTPRequestHandler to False which causes the implementation to use subprocesses and pipes instead of fork to run the CGI binary. With this method, the incoming requests are buffered and written to a pipe, which is then closed. This fits the expected model of git-http-backend and therefore makes it work.
If you are on a system without fork in the first place (i.e. Windows) you don't need the workaround and can directly use:
$ python -m CGIHTTPServer 8000
$ python3 -m http.server --cgi 8000
Both setups require that git-http-backend is made available under a cgi-bin directory. The easiest setup is to create the cgi-bin directory inside a bare git repository, symlink or copy the git-http-backend binary into it and start the server from the bare repository:
$ git clone --bare <repo> bare.git
$ cd bare.git
$ touch git-daemon-export-ok
$ mkdir cgi-bin
$ ln -s /usr/lib/git-core/git-http-backend cgi-bin/git
$ python -c 'import CGIHTTPServer; CGIHTTPServer.CGIHTTPRequestHandler.have_fork = False; CGIHTTPServer.test()' 8000
With that setup, the repository is served at http://localhost:8000/cgi-bin/git because git-http-backend was symlinked to cgi-bin/git. So the following should then work:
$ git clone http://localhost:8000/cgi-bin/git clonedRepoName
To allow pushing into the bare repository use:
$ git config http.receivepack true
More advanced setups, with more than one repository served, can be made using the appropriate environment variables. Since the environment is inherited by the server and passed to the CGI binary, simply exporting the desired environment variables should work. See the git-http-backend documentation for all possible configuration and environment variables.
Based on Gustave's suggestion, I've discovered SimpleHTTPServer within JGit. Works like a charm. Thank you!

Unable to install new relic on linux using tomcat server

I have created account on new relic and downloaded zip for new relic agent and uploaded to /etc directory in my linux machine(tomcat server).
As per documentations, I follow the following code
cd /etc/newrelic
java -jar newrelic.jar install
But I am getting following error:
Dec 31, 2013 06:14:04 +0000 NewRelic 1 INFO: Agent is using Logback
***** ( ( o)) New Relic Java Agent Installer
***** Installing version 3.2.3 ...
Could not edit start script because:
.:. Could not locate a Tomcat, Jetty, JBoss, JBoss7 or Glassfish instance in /etc
Try re-running the install command with the -s <AppServerRootDirectory> option or from <AppServerRootDirectory>/newrelic.
If that doesn't work, locate and edit the start script manually.
No need to create New Relic configuration file because:
.:. A config file already exists: /etc/newrelic/newrelic.yml
***** Install incomplete
***** Next steps:
For help completing the install, see https://newrelic.com/docs/java/new-relic-for-java
Can anyone give me solution for this?
As the log information provide that it Could not locate a Tomcat, you need to provide env var like TOMCAT_HOME and so on.
In linux, even if you have installed some software, it can not be conveniently used without adding into PATH or some other env var.
In your situation, seems you need to add TOMCAT_HOME and export it.
Make sure the tomcat is correctly installed!
I was dealing with the same error, you only need to copy the new-relic.jar file inside the root of your tomcat server and then type:
java -jar new-relic.jar install
And that's it, it worked for me. Hope it helps
I work in support at New Relic, specializing in the Java agent.
Since Tomcat installations vary between Linux environments, your best bet is to follow the manual installation instructions:
https://docs.newrelic.com/docs/java/java-agent-manual-installation
Scroll down to the Tomcat instructions, which advise you to add the -javaagent flag to your Tomcat startup script. Once you've made that change and started your Tomcat instance, you can verify that the newrelic.jar is included in the startup arguments by issuing a ps -ef | grep java command.
If you need further help, please open a support ticket at support.newrelic.com and we'll be glad to assist.
Before installing the New Relic the code will fetch the requisite environment parameters like JAVA_HOME, TOMCAT_HOME, etc ( depends on your configuration) and then install the agent on your server. Make sure all the required env variables are defined.
After you have done the above, also check the following:
a) The New Relic should be extraced/installed in your home directory ( in my case /APP)
cd /APP
Unzip newrelic-java-3.26.1.zip –d /APP
b) The Java agent should be defined in the local properties file ( I have configured it for Hybris server in Dev environment)
vim /APP/hybris/config/local.properties
Add : -javaagent:/APP/newrelic/newrelic.jar –D newrelic.environment=Development
c) In some cases, it requirs the application specific yml file along with the newrelic.yml file ( in my case hybris.yml)
Cd /APP/newrelic
mkdir extensions
chmod 755 extensions
cd /APP/newrelic/extensions
vim hybris.yml
Hybris specific configuration for the hybris.yml file ( use jmx.yml)
Add the jmx.yml data in the hybris.yml after creating the file.
d) Restart your application:
I did it using the following commands:
cd /APP/hybris/bin/platform
ant clean all
e) You should see the data in sometime. Keep monitoring the new relic logs in:
tail -f /APP/newrelic/logs/newrelic_agent.log
Before you do any of these steps, make sure that your new relic folder is in inside the folder of your server. That immediately fixed my problem.
The folder newrelic belongs to /usr/share/tomcat/. At least on Ubuntu 16.04 with Tomcat 7. Then also the install command works. Please do not forget to read and adapt the whole newrelic.yml file.

Categories