Skip to content

Commit 54e57d1

Browse files
committed
Start extracting files from the main repository
1 parent eb5e1e7 commit 54e57d1

5 files changed

Lines changed: 137 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

Dockerfile.lambda

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM public.ecr.aws/lambda/nodejs:12
2+
3+
ENV DOCKERIZED yes
4+
5+
RUN yum install -y \
6+
git gcc make gcc-c++ zlib-devel libjpeg-turbo-devel nasm automake autoconf libtool \
7+
ca-certificates freetype freetype-devel harfbuzz nss \
8+
cups-libs dbus-glib libXrandr libXcursor libXinerama cairo cairo-gobject pango && \
9+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/a/atk-2.26.0-1.fc27.x86_64.rpm && \
10+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/a/at-spi2-atk-2.26.0-1.fc27.x86_64.rpm && \
11+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/a/at-spi2-core-2.26.0-1.fc27.x86_64.rpm && \
12+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libxkbcommon-0.7.1-5.fc27.x86_64.rpm && \
13+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libXcomposite-0.4.4-11.fc27.x86_64.rpm && \
14+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/a/alsa-lib-1.1.4.1-3.fc27.x86_64.rpm && \
15+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libXi-1.7.9-4.fc27.x86_64.rpm && \
16+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libXtst-1.2.3-4.fc27.x86_64.rpm && \
17+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libxkbcommon-x11-0.7.1-5.fc27.x86_64.rpm && \
18+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/g/gtk3-3.22.24-1.fc27.x86_64.rpm && \
19+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libepoxy-1.4.3-3.fc27.x86_64.rpm && \
20+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libwayland-cursor-1.14.0-1.fc27.x86_64.rpm && \
21+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/m/mesa-libwayland-egl-17.2.2-4.fc27.x86_64.rpm && \
22+
rpm -ivh --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/g/gdk-pixbuf2-2.36.11-1.fc27.x86_64.rpm && \
23+
rpm -ivh --force --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/l/libpng-1.6.31-1.fc27.x86_64.rpm && \
24+
rpm -ivh --force --nodeps http://dl.fedoraproject.org/pub/archive/fedora/linux/releases/27/Everything/x86_64/os/Packages/z/zlib-1.2.11-4.fc27.x86_64.rpm && \
25+
yum clean all && \
26+
rm -rf /var/cache/yum
27+
28+
ADD . /var/task
29+
30+
RUN rm -rf node_modules && \
31+
npm install jpegoptim-bin --unsafe-perm=true --allow-root && \
32+
NODE_ENV=development && npm install --only=prod && \
33+
sed -i 's@"--disable-dev-shm-usage"@"--disable-dev-shm-usage", "--no-sandbox", "--no-zygote", "--disable-gpu", "--single-process"@' node_modules/phantomas/lib/browser.js
34+
35+
CMD [ "lambda.runner" ]

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
env ?= dev
2+
AWS_PROFILE ?= yellowlabtools-$(env)
3+
AWS_REGION ?= us-east-1
4+
DOCKER_IMAGE_TAG ?= latest
5+
RESULT_BUCKET_NAME ?= $(env)-yellowlabtools-storage
6+
TEST_NAME ?= test-local
7+
TEST_URL ?= https://www.google.fr
8+
9+
all: install
10+
11+
install:
12+
@npm install
13+
14+
build-docker-image-lambda:
15+
@docker build -f Dockerfile.lambda -t yellowlabtools-runner-lambda .
16+
17+
tag-docker-image-lambda:
18+
@docker tag yellowlabtools-runner-lambda:$(DOCKER_IMAGE_TAG) $(DOCKER_REGISTRY)/yellowlabtools-runner-lambda:$(DOCKER_IMAGE_TAG)
19+
20+
push-docker-image-lambda:
21+
@docker push $(DOCKER_REGISTRY)/yellowlabtools-runner-lambda:$(DOCKER_IMAGE_TAG)
22+
23+
login-docker:
24+
@AWS_PROFILE=$(AWS_PROFILE) aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(DOCKER_REGISTRY)
25+
26+
start-local-lambda:
27+
@docker run --rm -it -p 9000:8080 -e RESULT_BUCKET_NAME=$(RESULT_BUCKET_NAME) -e AWS_ACCESS_KEY_ID=$(AWS_ACCESS_KEY_ID) -e AWS_SECRET_ACCESS_KEY=$(AWS_SECRET_ACCESS_KEY) yellowlabtools-runner-lambda:$(DOCKER_IMAGE_TAG)
28+
29+
run-local-test:
30+
@curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"id": "$(TEST_NAME)", "url": "$(TEST_URL)"}'

lambda.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const AWS = require('aws-sdk');
2+
const s3 = new AWS.S3();
3+
const ylt = require('..');
4+
5+
// noinspection JSUnusedLocalSymbols
6+
async function runner({id, url, options = {}}, context) {
7+
console.log(`Processing run #${id} on ${url}`);
8+
9+
// AWS S3 bucket and path
10+
const bucket = process.env.RESULT_BUCKET_NAME;
11+
const keyPrefix = `results/${id}`;
12+
13+
// Function that can save any file on S3 (JSON, screenshot,...)
14+
const saveFile = async (path, content) => s3.putObject({Bucket: bucket, Key: `${keyPrefix}/${path}`, Body: content})
15+
.promise();
16+
17+
// Let's launch ylt
18+
const result = await ylt(url, {...options, saveScreenshotFn: saveFile})
19+
20+
.then(async data => {
21+
console.log(`Run succeeded`);
22+
23+
data.runId = id;
24+
await saveFile('results.json', JSON.stringify(data));
25+
26+
return {
27+
status: 'processed',
28+
id,
29+
bucket,
30+
keyPrefix
31+
};
32+
})
33+
34+
.fail(error => {
35+
console.log(`Run failed with error: ${error}`);
36+
return {
37+
status: 'failed',
38+
id,
39+
bucket,
40+
errorMessage: error
41+
};
42+
});
43+
44+
return result;
45+
}
46+
47+
module.exports = {runner};

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "yellowlabtools-lambda-agent",
3+
"version": "1.0.0",
4+
"description": "The AWS Lambda testing agent that's in use on https://yellowlab.tools",
5+
"main": "lambda.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/YellowLabTools/YellowLabTools-lambda-agent.git"
12+
},
13+
"author": "Gaël Métais & Olivier Hoareau",
14+
"license": "GPL-2.0",
15+
"bugs": {
16+
"url": "https://github.com/YellowLabTools/YellowLabTools-lambda-agent/issues"
17+
},
18+
"homepage": "https://github.com/YellowLabTools/YellowLabTools-lambda-agent#readme",
19+
"dependencies": {
20+
"aws-sdk": "2.904.0",
21+
"yellowlabtools": "2.1.0"
22+
}
23+
}

0 commit comments

Comments
 (0)