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

Changing from aws-chromelambda to @sparticuz/chromium #492

2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
run: yarn --frozen-lockfile --non-interactive --silent --ignore-scripts
- name: Prepare docker
run: docker pull yukinying/chrome-headless-browser-stable:118.0.5993.117
- name: Prepare docker lambda
run: yarn prepare:lambda:test
- name: Run unit tests
run: yarn test-ci

Expand Down
2 changes: 1 addition & 1 deletion docs/serverless.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ yarn init -y
### 2. Add loki renderer and Chrome binary

```sh
yarn add @loki/renderer-aws-lambda chrome-aws-lambda
yarn add @loki/renderer-aws-lambda @sparticuz/chromium
```

### 3. Expose loki in lambda handler
Expand Down
2 changes: 1 addition & 1 deletion examples/renderer-aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@loki/renderer-aws-lambda": "^0.33.1",
"chrome-aws-lambda": "^2.0.1"
"@sparticuz/chromium": "118.0.0"
}
}
13 changes: 13 additions & 0 deletions examples/running-renderer-aws-lambda/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM amazon/aws-lambda-nodejs:18

ENV DEBUG=*

ADD fixtures ${LAMBDA_TASK_ROOT}/fixtures

COPY package.json ${LAMBDA_TASK_ROOT}

COPY node_modules ${LAMBDA_TASK_ROOT}/node_modules

COPY index.js ${LAMBDA_TASK_ROOT}

CMD ["index.handler"]
15 changes: 15 additions & 0 deletions examples/running-renderer-aws-lambda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Running the lambda locally
This is to simulate and run the lambda locally for development and test pourpose.

### Commands
```sh
yarn build
```

This command will build the docker image with the lambda.

```sh
yarn start
```

This command will start the docker.
28 changes: 28 additions & 0 deletions examples/running-renderer-aws-lambda/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

CONTAINER_ID=$(docker ps -a | grep "example-renderer-aws-lambda" | awk '{print $1}')

if [ ! -z "$CONTAINER_ID" ];
then
echo "Stopping and removing container..."
docker stop $CONTAINER_ID 2>&1
docker rm $CONTAINER_ID 2>&1
fi

IMAGE_NAME=$(docker images | grep "example-renderer-aws-lambda" | awk '{print $1}')

if [ ! -z "$IMAGE_NAME" ];
then
echo "Removing image..."
docker rmi $IMAGE_NAME 2>&1
fi

rm -rf node_modules

yarn

cp -R ../../fixtures fixtures

docker build . -t example-renderer-aws-lambda:latest

rm -rf fixtures
5 changes: 5 additions & 0 deletions examples/running-renderer-aws-lambda/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { createChromeAWSLambdaRenderer } = require('@loki/renderer-aws-lambda');

module.exports = {
handler: createChromeAWSLambdaRenderer(),
};
20 changes: 20 additions & 0 deletions examples/running-renderer-aws-lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@loki/example-running-renderer-aws-lambda",
"version": "0.33.1",
"private": true,
"scripts": {
"build": "sh build.sh",
"start": "docker run -d -p 8080:8080 -t example-renderer-aws-lambda:latest"
},
"dependencies": {
"@loki/renderer-aws-lambda": "file:../../packages/renderer-aws-lambda",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this, add this project to the workspace by adding it to workspaces.packages in the root package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this way to be able to iterate during the development and have the dependencies updated inside node_modules when I installed them. If I use the version when I install this it will fetch from the npm and not from the code I changed.

Is there another way to achieve this?

I added in the other comment why I didn't use the workspace.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an option for yarn workspaces called nohoist which I think should solve this problem: https://classic.yarnpkg.com/blog/2018/02/15/nohoist/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I did the change using workspace and nohoist.

"@sparticuz/chromium": "118.0.0"
},
"resolutions": {
"@loki/target-chrome-app": "file:../../packages/target-chrome-app",
"@loki/target-chrome-core": "file:../../packages/target-chrome-core",
"@loki/browser": "file:../../packages/browser",
"@loki/core": "file:../../packages/core",
"@loki/integration-core": "file:../../packages/integration-core"
}
}
Loading
Loading