Skip to content

Commit

Permalink
First working unlighthouse build
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjol committed Aug 26, 2024
1 parent e736c27 commit cdf4251
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 103 deletions.
13 changes: 13 additions & 0 deletions commands/unlighthouse/unlighthouse
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#ddev-generated

## Description: Run unlighthouse and prepare reports
## Usage: unlighthouse
## Example: "ddev unlighthouse"
## ExecRaw: true
# export NODE_TLS_REJECT_UNAUTHORIZED='0'

FOLDER=${1:-'local'}
FILE=${2:-'unlighthouse.ts'}

unlighthouse --config-file=./config/$FOLDER/$FILE --upload.outputDir=./export/$FOLDER
17 changes: 0 additions & 17 deletions docker-compose.addon-template.yaml

This file was deleted.

28 changes: 28 additions & 0 deletions docker-compose.unlighthouse.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ddev-generated
services:
unlighthouse:
container_name: ddev-${DDEV_SITENAME}-unlighthouse
build:
context: './unlighthouseBuild'
args:
username: $USER
uid: $DDEV_UID
gid: $DDEV_GID
user: '$DDEV_UID:$DDEV_GID'
networks: [default, ddev_default]
restart: "no"
shm_size: ${UNLIGHTHOUSE_SHM_SIZE:-1gb}
cap_add:
- SYS_ADMIN
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
entrypoint: [ "/entrypoint.sh" ]
environment:
DDEV_HOSTNAME: $DDEV_HOSTNAME
NODE_EXTRA_CA_CERTS: /mnt/ddev-global-cache/mkcert/rootCA.pem
volumes:
- ../reports/unlighthouse:/home/$USER/reports/export
- ../tests/unlighthouse:/home/$USER/reports/config
- .:/mnt/ddev_config:ro
- ddev-global-cache:/mnt/ddev-global-cache
93 changes: 7 additions & 86 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -1,91 +1,12 @@
# Details about the install.yaml file are at https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#sections-and-features-of-ddev-get-add-on-installyaml
name: unlighthouse

name: addon-template

# pre_install_actions - list of actions to run before installing the addon.
# Examples would be removing an extraneous docker volume,
# or doing a sanity check for requirements.
# DDEV environment variables can be interpolated into these actions
pre_install_actions:
# Actions with #ddev-nodisplay will not show the execution of the action, but may show their output
# - |
# #ddev-nodisplay
#ddev-description:Check architecture type for incompatible arm64 type
# if [ "$(arch)" = "arm64" -o "$(arch)" = "aarch64" ]; then
# echo "This package does not work on arm64 machines";
# exit 1;
#fi

# - "docker volume rm ddev-${DDEV_PROJECT}_solr 2>/dev/null || true"
#- |
# # Using #ddev-nodisplay tells ddev to be quiet about this action and not show it or its output.
# #ddev-nodisplay
# #ddev-description:Remove solr volume
# if ! ( ddev debug capabilities 2>/dev/null | grep multiple-dockerfiles >/dev/null 2>&1 ) ; then
# echo "This add-on requires DDEV v1.19.4 or higher, please upgrade." && exit 2
# fi
#- 'echo "what is your platform.sh token" && read x'

# This item shows templating using DDEV environment variables.
# -
# #ddev-description:Touch a file to create it
# touch somefile.${DDEV_PROJECT_TYPE}.${DDEV_DOCROOT}.txt
#

# This item shows complex go templating possibilities based on yaml_read_files
#- |
#- #ddev-description:Create a config.platformsh.yaml
# cat <<EOF >.ddev/config.platformsh.yaml
# php_version: {{ trimPrefix "php:" .platformapp.type }}
# database:
# type: {{ regexReplaceAll ":.*$" .services.db.type "" }}
# version: {{ regexReplaceAll "^.*:" .services.db.type "" }}
#
# docroot: {{ dig "web" "locations" "/" "root" "notfound" .platformapp }}
# {{ if eq .platformapp.build.flavor "composer" }}
# hooks:
# post-start:
# - composer: install
# {{ if .platformapp.hooks.deploy }}
# - exec: "{{ trimAll "\n" .platformapp.hooks.deploy | splitList "\n" | join ` && ` }}"
# {{ end }}
# {{ end }}
#
# EOF

# list of files and directories listed that are copied into project .ddev directory
# Each file should contain #ddev-generated so it can be replaced by a later `ddev get`
# if it hasn't been modified by the user.
# DDEV environment variables can be interpolated into these filenames
project_files:
- docker-compose.addon-template.yaml
# - extra_files/
# - somefile.sh
- docker-compose.unlighthouse.yaml
- unlighthouseBuild
- commands

