Problem with layer when using serverless-offline with Bref - php

I'm trying to run a Symfony application with Bref and serverless-offline. I know that Bref doesn't officially support serverless-offline, but I want to give it a shot; this thread - https://github.com/brefphp/bref/issues/875 - implies that it should be possible but I'm not getting the error described there yet.
When I run sls invoke local -f MyLambda I get this error:
{"errorType":"exitError","errorMessage":"RequestId: 09256631-dcc7-1775-350e-b0c10a2c9c00 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}
So I assume that serverless-offline fails to get the layer correctly. The directory .serverless/layers contains a sub-structure php-81-fpm/18 for the PHP layer but it is empty.
What's important is that I'm running this setup in a development Docker container. I mounted the docker socket so the Docker daemon on the host is used.
The serverless.yml looks like this (simplified):
plugins:
- ./vendor/bref/bref
- serverless-offline
functions:
MyLambda:
handler: public/index.php
layers:
- ${bref:layer.php-81-fpm} # also tried with 'arn:aws:lambda:eu-central-1:209497400698:layer:php-81-fpm:18'
custom:
serverless-offline:
host: 0.0.0.0
useDocker: true
dockerHost: host.docker.internal
I'm happy to provide further information, please let me know. Don't hesitate to suggest "low-level" things as I'm quite new to this ecosystem. Thanks for your help!

Related

Gitlab CI configuration with Laravel Docker Redis wrong host or port

I'm working on a Gitlab CI configuration in the .gitlab-ci.yml file for a Laravel project which uses redis as Cache Driver. Within this configuration file I use an image which has all the linux packages, php extension which are used on our production environment. This includes the redis extension installed by pecl so phpredis can be used within Laravel.
After spending a fair amount of time into learning the process of continuous integration and the configuration of the gitlab ci file I encountered the following error on deploy of the image:
In PhpRedisConnector.php line 126:
Redis::connect() expects parameter 2 to be int, string given
parameter should be only the port as an int but somehow turned into tcp://111.111.11.11:6379
As documented https://docs.gitlab.com/ee/ci/services/redis.html the host in your .env should be redis so I had. Dumping the config during the deploy resulted in port being some tcp://111.111.11.11:6379 connection string and host being empty. There is no way this is changed within our application or any extension we use.
I use the https://hub.docker.com/_/redis/ as a service in the .gitlab-ci.yml.
...
services:
- name: redis:4
...
Solution found here:
https://laracasts.com/discuss/channels/testing/gitlab-ci-weird-redis-host
This variable isn't documented anywhere but somehow it solves the problem.
Add the following to your .gitlab-ci.yml file:
variables:
REDIS_PORT: 6379
If anyone finds documentation about this variable and maybe more options, let me know!
This is expected behaviour from Docker.
In Gitlab CI, all services you define will be linked with your container which is running your job using Docker linking system.
As describe here, when we link containers, Docker automatically creates ENVs in format:
<_alias>_NAME
<_alias>_PORT
and some other ENVS
And those ENVs from Docker will override yours.
alias here will be the hostname of your container you defined in services. For example you define these services in your .gitlab-ci.yml:
services:
- redis:5-alpine
- name: mongo
alias: db
So Docker will create the following ENVs respectively:
REDIS_PORT="some thing looks like: tcp://172.17.0.3:6379"
REDIS_NAME="looks like: /runner-72989761-project-19846207-concurrent-0-62507216079cf651-build-3/redis"
DB_PORT=same like redis
DB_NAME=same like redis
And note that, as described here, by default the following ENVs are also auto created based on service image's name:
MONGO_PORT=...
MONGO_NAME=...
So in your code if you have any variable that has same name with the ones Docker creates, you may need to change your variable's name otherwise it'll be override by Docker. Or you can use the solution from #MmynameStackflow above, pass variables in your Gitlab CI config file to override what Docker does.

Symfony 4 on Google App Eng (flex) - 500 error

Symfony 4 app running on Google App Eng (flex).
I deployed the app, but I am getting a 500 error, and app engine is providing no additional detail.
The deploy process I did was as follows:
(Following doc https://cloud.google.com/community/tutorials/run-symfony-on-appengine-flexible)
Include an app.yaml file as follows:
runtime: php
env: flex
runtime_config:
document_root: public
front_controller_file: index.php
env_variables:
APP_ENV: "prod"
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Update the composer line:
"post-install-cmd": [
"chmod -R ug+w $APP_DIR/var"
],
Cleared cache and warmed cache for production:
php bin/console cache:clear --env=prod --no-debug
php bin/console cache:warmup --env=prod --no-debug
Even though I haven't done the doctrine set up part, I should be able to go to xxxx.appspot.com and get the home page. Instead I get ...
xxxx.appspot.com is currently unable to handle this request. HTTP ERROR 500
This is puzzling because the app worked totally fine locally before warming the cache.
Am I deploying correctly or forgetting something? (I cant get any detail on error from App Engine).
Edit
I have checked the var/log local folder and found dev.log and prod.deprecations.log. In the latter I have this error many times ...
[2018-10-15 11:28:59] php.INFO: User Deprecated: Referencing controllers with a single colon is deprecated since Symfony 4.1, use "fos_user.security.controller::loginAction" instead. {"exception":"[object] (ErrorException(code: 0): User Deprecated: Referencing controllers with a single colon is deprecated since Symfony 4.1, use \"fos_user.security.controller::loginAction\" instead. at C:\\dev\\projects\\jw-app\\vendor\\symfony\\framework-bundle\\Routing\\DelegatingLoader.php:98)"}
Based on the new edit information you’ve just provided it seems that the issue you are encountering is more on the Symfony version you are using than GAE.
Symfony 4.1 has deprecated the bundle notation. This means that it is no longer recommended to organize your business logic using bundles. You can see some examples of this on the official Symfony web page here.
Your error message tells you to use the following:
\"fos_user.security.controller::loginAction\
For the file at path:
C:\dev\projects\jw-app\vendor\symfony\framework-bundle\Routing\DelegatingLoader.php:98)
on line 98
It seems a few people have the following referencing issues with Symfony 4.1 as well. You can view the details of their similar issue and review recommended fixes at FriendsOfSymfony Github page.
Also, I would like to mention that since you are using GAE:Flex you can view your build history and error logs for your project at the following:
Google Cloud Build ( Google Cloud Console > Open the menu > tools > Cloud Build )
This will provide you the necessary information of the build you are trying to deploy on GAE.

Docker compose external links alias with http protocol

I have a problem using docker compose link alias. I host a PHP application on docker and use curl in the application
this is my docker-compose.yml
php:
external_links:
- apache:my-apache
That links is working. I have my-apache item on /etc/hosts
172.17.0.5 my-apache
But the problem comes when i use php curl to access my-apache service, since php curl requires the strict format : http://domain.com, and i am unable to use http://domain.com as an alias for docker link.
This will produce error
apache:http://domain.com
The error :
ERROR: for php too many values to unpack
Any suggestions?
Big Thanks

You have requested a non-existent service "phpexcel"

I know there are some questions almost identical but none of them seems to be my case.
I have a symfony 2.8.3 project that reads and imports data from an excel file into mysql database. Its all working nice on localhost but in the last 48 hours I've been trying to get it working on my server. Its a shared hosting, with no SSH access to the linux.
When I am trying to load it from the server I get this error: "You have requested a non-existent service "phpexcel"."
Looks like you want to use service from ExcelBundle. But that bundle is not loaded. Check if you have it added for production env.
$bundles = array(
// ...
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
);
Don't forget to clear cache on production environment after any config (AppKernel.php also) change.
To clear cache run php app/console cache:clear. You can also add env parameter: --env=dev or --env=prod - depending on your env. If it don't help then just remove all content of app/cache/ directory (or var/cache/ in case of Symfony3 app)
Pawel answered correctly, but something is missing: after you add this line: new Liuggio\ExcelBundle\LiuggioExcelBundle(), to the AppKernel.php file, inside the $bundles array, don't forget to clear the cache: delete the file from app/cache/dev in case you're in developer mode or app/cache/prod in case on production mode.

Behat with Mink

Does anyone know how to successfully configure Mink to work with Behat? In case if anyone doesn't know, Behat is a BDD(Behaviour-Driven Development) framework for PHP and Mink provides a browser emulators abstraction layer to test with.
You can find out more about Behat at http://behat.org/ and Mink at https://github.com/Behat/Mink or http://www.knplabs.com/fr/blog/one-mink-to-rule-them-all
Basically i followed the instructions at http://www.knplabs.com/fr/blog/one-mink-to-rule-them-all to configure my Mink to work with my Behat. My behat.yml, the one located inside the Behat folder, not the Mink folder, is as follows:
default:
paths:
features: %%BEHAT_CONFIG_PATH%%/features
formatter:
name: progress
pretty:
formatter:
name: pretty
parameters:
multiline_arguments: false
default:
environment:
parameters:
start_url: http://localhost/
imports:
- mink/behat.yml
I also have the following code in my features/support/boostrap.php
require_once 'mink/autoload.php';
However, having the following code in my features/support/env.php
$world->client = new \Goutte\Client;
would give me a PHP Fatal error: Class 'Goutte\Client' not found in terminal(OSX) when i use the behat command. This happens even if i have the goutte.phar inside my behat/Mink/Vendor/Goutte folder.
Hope anyone can enlighten me on where i went wrong and if there was any part in the question where I wasn't being clear about it, do let me know. Thanks a lot.
Here it is: https://github.com/knplabs/mink-demo ;-)
Basically, with Mink, you don't need to create or require Goutte client it's done by Mink automatically. Your $world was also enhanced and now you're able to get mink session inside step definitions:
$downloadsLink = $world->getSession()->getPage()->findLink('downloads');
Also, you've forgot to include PHPUnit!
See mink-demo for getting great example ;-)

Categories