GAE dont run composer after deploy - google-app-engine

I develop a simple app for GAE on php.
In local env all is ok, but after "gcloud app deploy" a have an error about autoload.php - No such file or directory.
I use composer only for autoload my classes - not an external dependences.
GAE standard, project without billing
What i do locally:
composer install
dev_appserver.py app.test.yaml
and aplication is working perfect.
But after deploy:
PHP Fatal error: require_once(): Failed opening required '/base/data/home/apps/***/vendor/autoload.php' (include_path='.;/base/data/home/apps/***/;/base/alloc/tmpfs/dynamic_runtimes/php55_dynamic/fc2f1b4915ea2bca/sdk') in /base/data/home/apps/***/webhook.php on line 8
Line 8:
require_once __DIR__ . '/vendor/autoload.php';
composer.json
{
"autoload": {
"psr-4": {
"Core\\": "Classes/",
"Telegram\\": "Classes/Telegram",
"PushEvent\\": "Classes/PushEvent"
}
}
}
So now i delete vendor from .gcloudignore - and app is work on GAE, but this thing make me sad :(

You can explicitly tell GAE to run the composer install or composer dump-autoload.
{
"scripts": {
"gcp-build": [
"composer install"
]
}
}
Tip1: GAE caches the install files, and sometimes you may want to not use it: gcloud beta app deploy --no-cache]
Tip2: I recommend you to change the document root of the application in app.yaml to not expose the vendor dir to the outside world.
runtime_config:
document_root: public
Directory structure:
src
- OtherFolder //PSR-4
- ClassA.php
public
- index.php
vendor
- autoload.php
- ...
compose.json
app.yaml
The require will have to reference the parent folder
require_once __DIR__ . '/../vendor/autoload.php';
And the composer.json only needs one psr4 entry
{
"autoload": {
"psr-4": {
"MyApp\\": "src/"
}
}
}

Related

How to pass -ldflags to GAE build?

I have an HTTP service written in Go. Inside main.go I have a global version string.
package main
var version string
Locally, I build using -ldflags "-X main.version=$VERSION where $VERSION is determined by the shell environment, like so:
VERSION=v0.16.0 go build ./cmd/app -ldflags "-X main.version=$VERSION
I've recently decided to trial Google App Engine and started with a basic YAML file:
runtime: go111
handlers:
- url: /.*
script: auto
What can I set in the YAML file in order to instruct GAE to build with the equivalent ldflags to bake in my version string?
I should also mention I use go modules with GO111MODULE=on locally when building.
You can't do it with you app.yaml file.
However, you can use Cloud build to build and deploy your app to App Engine.
In your cloudbuild.yaml you can add a line to the build step
args: ['build', '-a', '-installsuffix', 'cgo', '-ldflags', '''-w''', '-o', 'main', './main.go']

How to define nginx root when using a custom runtime in Google App Engine?

I'm using Google App Engine Flex and need to use a custom runtime so I can install some thirdparty libs. I need to define the document_root to be 'public', only the runtime_configs seems to get ignored when using a custom runtime, so this isn't working:
runtime_config:
document_root: public
I've also tried adding in a nginx-app.conf file with the root declared (I'm also unsure how to get the app path, so i've just hardcoded it):
root "/app/public";
But I get the error:
nginx: [emerg] "root" directive is duplicate in /etc/nginx/conf.d/nginx-app.conf:1
I haven't been able to find the answer to this in the docs, so any help is appreciated!
Following this Hello World example, you can see that root folder is declared in the nginx configuration file in your case nginx-app.conf
First of all you have to properly configure your Docker file, which will create public folder and copy all the files from local machine to it:
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /usr/share/nginx/public/
# Copy static files from local public folder
ADD public/ /usr/share/nginx/public/
RUN chmod -R a+r /usr/share/nginx/public
Than you have to define a path to that public folder in nginx-app.conf file:
http {
server {
root /usr/share/nginx/public;
}
}

Cloud Container Builder, ZIP does not support timestamps before 1980

