Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Conversation

@kmturley
Copy link

@kmturley kmturley commented Aug 3, 2017

These changes allowed me to get your lighthouse-ci image working locally and on gitlab-ci using these files in my own project:

Docker Compose

docker-compose.yml

version: "2"
services:

  backend:
    build: ./backend
    command: python server.py
    environment:
      NODE_ENV: development
    networks:
      - backend
    ports:
      - '3000:3000'
    volumes:
      - ./backend:/usr/src/app:ro

  lighthouse:
    image: kmturley/lighthouse-ci
    networks:
      - backend
    ports:
      - "8085:8085"

networks:
  backend:
    driver: bridge

qa/page_runner.py

import os, requests, json, re
BASE_URL = os.getenv('BASE_URL', 'https://localhost:3000')
LIGHTHOUSE_IMAGE = os.getenv('LIGHTHOUSE_IMAGE', 'http://localhost:8085')
headers = {
  'Accept-Charset': 'UTF-8',
  'Content-Type': 'application/json',
  'X-API-KEY': '<YOUR_API_KEY>'
}

# r = requests.post(LIGHTHOUSE_IMAGE + '/ci', data='{"format": "json", "url": "' + BASE_URL + '"}', headers=headers)
r = requests.get(LIGHTHOUSE_IMAGE + '/stream?format=json&url=' + BASE_URL, headers=headers)

urls = re.findall(
    'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', r.text)
print (LIGHTHOUSE_IMAGE + urls[0].split('8085')[1])

req = requests.get(LIGHTHOUSE_IMAGE + urls[0].split('8085')[1], headers=headers)
data = req.json()
directory = 'qa/output';
if not os.path.exists(directory):
    os.makedirs(directory)
with open(directory + 'index.report.json', 'w') as f:
    json.dump(data, f)
print ('copied to: ' + directory + 'index.report.json')

Gitlab CI

.gitlab-ci.yml

test_accessibility:
  image: python
  stage: test
  services:
  - name: kmturley/lighthouse-ci
  script:
    - pip install -r requirements.txt
    - BASE_URL="https://$CI_BUILD_REF_SLUG-dot-$GAE_PROJECT.appspot.com" LIGHTHOUSE_IMAGE="http://kmturley__lighthouse-ci:8085" python qa/page_runner.py

BitBucket CI

bitbucket-pipelines.yml

image: python:2.7

pipelines:
  default:
    - step:
        services:
          - lighthouse
        script:
          - echo 'verify_accessibility' &&
            pip install -r requirements.txt &&
            BASE_URL="http://$BITBUCKET_BRANCH.$BITBUCKET_PROJECT.elasticbeanstalk.com" LIGHTHOUSE_IMAGE="http://127.0.0.1:8085" python qa/page_runner.py

definitions:
  services:
    lighthouse:
      image: kmturley/lighthouse-ci

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants