Open ak4t0sh opened 4 years ago
We're using it right now in our GitLab CI/CD and it works!
@adpe would be great if you could show an example of .gitlab-ci.yml
content. If you have more time, PR with instruction for our docs would be really appreciated 😄
Hello @kabalin
Here is an example https://gist.github.com/adpe/834c741156edd6a6403eebe148a0ecec, but pay attention. It's not up-to-date. And as I noticed today at work, the Behat tests can't be run. The rest seems still to work.
The problem is mainly, that from within the moodlehq/moodle-php-apache
the docker image selenium can't be started.
I'm now figuring out Behat tests can be run in another service container, and moodle-plugin-ci behat
would run instead in this container as in the container running the php image.
Maybe you have some idea, how to do that?
Greets, Adrian
I've seen some which work for a particular plugin but apply it to another one it rarely does work.
I also think it would be good to have one well structured to allow for runs to happen in parallel - phpunit, behat & the rest - at least.
But also Travis was useful for matrixes of Moodle version, db engine, php versions - that I have never seen in a gitlab-ci.yml for Moodle yet
I think Gitlab would be worth the effort because there is some free runners one can use but more importantly any dev can setup a runner on a spare machine under the desk, cheap cloud server or roaring number crunching beast depending on their budget - https://docs.gitlab.com/runner/install/index.html
Hi @aspark21
With different job definitions you could achieve the same as the matrix approach.
Does somebody have Behat working in a GitLab CI/CD environment?
Greets Adrian
Hi @marinaglancy
I've seen that you have Behat setup in this repository https://github.com/moodleworkplace/moodle-mod_coursecertificate/blob/master/.gitlab-ci.yml
But I've problems to set up Behat for my plugin.
Output:
$ moodle-plugin-ci behat --suite default --profile chrome
RUN Behat features for local_<plugin-name>
In BehatCommand.php line 130:
Docker is not available, can't start Selenium server
behat [-m|--moodle MOODLE] [-p|--profile PROFILE] [--suite SUITE] [--start-servers] [--auto-rerun AUTO-RERUN] [--dump] [--] [<plugin>]
Any hints? I'm using the moodlehq/moodle-php-apache:7.4
image and Behat is set up successful:
[debug] Enabling Behat
RUN php -d log_errors=1 -d error_log=NULL /var/www/html/moodle/admin/tool/behat/cli/util_single_run.php --enable --add-core-features-to-theme
OUT Creating Behat configuration ... done in 4.13 seconds.
OUT Building theme CSS for boost [ltr] ... done in 2.09 seconds.
OUT Building theme CSS for classic [ltr] ... done in 1.67 seconds.
OUT Testing environment themes built
OUT Acceptance tests environment enabled on http://localhost:8000, to run the tests use:
OUT vendor/bin/behat --config /builds/ffhs-it-services/moodle/moodledata/behat_moodledata/behatrun/behat/behat.yml
OUT [info] Install completed
RES Command ran successfully
$ moodle-plugin-ci phplint
Really appreciate any hints and help!
Greets Adrian
Hi @adpe, what is your GL CI? I never used the GL CI but if I look at the very start of Marina's CI code:
image: moodlehq/moodle-workplace-plugin-ci:7.3
services:
- postgres:9.6
#- mysql:5.7.26
- name: selenium/standalone-chrome:3
alias: selenium-standalone-chrome
variables:
Among the services
there is the selenium image too.
Wondering if the moodle-plugin-ci
code in the image above has been customized to avoid calling the Docker Engine stuff if the "service" has been already provided: you could try using that moodlehq/moodle-workplace-plugin-ci
image too.
HTH, Matteo
Hi @scara
I've included this service as well the MOODLE_BEHAT_WDHOST
variable. I think there must be some customization made behind the scenes.
Greets Adrian
Hi @adpe, thanks for the follow up: it would be helpful for the others falling into the same issue 👍 😃.
I think there must be some customization made behind the scenes.
Not quite, since it is supported in the standard moodle-plugin-ci too.
It looks like the service.alias
does the magic (DNS) and the ENV VAR set it properly into the plugin.
I still believe that one customization in the workplace flavour is to (optionally?) avoid creating the selenium instance: it would be nice if that feature could be ported into the standard version, here, to help CI scenarios like the one related to GL.
HTH, Matteo
Yep @scara - you're right. It tries actually to run the tests and not starting any more new Selenium server instance. Now I get following output:
Behat requirement not satisfied: http://localhost:8000/behatrun1 is not available, ensure you specified correct url and that the server is set up and started.
.
.
.
Behat requirement not satisfied: http://localhost:8000/behatrun2 is not available, ensure you specified correct url and that the server is set up and started.
.
.
.
Behat requirement not satisfied: http://localhost:8000/behatrun3 is not available, ensure you specified correct url and that the server is set up and started.
.
.
.
Exit codes for each behat run:
behatrun1: 251
behatrun2: 251
behatrun3: 251
It's still not working and I tried different approaches. We're using our own infrastructure running GitLab and the GitLab Runners. Would good if @marinaglancy could assist me, so that we can provide a clean and good solution for the Moodle developers out there.
Greets Adrian
I think there must be some customization made behind the scenes.
Here is behind the scenes part of moodlehq/moodle-workplace-plugin-ci
that should make things clear for you:
export TRAVIS_BUILD_DIR="$CI_PROJECT_DIR"
if [[ "$DB" == "mysqli" ]]; then
export DB_HOST="mysql"
elif [[ "$DB" == "pgsql" ]]; then
export DB_HOST="postgres"
else
export DB_HOST="$DB"
fi
export IPADDRESS=`grep "${HOSTNAME}$" /etc/hosts |awk '{print $1}'`
export MOODLE_BEHAT_WWWROOT="http://${IPADDRESS}:8000"
export MOODLE_START_BEHAT_SERVERS="NO"
Docker image is extending moodlehq/moodle-php-apache:${php}
and adds workplace specific CI stuff, it also downloads moodle-plugin-ci
as part of image build process using standard approach (composer create-project ....
) to reduce test running time, I am sure with above configuration you can use moodlehq/moodle-php-apache
image directly in your .gitlab-ci.yml
.
Thanks @kabalin
Right now I'm using the workplace image to reduce the amount of errors and to get it finally run. But it's not working. This is my actual .gitlab-ci.yml
file https://gist.github.com/adpe/06ffdc70751bc5b626d69d247193e59b.
As I understand, I don't must care about the variables you are exporting right now in the workplage image. I must only add these to my file, if I'll use the default moodlehq/moodle-php-apache:${php}
image.
Do you see any errors on my actual file?
Greets Adrian
I've seen some which work for a particular plugin but apply it to another one it rarely does work.
I also think it would be good to have one well structured to allow for runs to happen in parallel - phpunit, behat & the rest - at least.
But also Travis was useful for matrixes of Moodle version, db engine, php versions - that I have never seen in a gitlab-ci.yml for Moodle yet
I think Gitlab would be worth the effort because there is some free runners one can use but more importantly any dev can setup a runner on a spare machine under the desk, cheap cloud server or roaring number crunching beast depending on their budget - https://docs.gitlab.com/runner/install/index.html
By the way. I've seen today that GitLab.com offers a CI/CD connection for external repositories:
Greets Adrian
I've now a working solution using the moodle-php-apache
image and updated the given gist I mentioned earlier (https://gist.github.com/adpe/834c741156edd6a6403eebe148a0ecec). After so many investigation time I don't have yet motivation and time to document this @kabalin.
Hope that helps others as well!
Greets Adrian
Many thanks @adpe for investigation work and working example! Now we have a good starting point to make it recorded in docs one day and create .gitlab-ci.dist.yml
for GitLab users.
As suggested by @danielneis in https://github.com/open-lms-open-source/moodle-plugin-ci/issues/13 it could be really usefull to add Gitlab CI support :)