# List of files and directories that are copied into the global .ddev directory
# DDEV environment variables can be interpolated into these filenames
global_files:
# - commands
# - homeadditions

# List of add-on names that this add-on depends on
dependencies:
# - redis

# DDEV environment variables can be interpolated into these actions
post_install_actions:
# - chmod +x ~/.ddev/commands/web/somecommand
# - touch somefile.${GOOS}.${DDEV_WEBSERVER}
# - perl -pi -e 's/oldstring/newstring/g' docker-compose.addon-template.yaml

# Shell actions that can be done during removal of the add-on
removal_actions:
# - rm ~/.ddev/commands/web/somecommand

# Advanced usage - yaml files can be read in and then used as go template actions
# in pre_install_actions and post_install_actions
# See example in
# https://github.com/rfay/ddev/blob/20220606_yaml_read_experiment/cmd/ddev/cmd/testdata/TestCmdGetComplex/recipe/install.yaml
yaml_read_files:
# someyaml: someyaml.yaml
# otheryaml: someotheryaml.yaml
- test -d ${DDEV_APPROOT}/reports/unlighthouse || mkdir -p ${DDEV_APPROOT}/reports/unlighthouse
- test -f "${DDEV_APPROOT}/reports/unlighthouse/.gitfile" || touch ${DDEV_APPROOT}/reports/unlighthouse/.gitfile
- echo "Install finished."
54 changes: 54 additions & 0 deletions unlighthouseBuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ddev-generated
# Based on https://github.com/indykoning/unlighthouse-docker/tree/master
FROM node:22-bullseye

RUN apt update --fix-missing; \
apt install -y chromium; \
apt install -y nss-passwords; \
apt install -y libfreetype6; \
apt install -y libharfbuzz-bin; \
apt install -y ca-certificates; \
apt install -y fonts-freefont-ttf;

RUN npm install -g unlighthouse

EXPOSE 5678

# Tell Puppeteer to skip installing Chrome. We'll be using the installed package.
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
ENV SITE="http://localhost"

RUN chown root:root /usr/lib/chromium/chrome-sandbox && \
chmod 4755 /usr/lib/chromium/chrome-sandbox

# Add user so we don't need --no-sandbox.
RUN adduser --help
RUN addgroup unlighthouse && adduser --ingroup unlighthouse unlighthouse \
&& mkdir -p /home/unlighthouse/Downloads /app \
&& chown -R unlighthouse:unlighthouse /home/unlighthouse \
&& chown -R unlighthouse:unlighthouse /app

# Add custom entrypoint
COPY ./entrypoint.sh /entrypoint.sh

# Swap to root user.
USER root
RUN chmod +x /entrypoint.sh

# delete the default 'node' user with uid 1000 and add current ddev user
ARG username
ARG uid
ARG gid
RUN userdel -r node
RUN (groupadd --gid $gid "$username" || groupadd "$username" || true) && (useradd -l -m -s "/bin/bash" --gid "$username" --comment '' --uid $uid "$username" || useradd -l -m -s "/bin/bash" --gid "$username" --comment '' "$username" || useradd -l -m -s "/bin/bash" --gid "$gid" --comment '' "$username" || useradd -l -m -s "/bin/bash" --comment '' $username )

# Add sudo and sudoers in manner similar to other ddev containers
RUN apt update --fix-missing; apt install -y sudo; mkdir /etc/sudoers.d; echo "ALL ALL=NOPASSWD: ALL" > /etc/sudoers.d/ddev-lighthouse && chmod 440 /etc/sudoers.d/ddev-lighthouse

RUN mkdir --parents /home/$username/reports && chown --recursive $username:$username /home/$username

# Setup ddev user name and folder.
USER $username
WORKDIR /home/$username/reports


17 changes: 17 additions & 0 deletions unlighthouseBuild/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#ddev-generated

routerIp=$(getent hosts ddev-router | awk '{ print $1 }')

# Add entries to /etc/hosts for each DDEV_HOSTNAME (all hostnames in the web container)
if [ -n "$routerIp" ]; then
OIFS=$IFS
IFS=','
for i in $DDEV_HOSTNAME; do
echo "Add to /etc/hosts: routerIp $i"
sudo sh -c "echo $routerIp $i >> /etc/hosts"
done
IFS=$OIFS
fi

sleep infinity

0 comments on commit cdf4251

Please sign in to comment.