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

Fixed docker image to enable running Lighthouse #517

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,44 @@ RUN go get -d -v
# Build the binary.
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o /go/bin/sswlinkauditor


############################
# Build the nodejs app
############################
FROM node:18 AS nodeBuilder
FROM node:16-bullseye AS nodeBuilder
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --legacy-peer-deps
RUN npm install
RUN node -v
COPY *.js ./

############################
# Build smallest image from node
############################
# FROM astefanutti/scratch-node
FROM node:18
FROM node:16-bullseye-slim

# Set variable so puppeteer will not try to download chromium
ENV PUPPETEER_SKIP_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable

# Install utilities
RUN apt-get update --fix-missing && apt-get -y upgrade && apt-get install -y git wget gnupg && apt-get clean

# Install Chromium for lighthouse
RUN apt-get update \
&& apt-get install -y chromium --no-install-recommends \
&& apt-get clean

# install perl for cloc
# RUN apk update && apk add perl
# Install Lighthouse CI
RUN npm install -g @lhci/[email protected]
RUN npm install -g lighthouse

# install chrome for light house
# RUN apt-get install -y wget
# RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
# && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# RUN apt-get update && apt-get -y install google-chrome-stable
# Install puppeteer
RUN npm install -g puppeteer

# add user because we can't run lighthouse with root user
# Setup a user to avoid doing everything as root
RUN groupadd --system lhci && \
useradd --system --create-home --gid lhci lhci && \
mkdir --parents /home/lhci/app && \
mkdir --parents /home/lhci/app/src && \
mkdir --parents /home/lhci/reports && \
chown --recursive lhci:lhci /home/lhci

RUN ls /etc/apt/sources.list.d
RUN cd /home/lhci/reports && npm link puppeteer
USER lhci

WORKDIR /home/lhci/app
Expand All @@ -57,8 +61,6 @@ COPY --from=builder /go/bin/sswlinkauditor /home/lhci/app/sswlinkauditor
# main nodejs app
COPY --from=nodeBuilder /usr/src/app /home/lhci/app

CMD [ "lhci", "--help" ]

# ENTRYPOINT ["./sswlinkauditor"]
# ENTRYPOINT ["./node_modules/.bin/lhci"]
# ENTRYPOINT ["./node_modules/.bin/cloc"]
ENTRYPOINT ["node","."]
ENTRYPOINT ["node","."]
4 changes: 2 additions & 2 deletions docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const _getAgrs = () => {
.option("lighthouse", {
describe: "Include Lighthouse audit",
type: "boolean",
default: false,
default: true,
})
.option("artillery", {
describe: "Include Artillery test",
Expand Down Expand Up @@ -183,7 +183,7 @@ const main = async () => {
writeLog(`start lighthouse`);
try {
const rs = execSync(
`./node_modules/.bin/lhci collect --url="${options.url}" -n 1`
`./node_modules/.bin/lhci collect --url="${options.url}"`
).toString();
writeLog(`lighthouse check finished`, rs);
} catch (e) {
Expand Down
34 changes: 17 additions & 17 deletions docker/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"box-console": "^2.0.0",
"boxen": "^4.2.0",
"chalk": "^3.0.0",
"csv-parser": "^2.3.5",
Expand Down
7 changes: 3 additions & 4 deletions docker/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const boxen = require("boxen");
const { htmlHintConfig, fetchHtml, getHTMLHintRules } = require("./api");
const R = require("ramda");
const { execSync } = require("child_process");
const boxConsole = require("box-console");
const slug = require("slug");
const nodemailer = require("nodemailer");
const fns = require('date-fns')
Expand Down Expand Up @@ -595,7 +594,7 @@ exports.printResultsToConsole = (
`${strPwa.padEnd(10)} ${lhScaled.pwaScore.toString().padStart(10)} / 100`
);

boxConsole([avg, performance, bestPractice, seo, pwa]);
consoleBox([avg, performance, bestPractice, seo, pwa], "green");
}

if (atrSummary) {
Expand Down Expand Up @@ -642,7 +641,7 @@ exports.printResultsToConsole = (
);
let errors = chalk(`${strErrors} ${atrSummary.errors}`);

boxConsole([
consoleBox([
timestamp,
scenCreated,
scenCompleted,
Expand All @@ -657,7 +656,7 @@ exports.printResultsToConsole = (
scenarioDurationP95,
scenarioDurationP99,
errors,
]);
], "green");
}

// output htmlhint summary
Expand Down
4 changes: 2 additions & 2 deletions ui/src/containers/Dashboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
## Get Started
Scan any website for broken links and [HTML Issues](https://htmlhint.com) by running the following command:
\`\`\` bash
$ docker run sswconsulting/codeauditor --token ${token} --url <URL>
$ docker container run --cap-add=SYS_ADMIN sswconsulting/codeauditor --token ${token} --url <URL>
\`\`\`

If you don't you your scan to be uploaded publicly, following command will upload your scan to your private profile:
\`\`\` bash
$ docker run sswconsulting/codeauditor --token ${token} --url <URL> --private
$ docker container run --cap-add=SYS_ADMIN sswconsulting/codeauditor --token ${token} --url <URL> --private
\`\`\`

Where: **${token}** is a unique token assigned to your account and **BUILDID** (optional) is your CI build number
Expand Down
2 changes: 1 addition & 1 deletion ui/src/containers/HowItWorks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
## How to Use CodeAuditor
Scan any website for broken links, [HTML Issues](https://htmlhint.com), [Google Lighthouse Audit](https://developers.google.com/web/tools/lighthouse) and [Artillery Load Test](https://artillery.io/) by running the following command:
\`\`\` bash
$ docker container run sswconsulting/codeauditor ${tokenText} --url <URL>
$ docker container run --cap-add=SYS_ADMIN sswconsulting/codeauditor ${tokenText} --url <URL>
\`\`\`
`;

Expand Down
2 changes: 1 addition & 1 deletion ui/src/containers/Public.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
## SSW CodeAuditor
Scan any website for broken links, [HTML Issues](https://htmlhint.com), [Google Lighthouse Audit](https://developers.google.com/web/tools/lighthouse) and [Artillery Load Test](https://artillery.io/) by running the following command:
\`\`\` bash
$ docker container run sswconsulting/codeauditor --cap-add=SYS_ADMIN --url <URL>
$ docker container run --cap-add=SYS_ADMIN sswconsulting/codeauditor --url <URL>
\`\`\`
Sign in to view prior scans and unlock more features
`;
Expand Down
Loading