### Sample HTML Page for Serverless Deployment
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
A basic HTML page structure designed for deployment in a Yandex Cloud serverless container. This serves as a minimal example to verify successful deployment and display a welcome message.
```html
Welcome to SourceCraft!
Welcome to SourceCraft!
For online documentation and support please refer to
sourcecraft.dev.
Thank you for using SourceCraft.
```
--------------------------------
### Configure Yandex Cloud Service Account for CI/CD
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
This snippet outlines the bash commands to create a Yandex Cloud service account, assign it essential roles (serverless-containers.editor, container-registry.images.pusher, iam.serviceAccounts.user), and set up a container registry. These steps are crucial for enabling SourceCraft to deploy serverless applications.
```bash
yc iam service-account create --name ci-cd-service-account
yc resource-manager folder add-access-binding \
--role serverless-containers.editor \
--subject serviceAccount:
yc resource-manager folder add-access-binding \
--role container-registry.images.pusher \
--subject serviceAccount:
yc resource-manager folder add-access-binding \
--role iam.serviceAccounts.user \
--subject serviceAccount:
yc container registry create --name my-registry
yc container registry list
```
--------------------------------
### Configure CI/CD Pipeline with YAML
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
This YAML configuration file defines the CI/CD process, including triggers, authentication tokens, and tasks for building and deploying an application to Yandex Cloud. It sets up the environment variables, retrieves IAM tokens, configures Docker Buildx, authenticates with Container Registry, and builds and pushes the Docker image.
```yaml
# .sourcecraft/ci.yaml - Полная конфигурация CI/CD-пайплайна
on:
push:
- workflows: demo-service-connection-workflow
tokens:
SERVICE_CONNECTION:
service_connection: default-service-connection
scope: org
workflows:
demo-service-connection-workflow:
tasks:
- name: demo-task
env:
YC_DOCKER_REGISTRY_URI: cr.yandex/
IMAGE_NAME: demo-image
YC_SERVERLESS_CONTAINER_NAME: demo-serverless-container1
YC_SERVICE_ACCOUNT_ID: ${{ tokens.SERVICE_CONNECTION.service_account_id }}
cubes:
# Получение IAM-токена для аутентификации
- name: get-iam-token
env:
ID_TOKEN: ${{ tokens.SERVICE_CONNECTION.id_token }}
YC_SA_ID: ${{ tokens.SERVICE_CONNECTION.service_account_id }}
image: cr.yandex/sourcecraft/yc-iam:latest
# Настройка Docker Buildx
- name: setup-buildx
action: docker/setup-buildx-action@v3.11.1
# Аутентификация в Container Registry
- name: login
action: docker/login-action@v3.5.0
with:
registry: ${{env.YC_DOCKER_REGISTRY_URI}}
username: iam
password: ${{ cubes.get-iam-token.outputs.IAM_TOKEN }}
# Сборка и публикация Docker-образа
- name: build-and-push
action: docker/build-push-action@v6.18.0
with:
context: .
file: Dockerfile
platforms: linux/amd64
tags: |
${{env.YC_DOCKER_REGISTRY_URI}}/demo-image:latest
push: true
```
--------------------------------
### Build Docker Image for Nginx Application
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
This Dockerfile defines the process for building a lightweight container based on nginx-unprivileged. It exposes port 8080, copies the configuration file and the index.html file into the container, and sets up the necessary environment for the nginx application to run.
```dockerfile
# Dockerfile - Сборка nginx-контейнера
FROM nginxinc/nginx-unprivileged
EXPOSE 8080
COPY ./docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY ./index.html /usr/share/nginx/html/index.html
```
--------------------------------
### Configure Nginx for Static Files
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
This Nginx configuration file sets up the server to serve static files and supports Single Page Application (SPA) routing. It listens on port 8080, specifies the root directory, and uses the index.html file as the index. It also defines a location block to handle requests, routing them to index.html if the requested resource is not found.
```nginx
# docker/nginx/conf.d/default.conf
server {
listen 8080;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
```
--------------------------------
### Deploy to Serverless Containers with YC CLI
Source: https://context7.com/sourcecraft/yc-ci-cd-serverless.git/llms.txt
This code snippet uses the Yandex Cloud CLI to create or update a serverless container, checking for its existence before deploying a new revision. It sets the folder ID, retrieves the IAM token, checks if the container exists, creates it if necessary, and then deploys a new revision of the container.
```yaml
# Развертывание контейнера с использованием Yandex Cloud CLI
- name: yc-cli-demo
env:
YC_FOLDER_ID: ${{ tokens.SERVICE_CONNECTION.folder_id }}
YC_IAM_TOKEN: ${{ cubes.get-iam-token.outputs.IAM_TOKEN }}
image:
name: cr.yandex/sourcecraft/yc-cli:latest
entrypoint: ""
script:
- |
# Установка рабочего каталога
yc config set folder-id $YC_FOLDER_ID
# Проверка существования контейнера и его создание при необходимости
if ! yc serverless container get --name $YC_SERVERLESS_CONTAINER_NAME &>/dev/null; then
echo "Container $YC_SERVERLESS_CONTAINER_NAME does not exist. Creating it..."
yc serverless container create --name $YC_SERVERLESS_CONTAINER_NAME \
--folder-id $YC_FOLDER_ID \
--description "Container created automatically"
echo "Container $YC_SERVERLESS_CONTAINER_NAME created successfully"
else
echo "Container $YC_SERVERLESS_CONTAINER_NAME already exists"
fi
# Развертывание новой ревизии контейнера
yc serverless container revision deploy \
--container-name $YC_SERVERLESS_CONTAINER_NAME \
--image $YC_DOCKER_REGISTRY_URI/$IMAGE_NAME:latest \
--service-account-id $YC_SERVICE_ACCOUNT_ID
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.