Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Gitlab CI #39

Open
ak4t0sh opened this issue Sep 18, 2020 · 15 comments · May be fixed by #223
Open

Add support to Gitlab CI #39

ak4t0sh opened this issue Sep 18, 2020 · 15 comments · May be fixed by #223
Labels
task Some task to complete

Comments

@ak4t0sh
Copy link

ak4t0sh commented Sep 18, 2020

As suggested by @danielneis in open-lms-open-source/moodle-plugin-ci#13 it could be really usefull to add Gitlab CI support :)

@kabalin kabalin added the task Some task to complete label Sep 18, 2020
@adpe
Copy link
Contributor

adpe commented Oct 21, 2020

We're using it right now in our GitLab CI/CD and it works!

@kabalin
Copy link
Member

kabalin commented Oct 21, 2020

@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 😄

@adpe
Copy link
Contributor

adpe commented Oct 21, 2020

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

@aspark21
Copy link
Contributor

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

@adpe
Copy link
Contributor

adpe commented Jun 10, 2021

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

@adpe
Copy link
Contributor

adpe commented Jun 10, 2021

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

@scara
Copy link

scara commented Jun 10, 2021

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

@adpe
Copy link
Contributor

adpe commented Jun 11, 2021

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

@scara
Copy link

scara commented Jun 11, 2021

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

@adpe
Copy link
Contributor

adpe commented Jun 11, 2021

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

@kabalin
Copy link
Member

kabalin commented Jun 11, 2021

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.

@adpe
Copy link
Contributor

adpe commented Jun 11, 2021

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

@adpe
Copy link
Contributor

adpe commented Jun 15, 2021

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:

image

Greets
Adrian

@adpe
Copy link
Contributor

adpe commented Jun 15, 2021

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

@kabalin
Copy link
Member

kabalin commented Jun 15, 2021

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.

kiklop74 added a commit to kiklop74/moodle-plugin-ci that referenced this issue Mar 30, 2023
@kiklop74 kiklop74 linked a pull request Mar 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Some task to complete
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants