This project is created for people who want to start creating the Yandex.Cloud functions using Typescript.
One of the advantages of creating cloud functions using TypeScript is that you can use new JavaScript features such as Nullish Coalescing Operator, etc.
- Typescript
- Jest
- Eslint
- CI/CD using github actions
- Clone repository
- Remove
.git
folder:rm -rf .git
- Set remote origin to your github repo
- Setup secret tokens to deploy function using GitHub Actions
Deployment to the Yandex.Cloud is made using a third-party package: Goodsmileduck/yandex-serverless-action.
You can specify additional options for Goodsmileduck/yandex-serverless-action
here: ./github/workflows/workflow.yml
To start the automatic process CI / CD, you must specify some Actions secrets:
YC_TOKEN
- Required. Token to use Yandex.Cloud CLI. Copy it from hereYC_FUNCTION_ID
- Required. The identifier of the function you want to deploy. (To begin with, you need to create it manually)YC_SERVICE_ACCOUNT
- Optional. If you want to get a service account token in the function context parameter to access the YC API inside the function.
In the case of a successful setup, after Push / Pull request to the main
branch, it will test the function, build it and deploy to the Yandex.Cloud.
- Build the function with
npm run build
script - Archive the content of the
dist
folder - Upload zip archive via Yandex.Cloud console
- Build the function with
npm run build
script - Run Yandex.Cloud CLI command (replace
${YOUR_FUNCTION_ID}
with yout function id):
yc serverless function version create \
--runtime nodejs12 \
--entrypoint index.handler \
--memory 128m \
--execution-timeout 3s \
--source-path ./dist \
--function-id ${YOUR_FUNCTION_ID}
You can run npm run build:zip
script to build and pack function into zip archive.
If you don't want to deploy package.json
with devDependecies
(to avoid limits for installing dependencies), then you can use jq to delete devDependecies
property from package.json
:
cat <<< $(jq 'del(.devDependencies)' package.json) > dist/package.json
If you are using Yarn, then to prevent CI/CD errors about differences in package versions, you need to update the .github/workflows/workflow.yaml
to install packages with the yarn install --frozen-lockfile
instead of npm ci
command.