Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
layout: post | ||
title: PlaywrightをGoogle Cloud Runで動かす | ||
date: 2022-12-24 00:00:00 +0900 | ||
tags: [Playwright,Google Cloud Run] | ||
--- | ||
|
||
# Google Cloud Run | ||
|
||
Cloud RunでHTTP APIを定義できるのは知っていましたがプレビューでジョブも定義できるようになったので使ってみました。 | ||
|
||
npm installだけでよい通常のライブラリであれば後述するDockerfileを定義する必要も無く、下記のサンプルのようにシンプルになります。 | ||
|
||
[クイックスタート: Cloud Run で Node.js ジョブをビルドして作成する \| Cloud Run のドキュメント \| Google Cloud](https://cloud.google.com/run/docs/quickstarts/jobs/build-create-nodejs?hl=ja) | ||
|
||
# cloudbuild.yml | ||
|
||
```angular2html | ||
steps: | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/$IMAGE_NAME', '.' ] | ||
images: | ||
- 'gcr.io/$PROJECT_ID/$IMAGE_NAME' | ||
``` | ||
|
||
`$PROJECT_ID` `IMAGE_NAME` は各自の環境に合わせて変更してください。 | ||
|
||
# Dockerfile | ||
|
||
```dockerfile | ||
FROM node:16.19-bullseye-slim | ||
ENV HOME="/home" | ||
WORKDIR /app | ||
COPY . . | ||
RUN npm ci && npx playwright install --with-deps chromium | ||
CMD npm run start | ||
``` | ||
|
||
`ENV HOME="/home"` がないとCloud Runで実行した時にplaywrightが見つからず、エラーになっていました。 |