diff --git a/pg-query/handler.py b/pg-query/code/handler.py similarity index 100% rename from pg-query/handler.py rename to pg-query/code/handler.py diff --git a/pg-query/requirements.txt b/pg-query/code/requirements.txt similarity index 100% rename from pg-query/requirements.txt rename to pg-query/code/requirements.txt diff --git a/pg-query/main.tf b/pg-query/main.tf index 9e539df..28e85a4 100644 --- a/pg-query/main.tf +++ b/pg-query/main.tf @@ -1,11 +1,13 @@ -# 2026-03-07 +# 2026-03-09 # main.tf — e2e тест: создать serverless функцию, которая читает из PostgreSQL. # +# Структура: +# code/ — исходники (handler.py, requirements.txt) +# dist/ — zip-архив (генерируется archive_file datasource) +# # Использование: -# 1. zip handler.py + requirements.txt: -# zip handler.zip handler.py requirements.txt -# 2. terraform init && terraform apply -# 3. После apply (ждёт ~2 мин пока kaniko соберёт образ): +# terraform init && terraform apply +# После apply (ждёт ~2 мин пока kaniko соберёт образ): # curl -s -X POST -d '{}' # # Оператор запущен в кластере: https://sless-api.kube5s.ru @@ -18,6 +20,10 @@ terraform { source = "terra.k8c.ru/naeel/sless" version = "~> 0.1.7" } + archive = { + source = "hashicorp/archive" + version = "~> 2.0" + } } } @@ -26,6 +32,12 @@ provider "sless" { token = "dev-token-change-me" } +data "archive_file" "handler_pg_query" { + type = "zip" + source_dir = "${path.module}/code" + output_path = "${path.module}/dist/handler.zip" +} + resource "sless_function" "pg_query" { namespace = "default" name = "pg-query" @@ -40,8 +52,8 @@ resource "sless_function" "pg_query" { PG_DSN = "postgres://sless:sless-pg-password@postgres.sless.svc.cluster.local:5432/sless?sslmode=disable" } - code_path = "${path.module}/handler.zip" - code_hash = filesha256("${path.module}/handler.py") + code_path = data.archive_file.handler_pg_query.output_path + code_hash = filesha256("${path.module}/code/handler.py") } resource "sless_trigger" "pg_query_http" {