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

gitlab-ci beaker #104

Closed
4 of 8 tasks
cdenneen opened this issue Jun 1, 2018 · 6 comments
Closed
4 of 8 tasks

gitlab-ci beaker #104

cdenneen opened this issue Jun 1, 2018 · 6 comments

Comments

@cdenneen
Copy link
Contributor

cdenneen commented Jun 1, 2018

@dhollinger @npwalker

Few things:

  • there is no rake task of acceptance anymore... needs to be beaker
  • the bundle install for acceptance job needs to be bundle install --with system_tests otherwise the bundle install does nothing but uses whats in cache and beaker never gets installed.
  • image should allow for registry in .sync or config_defaults and if set prepend with the registry_host/
  • beaker variables (and probably any other variables needs to convert boolean to string)
---
.gitlab-ci.yml:
  custom:
    beaker:
      variables:
        BEAKER_debug: 'true'

converts to BEAKER_debug: true and then fails ci lint as it needs to be BEAKER_debug: 'true'

  • beaker acceptance job missing default image and/or gitlab-ci.yml doesn't have a default set so falls back to runners configured default image which in the case of gitlab.com is ruby:2.5 but in my local hosted gitlab there is no default so it fails:
Running with gitlab-runner 10.8.0 (079aad9e)
  on gitlab-ci-runner-1 e1b7b7f8
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Preparation failed: no image specified and no default set in config
Will be retried in 3s ...
ERROR: Job failed (system failure): no image specified and no default set in config
  • outside the scope of this in general but gem install nokogiri even cached will recompile during acceptance job I believe because that needs to be installed with --prune flag or something if I recall reading that somewhere.
  • currently by having 2 spec and lint jobs running in same stage there is absolutely NO benefit to caching in gitlab-ci. In order for caching to make sense is the use of multiple stages. (technically right now the last syntax stage job is the one winning in the "cache.zip" upload... since they are overwriting each other.) I thought we originally discussed needing a "quick" job as the first stage like linting which could create the cache and speed up the spec/acceptance jobs downstream? Also if your going to fail linting, validate, maybe even rubocop it's probably not worth installing all fixtures and full spec testing suite since some of those can be massive and fail early in previous stage? Maybe even consider a "prep" job that just does the bundle install --with development and creates the cache (seems like waste for container so still recommend moving the linting to first stage)? It's possibly the lint was supposed to be first then at that point the ERB is just a typo and the spec ones should be unit stages
  • setting override removes syntax and unit from the stages but not the jobs. I believe if there are jobs calling a stage that is no longer defined this will break ci linting. So maybe if override the jobs get removed as well as the stages?
@npwalker
Copy link
Contributor

npwalker commented Jun 1, 2018

The current code for determining what stage something should be in is based on the name of the check and I changed that to be more descriptive and it made it so there is no differentiation of stages any more.

https://github.com/puppetlabs/pdk-templates/blob/master/moduleroot/.gitlab-ci.yml.erb#L46-L47

The stage should be provided via config IMO but given the way it's written there is no way to do that. I suspect the easiest way to allow this is to have the user provide a hash with the key being the check to perform and stage, variables, image, etc... would be in a hash as the value. Something like:

parallel_spec: 
  stage: syntax
  image: ruby:2.4.4
  variables:
    PUPPET_GEM_VERSION: '~> 5.5'

@cdenneen
Copy link
Contributor Author

cdenneen commented Jun 1, 2018

Ah so you broke it. LOL
Well maybe the check == 'spec' should be =~ instead.
Also not sure I agree with parallel being the default, maybe a Boolean to use? For some reason when using parallel and coverage for Rspec configure after suite check it tries to do coverage for each thread instead of as whole anymore. Once that’s fixed I think parallel is okay. (@DavidS @rodjek)

@dhollinger
Copy link
Contributor

@cdenneen

  • I'm fixing issues 1, 2, and 4 (based on checkboxes starting from top to bottom).
  • Issue 3 should not be fixed as the registry URL is considered a part of the Image name by Docker and other container technologies and the registry URL can be incredibly simple or incredibly complex depending on registry tool and specific user layout.
  • The beaker job should not use any image/service other than dind if using docker. As beaker itself controls the creation/destruction of the SUT, the only image that can be used with gitlab-ci and a docker running is dind

As to @npwalker's comment about the different ways to configure gitlab-ci.yml, there are hundreds of ways a user can configure .gitlab-ci.yml and this template is designed to create a default that is reminiscent of the defaults in .travis.yml. The defaults in this repo need to conform to what Puppetlabs has deemed best practice. The override and managed: false options are provided to .snyc.yml specifically for this reason. The defaults in this template for .gitlab-ci.yml don't work for me, either, so I use override: true and provide my own set of stages, jobs, etc.

@dhollinger
Copy link
Contributor

Here's an example of a working gitlab ci config in .sync.yml:

