I'm running Symfony Insight with a gitlab CI in order to improve my code quality.
I recently added google recaptcha, which needs a public (used in twig) and a private token (used in controller).
To do a clean job, I added them both as environment variables, added the pub one as twig global variable, and i get the private one with getenv.
I a am now getting the "A Symfony application should be bootable" error on symfony insight, with the following stacktrace :
Symfony\Component\DependencyInjection\Exception\EnvNotFoundException: Environment variable not found: "RECAPTCHA_PUBLIC_KEY". in /home/foobar/code/vendor/symfony/dependency-injection/EnvVarProcessor.php:97
Note that everything is working properly on both local and php unit tests (also ran by CI)
I'm guessing that the insight isn't finding the env var when trying to initiate the global twig variable.
Here is my .env.dist file : (the keys are google testing key, not my real ones, don't worry)
###> google-recaptcha ###
RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
###< google-recaptcha ###
Here is my twig variable declaration :
globals:
recaptcha_public_key: '%env(RECAPTCHA_PUBLIC_KEY)%'
And my gitlab-ci insight config:
insight:
stage: insight
image: php:7.1
tags:
- symfony4
script:
- curl -o insight.phar -s https://get.insight.symfony.com/insight.phar
- php insight.phar analyze --no-interaction --no-ansi cc8f0c98-ce1b-4b1e-acc4-9dfafd4bafc4 -v --reference=$CI_COMMIT_SHA --user-uuid=23888e4d-ec4f-479b-90c6-ee454c7bfc88 --api-token=b1dcbef05392e237a5ee5d29ea348b9ab7179245b0f086c3490478b0ae643272 --fail-condition="counts.critical > 0 or counts.major > 0"
only:
- develop
- master
variables:
MYSQL_DATABASE: higalsymf
DATABASE_HOST: mysql
MYSQL_ROOT_PASSWORD: root
The first idea: you can insert tokens in variables section in gitlab-ci.yml.
Second idea is add command cp .env.dist .env in section before_script in gitlab-ci.yml.
Related
I have my own php image, which I would like to use for my project to run tests on.
container: rela589n/doctrine-event-sourcing-php:latest
services:
test_db:
image: postgres:13-alpine
env:
POSTGRES_DB: des
POSTGRES_USER: des_user
POSTGRES_PASSWORD: p#$$w0rd
steps:
- uses: actions/checkout#v2
- whatever_needed_to_run_tests_inside_container
This fails on checkout action with such error:
EACCES: permission denied, open '/__w/doctrine-event-sourcing/doctrine-event-sourcing/6977c4d4-3881-44e9-804e-ae086752556e.tar.gz'
And this is logical as in fresh docker container there's no such folder structure. What i thought to do is run checkout action inside virtual machine provided runs-on: ubuntu-20.04 and configure volume for docker so that it will have access to code. However I have no idea neither is it a good practice to do this way nor how to implement this. I guess even if it is possible to do this way it won't work for other actions.
Had the same issue when trying to use my own Docker image. In my case, installing everything I need on the fly was not an option, so I had to fix this issue.
It appears that GitHub runs the Docker image with user 1001 named runner and group 121 named docker. After adding the group, adding the user and adding the user to sudoers the problem was solved.
Notice that the checkout path starts with /_w which is strange. If I perform actions/checkout#v2 without my container, the path is /home/runner. Not sure how to solve that yet.
Thanks, this really helped me to find the issue when trying to deploy a CDK project from within a Docker container on Github Actions.
I was getting a permission denied error after checking out the code, and trying to deploy it.
Error: EACCES: permission denied, mkdir '/__w/arm-test/arm-test/cdk.out/asset.7d21b14f781f8b0e4ebb3b30c66614a80f71a2c1637298e5557a97662fce0abe'
This issue had the workaround of running the container with the same user and group as the Github Actions runner, so that it matched with the permissions of the source code directory: https://github.com/actions/runner/issues/691
jobs:
configure:
runs-on: ubuntu-latest
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"
clone-and-install:
needs: configure
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
options: --user ${{ needs.configure.outputs.uid_gid }}
steps:
- uses: actions/checkout#v2
If you've worked with Laravel and Lando together, you probably know that Lando gives you its own artisan shortcut. So instead of having to run lando php artisan ..., you can run lando artisan ....
However, when I do that, I get this error:
Could not open input file: /app/./../artisan
This forces me to have to run lando php artisan to run any artisan commands, and that does work fine. So far, this is all that's going wrong with my project in Lando. Everything else is running smoothly.
Here's what my lando config looks like:
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
database: mysql:8.0
services:
appserver:
webroot: public
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
Also, this does look a bit different from Lando's sample config on their website. This is because I was trying to configure xdebug according to their "Using Lando with VSCode" instructions (see Lando rc.2+ version).
Appreciate any help figuring this weird issue out. It's not debilitating, but it does get in the way when I forget the workaround.
Other notes:
"webroot" is set to "public" because that's where the public-facing directory is for a Laravel app. The example Lando config for Laravel has this part wrong and it causes the project root to be visible to the browser.
I got it working. I moved the webroot key back under the top-level config. Not sure what the difference is, but as long as it works... I guess the only thing I really need to specify in the appserver service is the Xdebug settings.
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
webroot: public
database: mysql:8.0
services:
appserver:
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
I have a Symfony 5.1.8 project, in which I want to use a different database connection for testing. To do so, I set up the file .env.test.local with a different value for DATABASE_URL than in my .env.local, just like the documentation in the .env file states:
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env.local contains default values for the environment variables needed by the app
# * .env.local.local uncommitted file with local overrides
# * .env.local.$APP_ENV committed environment-specific defaults
# * .env.local.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env.local files.
Symfony seems to ignore these overrides and always uses the values provided in .env.local.
To find out what exactly happens I changed the last line in bin/console from $application->run($input); to dd($_ENV); in order to just dump whatever environment variables symfony sees during its execution.
Here are the contents of my different .env files:
.env
APP_ENV=dev
ENV_VAR=ENV
.env.local
APP_ENV=dev
ENV_VAR=ENV_LOCAL
.env.test
APP_ENV=test
ENV_VAR=ENV_TEST
.env.test.local
APP_ENV=test
ENV_VAR=ENV_TEST_LOCAL
When I run php bin/console now the output is as follows:
array:10 [
"APP_ENV" => "dev"
"ENV_VAR" => "ENV_LOCAL"
...
]
Which is what I expect. But when I run php bin/console -e test the following is being printed:
array:10 [
"APP_ENV" => "test"
"ENV_VAR" => "ENV_LOCAL"
...
]
APP_ENV is set correctly, according to the -e parameter, but still, for ENV_VAR the value from .env.local is taken.
Do I have a misconception about the .env-files and their behaviour or is this a bug of some sort?
In case it matters, I am currently working on Windows 10 with PHP 7.3.24.
It was a configuration error on my side.
When I first started this project I did not fully grasp the concept of multi level .env files and did a little change to the bin/console executable, to make things "easier" for me:
curl -o console.temp https://raw.githubusercontent.com/symfony/recipes/master/symfony/console/5.1/bin/console
diff console console.temp
31c31
< (new Dotenv())->bootEnv(dirname(__DIR__) . '/.env.local');
---
> (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
This, of course prevented the whole DotEnv thingy from working correctly. I just forgot about this change that I introduced, but thanks to #PierrickM's comment on my question, everything is working fine now!
I am investigating on how I can create an AWS lambda in php using the bref library
Therefore, according to documentation I set up the environment with the following command cocktail:
sudo -H npm install -g serverless
composer require bref/bref
Then using the following command created my first php lambda:
vendor/bin/bref init
And I selected the first option PHP Function provided by default. Creating the following creating an index.php file:
declare(strict_types=1);
require __DIR__.'/vendor/autoload.php';
lambda(function ($event) {
return 'Hello ' . ($event['name'] ?? 'world');
});
Then I changed my serverless.yml into that:
service: app
provider:
name: aws
region: eu-central-1
runtime: provided
stage: ${opt:stage,'local'}
package:
exclude:
- '.gitignore'
plugins:
- ./vendor/bref/bref
functions:
dummy:
handler: index.php
name: Dummy-${self:provider.stage}
description: 'Dummy Lambda'
layers:
- ${bref:layer.php-73}
And I try to launch it via the following command:
sls invoke local --stage=local --docker --function dummy
But I get the following error:
{"errorType":"exitError","errorMessage":"RequestId: 6403ebee-13b6-179f-78cb-41cb2f517460 Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]"}
Therefore, I want to ask why I am unable to run my lambda localy?
Since this question is getting a lot of views, I recommend to have a look at the Bref documentation:
Local development for PHP functions
That involves using the bref local CLI command instead of serverless invoke local:
$ vendor/bin/bref local hello
Hello world
# With JSON event data
$ vendor/bin/bref local hello '{"name": "Jane"}'
Hello Jane
# With JSON in a file
$ vendor/bin/bref local hello --file=event.json
Hello Jane
On my local, clearing cache before invoking lambda worked fine, I'm using linux / ubuntu
docker system prune --all
sudo apt-get autoremove
sudo apt-get clean
sudo apt-get autoclean
sudo rm -rf ~/.cache/
sudo rm -rf /var/cache/
It is a known bug for bref. It can be solved via providing the layer manually on your function in serverless.yml. So the functions section at serverless.yml should change from:
functions:
dummy:
handler: index.php
name: Dummy-${self:provider.stage}
description: 'Dummy Lambda'
layers:
- ${bref:layer.php-73}
Into:
functions:
dummy:
handler: index.php
name: Dummy-${self:provider.stage}
description: 'Dummy Lambda'
layers:
- 'arn:aws:lambda:eu-central-1:209497400698:layer:php-73:15'
The reason why is that ${bref:layer.php-73} cannot be resolved into a php layer. Therefore, you need to provide manually the arn for the lambda layer.
Keep in mind that the arn comes into various "versions" that is being inidcated from the last number in the arn seperated with :. So in the arn
arn:aws:lambda:eu-central-1:209497400698:layer:php-73:15
Indicated that the layer is in version "15" whitch is thje latest at the moment of the answer. The next one logically should be the:
arn:aws:lambda:eu-central-1:209497400698:layer:php-73:16
I am trying to integrate sonarcloud with Bitbucket pipeline. I have a simple test project with single file named index.php consisting few lines.
I am exactly not sure what method should I follow.
I have created sonar-project.properties files that consists following lines.
sonar.sourceEncoding=UTF-8
sonar.host.url=https://sonarcloud.io/dashboard?id=first_ftp
sonar.projectKey=first_ftp
Here is my yml file
image: aariacarterweir/lamp-gitftp:latest
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node
- sonar
script:
- npm install --quiet
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
When I check into sonarcloud website, It tells
The main branch has no lines of code
Can anybody help me how to configure properly sonarcloud with bitbucket for php project.
I've had the same issue - in my case it was because of the name of the project - it was called ---------Test, and apparently, by default, Sonar will treat that as a test assembly and will exclude it from analysis.
Before running code analysis in bitbucket pipelines, you would have to first manually run analysis(only once). By following below steps.