How do I upload a webpage to Bluemix using the cf CLI? - cloud-foundry

I'm trying to upload an index.html page to Bluemix using the cf CLI. I'm not sure if I'm approaching this with the right mentality. I'm thinking of uploading this HTML file as we usually do with normal hosting services, through FTP. With Bluemix I assume I should be using the push command in cf and treat this index.html as an app. Is this right?
If this is right, I'm not getting how to use this command. Can you give me an example of full command to push/upload this page?

The cf push command would be the one to use to 'upload' your application to the Bluemix server. However, it does more than just upload. In Bluemix there is a concept of a runtime or buildpack, the idea being this will be the runtime to run your application. So if you uploaded a Java application you would pair it with the Java Liberty Buildpack/runtime. If you uploaded a PHP application then you would pair it with the PHP buildpack.
If you pushed just a HTML file with no buildpack then you would likely get an error indicating the buildpack could not be determined. Bluemix tries to guess the type of buildpack you want based on the type of files uploaded, and then pull the buildpack from an internal cache. The cf push command allows you to explicitly state the buildpack to use -b so there is no guess work and no need to rely on only the buildpack that Bluemix currently knows about.
In your case, for a static HTML file you would need some type of http server like nginx as the 'runtime'. Notice that Bluemix currently does not have a built-in buildpack for this, so you'd have to get it from somewhere else. There are a few buildpacks available already, but the best one to use would be this one: https://github.com/cloudfoundry-community/staticfile-buildpack . To use it simply supply that url with the -b option on the cf push command from the root directory of your application i.e.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack
Be sure you are issuing this command from your app directory.
The yourappname will be part of the URL for your website/app
For an actual example, we will upload your index.html which exist in folder C:\Users\XYZ\Documents\projects\ProjectHelloWorld and we will call this app HelloWorld. Here is what we would do:
C:\> cd C:\Users\XYZ\Documents\projects\ProjectHelloWorld
C:\Users\XYZ\Documents\projects\ProjectHelloWorld> cf push HelloWorld -b https://git
hub.com/cloudfoundry-community/staticfile-buildpack
Bluemix will then upload everything in that local directory to the server and also grab the buildpack from the URL location and stage your application code with the buildpack, Bluemix will then attempt to start the application. This is an example Bluemix output when the push command succeed:
Creating app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
OK
Creating route HelloWorld.mybluemix.net...
OK
Binding HelloWorld.mybluemix.net to HelloWorld...
OK
Uploading HelloWorld...
Uploading app files from: C:\Users\XYZ\Documents\projects\ProjectHelloWorld
Uploading 1M, 21 files
Done uploading
OK
Starting app HelloWorld in org xyz#gmail.com / space test as xyz#gmail.com...
-----> Downloaded app package (960K)
Cloning into '/tmp/buildpacks/staticfile-buildpack'...
grep: Staticfile: No such file or directory
-----> Using root folder
-----> Copying project files into public/
-----> Setting up nginx
grep: Staticfile: No such file or directory
-----> Uploading droplet (3.4M)
1 of 1 instances running
App started
OK
Showing health and status for app HelloWorld in org xyz#gmail.com / space
test as xyz#gmail.com...
OK
requested state: started
instances: 1/1
usage: 1G x 1 instances
urls: HelloWorld.mybluemix.net
last uploaded: Tue Nov 25 14:50:44 +0000 2014
For more details:
See the github page for the buildpack on how to structure your application (public folder etc)
See Bluemix Docs website. It has a lot of demos and examples.
See Takehiko Amano's Bluemix demo. Is a good and easy to understand demo.

you can either deploy your app directly using "cf push ..." or via creating a manifest.yml file.if you create manifest.yml file inside you app code path,only cf push is sufficient.
below is the reference link for this:
http://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html
Hope it clears your doubt!!

Yeah as whitfiea mentioned its pretty simple. You need to use the cf push command. For example if you had a static website with an index.html file.
For example the following.
[02:30 PM] jsloyer#jeffs-mbp [friendme]>ls
index.html
To push that app to Bluemix run the following.
cf push yourappname -b https://github.com/cloudfoundry-community/staticfile-buildpack.git

https://www.ng.bluemix.net/docs/#starters/index.html
In this browse Creating Web Apps->Building a web app-> Uploading an app
It says;-
You can use a sample Java™ web application to get started. This sample application displays the list of environment variables that are available. You can download the sample Java web application from the community sample site. The sample application contains a single JSP and the WEB-INF/web.xml file.
Extract the downloaded file, and a new directory that contains the application is created. From the newly created application directory, issue the cf push command. In the following example, you can use a unique name testEnv for the application and 512M for memory allocation. The name must be unique in the whole Bluemix environment.
$ cf push testEnv -m 512m
->So as per your requirement, you can add your html file along with the JSP file before uploading the application.
Hopefully this help...

Related

how to run a one-off task on cloudfoundry to upload data before starting Python app

Hi this is my first experience trying to deploy a Python app on cloud using CF. I am having issues deploying my app; I sincerely appreciate if anyone can help me or point me to the right direction to solve the issue.
The main problem is the app that I am trying to deploy is large size due to a lot of python dependencies. The size of my app directory is 200 Kb. The first error I observed was: Staging fails due to "Failed to upload payload for droplet" . I think the reason is when all Python dependencies are downloaded from requirements.txt file and finally the droplet is created its size is too large for upload. The droplet size=982. 3 Mb.
The first solution I tried was vendoring app where I created a vendor directory containing all python dependencies but the size of vendor directory was greater that 1Gb, which causes the upload size exceed 1Gb limit and leads to failure in uploading app files.
The second solution I am working on is to upload all installed Python libraries on an object store (in my case S3 bucket which is bounded to my app) and then download the dependencies folder called Pypackages to the app's root directory: /home/vcap/app, so I want to have /home/vcap/app/Pypackages exist before my app starts on the cloud. But I couldn't do it successfully yet. I have included a python script in my app directory which downloads files from S3 bucket successfully. (I have put the correct absolute path for download in downloadS3.py script ie, /home/vcap/app/Pypackages) I want to run this script using "python downloadS3.py" as a one-off task. First I tried the solution here : Can I have multiple commands run in a manifest.yml file?
and although I can see the status of the task is SUCCEED via '$cf tasks my-app-name' , /home/vcap/app/Pypackages does not exist.
I also tried to run one-off task as the steps below:
1-
$ cf push -c 'python downloadS3.py && sleep infinity' -i 1 --no-route
2-
$ cf push -c 'null'
I have printed the contents of /home/vcap/app on my app, ie when app is started and I enter the url in my browser (I don't know what is the right way to see the contents of root directory). Anyway, the problem is Pypackages are not downloaded to the correct root directory. I am not sure if I am running the one-off task in a wrong way or if there is a better solution to make my app work.
I appreciate any helps! (edited)
Diego Cells stage apps and upload droplet to blobstore via cloud controller, the max file can be uploaded is configurable at Ops Manager > TAS for VMs > Application Developer Control > Maximum File Upload Size (MB), default is 1024MB. Seems this is causing restriction, if you can get it increased with your admin help...
Tasks run in their own containers so possibly not an option. I think Python buildpack collects and install the packages before creating the droplet, so don't think copying packages directly to /app directory will be of much help.
If you have data files then you can use .profile file and do some scripting to copy them from S3 or server/NFS location into the /app directory. Something like
wget http://s3.location.com/data_files
cp data_files /home/vcap/app/
But if all these are packages and increasing the size is not feasible then you may need to look to break the app..

Google Cloud Run not loading JS/Part of Bootstrap/Part of Flask engine/Part of static files

I've deployed my web app on google cloud today but when I open the link to my website only the HTML/almost no JS/flask functions, only some elements of bootstrap work (mostly the responsiveness that cols/rows provide, not e.g. the navbar collapse etc.) and most of the pictures I've stored in my static files aren't getting displayed as well. I suppose my Javascript doesn't work because most HTML/CSS properties provided by me / bootstrap are still working. When I run the container without cloud run everything works as it should. I run the container with gunicorn as my WSGI Server.
This is my file tree of the webapp
I created the image with docker:
-docker build -t styleit .
Then I used this https://cloud.google.com/container-registry/docs/pushing-and-pulling to push my container to container registry:
-docker tag styleit eu.gcr.io/styleit/styleit (my project-id is styleit as well)
-docker push eu.gcr.io/styleit/styleit
Then I used these (1) (2) configurations for the cloud run setup.
Please don't be easy on me if I did something wrong, I want to learn how the cloud infrastructure works ^^

Copy a folder to Pivotal Cloud Foundry

I m running a jar application that uses some resources folder that needs to be in the same path as the jar:
here is an example of my folder how it uses to be :
$ ls
__files mappings wiremock-standalone-2.24.0.jar
I'm able to push the jar file using
cf push wiremock-standalone-2.24.0.jar
But not able to push the two folders mappings and __files to pcf.
When I do :
cf push wiremock/__files
Ittries to create an app named wiremock/__files:
Getting app info...
Creating app with these attributes...
+ name: wiremock/__files
path: /tmp/build/2985dd2f
What is the command line I should use ?
What you could do is add all missing files to your JAR package:
cp wiremock-standalone-2.24.0.jar wiremock-standalone-2.24.0-fat.jar
jar uf wiremock-standalone-2.24.0-fat.jar ./lib
Than your command will be exactly the same all you have to do is point to the new resources inside the Java app.
cf push is used to deploy an application to a container. Anything that is deployed with cf push is expected to be an executable app. Even if you were able to cf push wiremock/__files successfully, the files would end up in a different container and inaccessible from the container created for cf push wiremock-standalone-2.24.0.jar.
It sounds like you need the jar file, __files, and mappings to all be in the same container. To make this happen, you'll need to bundle them all into an archive and cf push them together.
As suggested by #Alex Rashkov, I added the files to the jar and that worked perfectly.
My problem was exactly the same as in the original question, I want to deploy wiremock to PCF with pre-configured mappings, so I did the following:
Started the wiremock server locally and defined the required mappings via the REST api (/__admin/mappings/import or /__admin/mappings/new)
Saved the mappings (__admin/mappings/save)
Now all the mappings will appear as files in the mappings directory
Add the mappings directory to the jar file (jar -uf wiremock-standalone-2.24.0.jar mappings). I just updated the downloaded jar file directly, but I can see where you might want to update a copy as suggested above.
push the updated jar file to PCF (java_buildpack). The wiremock server running in PCF will see the mappings in the mappings folder and have those predefined.
Thanks #Alex Rashkov for the tip!

How to specify the root folder to deploy an app using the Cloud SDK?

I'm using "Google App Engine" from GCP to host a static website. I already created the website files (HTML, JS) and yaml using Visual Studio Code. I have the folder with those files stored locally in my local computer.
I downloaded the Cloud SDK Shell for Windows. I logged in to my account, and selected the project. According to videos and tutorials, I need to deploy the app using "gcloud app deploy".
However I got an error saying that an "app.yaml" file is required to deploy this directory...
I'm trying to follow this tutorial:
https://cloud.google.com/appengine/docs/standard/python/getting-started/hosting-a-static-website#before_you_begin
I'm also trying to follow the steps contained in this video:
https://www.youtube.com/watch?v=mlcO7nfQzSg
How do I specify the root folder where I have my "app.yaml" file?
Thanks in advance!!
I already tried with many commands and unfortunately none of them have worked
The particular case in which gcloud app deploy works without additional arguments is for single-service applications only and only if the command is executed in the directory in which the service's app.yaml configuration file exists (and has that exact name, can't use a different name).
For other cases deployables can/must be specified. From gcloud app deploy:
SYNOPSIS
gcloud app deploy [DEPLOYABLES …] [--bucket=BUCKET] [--image-url=IMAGE_URL] [--no-promote] [--no-stop-previous-version]
[--version=VERSION, -v VERSION] [GCLOUD_WIDE_FLAG …]
DESCRIPTION
This command is used to deploy both code and configuration to the App
Engine server. As an input it takes one or more DEPLOYABLES that
should be uploaded. A DEPLOYABLE can be a service's .yaml file or a
configuration's .yaml file (for more information about configuration
files specific to your App Engine environment, refer to
https://cloud.google.com/appengine/docs/standard/python/configuration-files
or
https://cloud.google.com/appengine/docs/flexible/python/configuration-files).
Note, for Java Standard apps, you must add the path to the
appengine-web.xml file inside the WEB-INF directory. gcloud app
deploy skips files specified in the .gcloudignore file (see gcloud
topic gcloudignore for more information).
So apart from running the command with no arguments in the directory in which your app.yaml exists is to specify the app.yaml (with a full or relative path if needed) as a deployable:
gcloud app deploy path/to/your/app.yaml
IMHO doing this is a good habit - specifying deployables is more reliable and is the only way to deploy apps with multiple services or using routing via a dispatch.yaml file.
gcloud app deploy will look at the current directory first for app.yaml. Generally you will change to the directory with app.yaml and your other files before deploying