.gitlab-ci.yml:
  override: true
  custom:
    custom_stages:
      - syntax
      - unit
      - acceptance
      - deploy
    bundler_args: '--without system_tests'
    ruby_versions:
      2.4.4:
        checks:
          - syntax
          - lint
          - rubocop
          - metadata_lint
          - spec
        puppet_version: '~> 5.0'
        tags:
          - 'puppet-unit'
    custom_jobs:
      acceptance:
        stage: acceptance
        variables:
          BEAKER_debug: 'true'
          BEAKER_set: 'ec2'
          BEAKER_PUPPET_COLLECTION: 'puppet5'
          PLATFORM_type: 'appliance'
        before_script:
          - rvm use 2.4.4
          - ruby -v
          - bundle update
        script:
          - bundle exec rake acceptance
        when: on_success
        tags:
          - puppet-acceptance
        except:
          - tags
          - master
      pages:
        stage: deploy
        image: ruby:2.4
        before_script:
          - bundle install
        script:
          - echo "Deploying Documentation"
          - bundle exec rake strings:generate
        artifacts:
          paths:
            - public
        only:
          - master
        tags:
          - puppet-acceptance
      release:
        stage: deploy
        before_script:
          - bundle update
        script:
          - 'GIT_SERVER=$(echo $CI_REPOSITORY_URL | cut -d"@" -f2 | cut -d"/" -f1)'
          - 'git remote set-url origin git@$GIT_SERVER:$CI_PROJECT_PATH.git'
          - 'bundle exec rake module_release'
        only:
          - master
        when: on_success
        tags:
          - puppet-acceptance
      build:
        stage: deploy
        before_script:
          - bundle update
        script:
          - "\"export VERSION=$(grep \\\"version\\\": metadata.json | awk '{ print $2 }' | sed 's/,//' | sed 's/\\\"//g')\""
          - bundle exec rake build
        artifacts:
          paths:
            - pkg/internal-$CI_PROJECT_NAME-*.tar.gz
        only:
          - master
        when: on_success
        tags:
          - puppet-acceptance

It generates:

---
stages:
  - syntax
  - unit
  - acceptance
  - deploy

before_script:
  - bundle -v
  - rm Gemfile.lock || true
  - gem update --system
  - gem update bundler
  - gem --version
  - bundle -v
  - bundle install --without system_tests

syntax-2.4.4:
  stage: syntax
  image: ruby:2.4.4
  script:
    - bundle exec rake syntax
  variables:
    PUPPET_GEM_VERSION: '~> 5.0'
  tags:
    - puppet-unit

lint-2.4.4:
  stage: syntax
  image: ruby:2.4.4
  script:
    - bundle exec rake lint
  variables:
    PUPPET_GEM_VERSION: '~> 5.0'
  tags:
    - puppet-unit

rubocop-2.4.4:
  stage: syntax
  image: ruby:2.4.4
  script:
    - bundle exec rake rubocop
  variables:
    PUPPET_GEM_VERSION: '~> 5.0'
  tags:
    - puppet-unit

metadata_lint-2.4.4:
  stage: syntax
  image: ruby:2.4.4
  script:
    - bundle exec rake metadata_lint
  variables:
    PUPPET_GEM_VERSION: '~> 5.0'
  tags:
    - puppet-unit

spec-2.4.4:
  stage: unit
  image: ruby:2.4.4
  script:
    - bundle exec rake spec
  variables:
    PUPPET_GEM_VERSION: '~> 5.0'
  tags:
    - puppet-unit

acceptance:
  stage: 'acceptance'
  variables:
    BEAKER_debug: 'true'
    BEAKER_set: 'ec2'
    BEAKER_PUPPET_COLLECTION: 'puppet5'
    PLATFORM_type: 'appliance'
  before_script:
    - rvm use 2.4.4
    - ruby -v
    - bundle update
  script:
    - bundle exec rake acceptance
  when: 'on_success'
  tags:
    - puppet-acceptance
  except:
    - tags
    - master

pages:
  stage: 'deploy'
  image: 'ruby:2.4'
  before_script:
    - bundle install
  script:
    - echo "Deploying Documentation"
    - bundle exec rake strings:generate
  artifacts:
    paths:
      - public
  only:
    - master
  tags:
    - puppet-acceptance

release:
  stage: 'deploy'
  before_script:
    - bundle update
  script:
    - GIT_SERVER=$(echo $CI_REPOSITORY_URL | cut -d"@" -f2 | cut -d"/" -f1)
    - git remote set-url origin git@$GIT_SERVER:$CI_PROJECT_PATH.git
    - bundle exec rake module_release
  only:
    - master
  when: 'on_success'
  tags:
    - puppet-acceptance

build:
  stage: 'deploy'
  before_script:
    - bundle update
  script:
    - "export VERSION=$(grep \"version\": metadata.json | awk '{ print $2 }' | sed 's/,//' | sed 's/\"//g')"
    - bundle exec rake build
  artifacts:
    paths:
      - pkg/ntts-$CI_PROJECT_NAME-*.tar.gz
  only:
    - master
  when: 'on_success'
  tags:
    - puppet-acceptance

NOTE - I am not using the beaker options, but my own acceptance job and providing my own rake/acceptance.rake file in the repo + the .sync.yml file

dhollinger added a commit to dhollinger/pdk-templates that referenced this issue Jun 2, 2018
@DavidS DavidS added the gitlab label Jun 4, 2018
@dhollinger
Copy link
Contributor

dhollinger commented Jun 7, 2018

@cdenneen nokogiri installations options should be addressed as a core pdk-templates issue rather than just for gitlab-ci.yml.

The override option should be removing ALL default jobs and stages. I'll look at that when I have time.

For the caching. It's, in my opinion, better to run more jobs in parallel than one at a time. Maybe the option here is to have the rubocop or syntax job run in the first stage (called validate or syntax respectively) and then run everything else in the next stage. The unit tests should also benefit from the caching. I don't think beaker tests can benefit from the caching since Beaker, more or less, acts as another layer of abstraction between CI and the SUT.

bmjen pushed a commit that referenced this issue Aug 14, 2018
@DavidS
Copy link
Contributor

DavidS commented Jan 18, 2021

Closing out old beaker stuff.

@DavidS DavidS closed this as completed Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants