initial commit
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Robert Kaussow 2020-07-16 09:53:03 +02:00
commit e3776c284a
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61
6 changed files with 293 additions and 0 deletions

123
.drone.yml Normal file
View File

@ -0,0 +1,123 @@
---
kind: pipeline
name: build-container
platform:
os: linux
arch: amd64
steps:
- name: dryrun
image: plugins/docker
settings:
build_args:
- BUILD_VERSION=${DRONE_TAG%-*}
dockerfile: Dockerfile
dry_run: true
password:
from_secret: docker_password
repo: xoxys/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/pull/**
- name: tags
image: xoxys/docker-autotag
environment:
DOCKER_AUTOTAG_FORCE_LATEST: True
DOCKER_AUTOTAG_IGNORE_PRERELEASE: True
DOCKER_AUTOTAG_OUTPUT_FILE: .tags
DOCKER_AUTOTAG_VERSION: ${DRONE_TAG}
when:
ref:
- refs/heads/master
- refs/tags/**
- name: publish
image: plugins/docker
settings:
build_args:
- BUILD_VERSION=${DRONE_TAG%-*}
dockerfile: Dockerfile
password:
from_secret: docker_password
repo: xoxys/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/heads/master
- refs/tags/**
- name: publish-gitea
image: plugins/gitea-release
settings:
api_key:
from_secret: gitea_token
base_url: https://gitea.rknet.org
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: readme
image: sheogorath/readme-to-dockerhub
environment:
DOCKERHUB_PASSWORD:
from_secret: docker_password
DOCKERHUB_REPO_NAME: ${DRONE_REPO_NAME}
DOCKERHUB_REPO_PREFIX: xoxys
DOCKERHUB_USERNAME:
from_secret: docker_username
README_PATH: README.md
SHORT_DESCRIPTION: lhci - Simple wrapper for lighthouse-ci
when:
status:
- success
- name: matrix
image: plugins/matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
username:
from_secret: matrix_username
when:
status:
- success
- failure
trigger:
ref:
- refs/heads/master
- refs/tags/**
status:
- success
- failure
depends_on:
- build-container
---
kind: signature
hmac: befd5fdd0b708ae98e2935494ee9220d94de90b485300b0fe489da6752c071d8
...

1
CHANGELOG.md Normal file
View File

@ -0,0 +1 @@
- initial release

41
Dockerfile Normal file
View File

@ -0,0 +1,41 @@
FROM node:10-alpine
# due to https://github.com/http-party/http-server/issues/537
LABEL maintainer="Robert Kaussow <mail@geeklabor.de>" \
org.label-schema.name="lhci" \
org.label-schema.vcs-url="https://gitea.rknet.org/docker/lhci" \
org.label-schema.vendor="Robert Kaussow" \
org.label-schema.schema-version="1.0"
ARG BUILD_VERSION=latest
ENV LHCI_VERSION="${BUILD_VERSION:-latest}" \
LHCI_BASE_DIR=/drone/src \
FORCE_COLOR=true \
NPM_CONFIG_LOGLEVEL=error
ADD overlay/ /
RUN apk --update add --virtual .build-deps curl && \
apk add --update --no-cache git chromium jq && \
curl -SsL -o /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/3.3.2/yq_linux_amd64 && \
chmod 755 /usr/local/bin/yq && \
LHCI_VERSION="${LHCI_VERSION##v}" && \
LHCI_MAJOR="${LHCI_VERSION%%.*}" && \
if [ -z "${LHCI_MAJOR//[0-9]}" ] && [ -n "$LHCI_MAJOR" ]; then \
echo "Installing lhci version '$LHCI_VERSION' ..." && \
npm install -g @lhci/cli@"$LHCI_VERSION"; \
else \
echo "Installing latest lhci ..." && \
npm install -g @lhci/cli; \
fi && \
npm install -g lighthouse && \
apk del .build-deps && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/* && \
rm -rf /root/.cache/
USER root
CMD []
WORKDIR /drone/src
ENTRYPOINT ["/usr/bin/lhci", "autorun"]

92
README.md Normal file
View File

@ -0,0 +1,92 @@
# [lhci](https://gitea.rknet.org/docker/lhci)
[![Build Status](https://img.shields.io/drone/build/docker/lhci?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/docker/lhci)
[![Docker Hub](https://img.shields.io/badge/docker-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/xoxys/lhci)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://gitea.rknet.org/docker/lhci/src/branch/master/LICENSE)
Simple wrapper for [lighthouse-ci](https://github.com/GoogleChrome/lighthouse-ci).
## Usage
There are two wrapper scripts around the lhci command you could use:
- `/usr/bin/lhci-official`: This will simply forward your command to the official binary at `/usr/local/bin/lhci`
- `/usr/bin/lhci`: This is a modified wrapper to post-process the created report file to prepare an upload.
The wrapper `/usr/bin/lhci` will do the following:
- create `DIST=$LHCI_BASE_DIR/$UPLOAD_OUTPUT_DIR/dist/$LHCI_REPO_NAME`
- find all files flagged with `isRepresentativeRun` in the `manifest.json`
- copy those files to `$DIST`
To get it working you need to configure the `fileupload` in `.lighthouserc.yml`command line configuration will not work:
```Yaml
---
ci:
[...]
upload:
target: filesystem
# has to be a relative path to the .lighthouserc.yml location
outputDir: lhci_reports
```
What you will get is the following file structure which could be used as an upload source:
```Shell
lhci_reports/dist/$REPO_NAME/
├── 9cf658e2-202007160745.html
├── f33fa4c4-202007160745.html
└── ffae8d3e-202007160745.html
# <FILENAME_HASH>-<DATETIME>.html
```
You will also get the target URLs in your CI output:
```Shell
/usr/bin/lhci autorun
[...]
All results processed!
Dumping 6 reports to disk at /drone/src/lhci_reports...
Done writing reports to disk.
Done running autorun.
Post-process report files...
Report for http://localhost:43901/ will be uploaded to https://example.com/9cf658e2-202007160745.html
Report for http://localhost:43901/404.html will be uploaded to https://example.com/ffae8d3e-202007160745.html
Report for http://localhost:43901/posts/ will be uploaded to https://example.com/f33fa4c4-202007160745.html
```
```Shell
docker run -v $(pwd)/public:/drone/src lhci autorun
# or pass arguments to lhci
docker run -v $(pwd)/public:/drone/src lhci autorun --upload.target=temporary-public-storage
```
## Environment variables
```Shell
LHCI_BASE_DIR="/drone/src"
LHCI_SERVER_URL="https://example.com/"
LHCI_REPO_NAME=$DRONE_REO_NAME
```
## Build
```Shell
docker build -t lhci:latest .
```
## License
This project is licensed under the MIT License - see the [LICENSE](https://gitea.rknet.org/docker/lhci/src/branch/master/LICENSE) file for details.
## Maintainers and Contributors
[Robert Kaussow](https://gitea.rknet.org/xoxys)

32
overlay/usr/bin/lhci Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env sh
set -eo pipefail
CONFIG="${LHCI_BASE_DIR%/}/.lighthouserc.yml"
/usr/local/bin/lhci "$@"
if [ -f "$CONFIG" ]; then
UPLOAD_TARGET=$(yq r "${CONFIG}" --defaultValue "" ci.upload.target)
UPLOAD_OUTPUT_DIR=$(yq r "${CONFIG}" --defaultValue "" ci.upload.outputDir)
if [ "${UPLOAD_TARGET}" = "filesystem" ] && [ -n "${UPLOAD_OUTPUT_DIR}" ] ; then
MANIFEST=${UPLOAD_OUTPUT_DIR%/}/manifest.json
DIST="${LHCI_BASE_DIR%/}/${UPLOAD_OUTPUT_DIR%/}/dist/${LHCI_REPO_NAME}"
mkdir -p "${DIST}"
printf "\nPost-process report files...\n"
for ITEM in $(jq -r '.[] | select( .isRepresentativeRun == true ) | @base64' < "${MANIFEST}"); do
JSON=$(echo "${ITEM}" | base64 -d)
FILE_DATE=$(date '+%Y%m%d%H%M')
FILENAME=$(echo "${JSON}" | jq -r '.htmlPath')
HASH=$(sha1sum "$FILENAME")
FILENAME_NEW="${HASH:0:8}-$FILE_DATE"
URL=$(echo "${JSON}" | jq -r '.url')
cp "${FILENAME}" "${DIST}/${FILENAME_NEW}.html"
echo "Report for ${URL} will be uploaded to ${LHCI_SERVER_URL%/}/$(basename "${FILENAME_NEW}").html"
done
fi
fi

4
overlay/usr/bin/lhci-official Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -eo pipefail
exec /usr/local/bin/lhci "$@"