Laravel showing error from /var/app/ondeck after deployment aws elasticbeanstalk

After having successfully deployed my laravel 5.4 app using AWS Elasticbeanstalk, Laravel throws InvalidArgumentException in FileViewFinder exception saying View [index] not found when i access my root route.
Here is a snippet of the stack trace.
in FileViewFinder.php line 137
at FileViewFinder->findInPaths('index', array('/var/app/ondeck/resources/views')) in FileViewFinder.php line 79
at FileViewFinder->find('index') in Factory.php line 128
at Factory->make('index', array(), array()) in helpers.php line 914
at view('index') in HomeController.php line 24
As you can see, Laravel it trying to find the view from /var/app/ondeck which as far as i know is the temporary location during deployment not after deployment. I've search everywhere and I can't seem to find a similar issue.
Any help on it will be appreciated.
After battling with it, I managed to use a post deployment script /opt/elasticbeanstalk/hooks/appdeploy/post/artisan_clear_cache.sh to run php artisan config:cache. Laravel caches the view path to point to ondeck directory so after deployment the cache needs to be cleared. Unfortunately this method is not documented. So I worked around it this way.
I had to create the directory that will contain the post deploy hook because it didnt exists by default. Running mkdir /opt/elasticbeanstalk/hooks/appdeploy/post will do.
I had to set the permissions for Laravel to write to storage. Running chmod -R 755 /var/app/current/storage will do.
Finally i had to put artisan command within the .sh.
This way the script will automatically run post deployment and clear the cache.
Note that all of this has to be done in a .config file in the .ebextensions directory within your project root. More details on that here