I'm trying the following tutorial.
Automatic serverless deployments with Cloud Source Repositories and Container Builder
But I got the error below.
$ gcloud container builds submit --config deploy.yaml .
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.beta.functions.deploy) Error creating a ZIP archive with the source code for directory .: ZIP does not support timestamps before 1980
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/gcloud" failed: exit status 1
I'm now trying to solve it. Do you have any idea? My gcloud is the latest version.
$ gcloud -v
Google Cloud SDK 193.0.0
app-engine-go
app-engine-python 1.9.67
beta 2017.09.15
bq 2.0.30
core 2018.03.09
gsutil 4.28
Sample google cloud function code on the tutorial.
#index.js
exports.f = function(req, res) {
res.send("hello, gcf!");
};
#deploy.yaml
steps:
- name: gcr.io/cloud-builders/gcloud
args:
- beta
- functions
- deploy
- --trigger-http
- --source=.
- --entry-point=f
- hello-gcf # Function name
#deploying without Cloud Container Builder is fine.
gcloud beta functions deploy --trigger-http --source=. --entry-point=f hello-gcf
Container Builder tars your source folder. Maybe something in your . directory has corrupted dates? That's why moving it to the source folder fixes it.
While I don't know the reason, I found a workaround.
(1) make src directory and move index.js into it.
├── deploy.yaml
└── src
└── index.js
(2) deploy via Cloud Container Builder.
$ gcloud container builds submit --config deploy.yaml ./src
I ran into the same issue now. I could not solve it but at least I found out where it comes from.
When you locally submit your build there is a tar created and uploaded to a bucket. In this tar the folders are created at 01.01.1970:
16777221 8683238 drwxr-xr-x 8 user staff 0 256 "Jan 1 01:00:00 1970" "Jan 1 01:00:00 1970" "May 15 12:42:04 2019" "Jan 1 01:00:00 1970" 4096 0 0 test
This issue only occurs locally. If you have a github build trigger it works
I recently came across the same issue using Cloud Build (the successor to Container Builder).
What helped was adding a step to list all the files/folders in the Cloud Build environment (default directory is /workspace) to identify the problematic file/folder. You can do this by overriding the gcloud container's entrypoint to execute the ls command.
steps
- name: gcr.io/cloud-builders/gcloud
entrypoint: "ls"
args: ["-la", "/workspace"]

cakephp websocket ratchet install error

I am trying to install Cakephp Ratchet Plugin in existing project.
My CakePHP version is 2.4.3.
It says to follow this link which has following steps:
$ cd myproject/app/
$ curl -s https://getcomposer.org/installer | php
$ php composer.phar require --no-update opauth/opauth:dev-wip/1.0 opauth/twitter:dev- wip/1.0
$ php composer.phar config vendor-dir Vendor
$ php composer.phar install
I am not very familiar with composer and when i do the last step,it shows following error....
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package opauth/opauth could not be found in any version, there may be a typo in the package name.
Problem 2
- The requested package opauth/twitter could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
EDIT:
Composer.json is like this
{
"require": {
"opauth/opauth": "dev-wip/1.0",
"opauth/twitter": "dev-wip/1.0"
},
"config": {
"vendor-dir": "Vendor"
}
}
As already mentioned in my comment, the Ratchet Plugin has nothing to do with Opauth, the linked article over at ceeram.github.io should only serve as an example on how to configure Composer and the CakePHP bootstrap.
However, for Composer autoloading in CakePHP I'd recommend to refer to the CakePHP cookbook, even if you're not including CakePHP itself via Composer:
http://book.cakephp.org/2.0/en/installation/advanced-installation.html
Long story short, what the "Getting Started / 2. Composer" section of the plugin docs want you to do, is to require the ratchet plugin, to make sure the vendor dir points to /app/Vendor/, and to include the Composer autoloader in your bootstrap.php.
composer.json (assuming it's placed in /app)
{
"require": {
"wyrihaximus/ratchet": "dev-master"
},
"config": {
"vendor-dir": "Vendor"
}
}
bootstrap.php (as per Cookbook)
// Load Composer autoload.
require APP . '/Vendor/autoload.php';
// Remove and re-prepend CakePHP's autoloader as Composer thinks it is the
// most important.
// See: http://goo.gl/kKVJO7
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);
Run composer install or composer update and you should be good.

How can I add the Google App Engine dependencies to my gradle build without making a flat file repository?

It is the first time i try to use gradle
I use the following build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-gae-plugin:0.7.6'
}
}
apply plugin: 'gae'
dependencies {
gaeSdk 'com.google.appengine:appengine-java-sdk:1.7.3'
}
gae {
optimizeWar = true
appcfg {
email = 'myemail'
passIn = true
app {
id = 'guestbook'
}
}
}
and I can do a gradle gaeVersion just fine
:gaeVersion
Release: 1.7.3
Timestamp: Wed Oct 24 03:01:39 CEST 2012
API versions: [1.0]
java.vm.vendor: Oracle Corporation
java.vm.version: 23.0-b21
java.version: 1.7.0_04
os.name: Windows 7
os.version: 6.1
but if I do a gradle gaeRun
it fails with a compile error for HttpServlet which I totally understand because I did not add the servlet dependencies.
How do I add the GAE dependencies to my gradle config without making a flat file repository?
You could retrieve the dependency from Maven Central as well. The configuration providedCompile is provided by the War plugin which the GAE plugin applies automatically. In case you notice that you do need to provide the Servlet API library in your WAR file (e.g. if the GAE runtime environment requires you to add it) you need to use the configuration compile instead.
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:servlet-api:2.5'
}

Resources