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

ci: open-next terraform module for YC #234

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions .github/workflows/deploy-serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Deploy

on:
workflow_call:
inputs:
environment:
required: true
description: Environment name
type: string
stage_name:
type: string
required: true
description: Название стенда
secrets:
YC_SA_JSON_CREDENTIALS:
description: Json, содержащий авторизованные ключи для сервисного аккаунта. Подробнее https://cloud.yandex.ru/docs/container-registry/operations/authentication#sa-json
DEPLOY_SA_ID:
FOLDER_ID:
TF_STATE_AWS_ACCESS_KEY_ID:
TF_STATE_AWS_SECRET_ACCESS_KEY:

outputs:
domain:
description: Доменное имя развернутого стенда
value: ${{ jobs.deploy.outputs.domain }}

jobs:
deploy:
name: Terraform
environment:
name: ${{ inputs.environment }}
url: ${{ steps.terraform-output.outputs.domain }}/
outputs:
domain: ${{ steps.terraform-output.outputs.domain }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: deploy/open-next
env:
YC_SERVICE_ACCOUNT_KEY_FILE: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
TF_CLI_CONFIG_FILE: '${{ github.workspace }}/.github/files/terraformrc'
TF_VAR_folder_path: '../../.open-next'
# TF_VAR_folder_id: ${{ secrets.FOLDER_ID }}
# TF_VAR_service_account_id: ${{ secrets.DEPLOY_SA_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.TF_STATE_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.TF_STATE_AWS_SECRET_ACCESS_KEY }}
steps:
- uses: actions/checkout@v4

- name: Terraform setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.7.1'
terraform_wrapper: false

- name: Terraform Init
run: terraform init -backend-config="key=${{ inputs.stage_name }}/terraform.tfstate"

- name: Terraform Plan
id: plan
run: terraform plan -input=false -no-color -out tf.plan

- name: Terraform Apply
run: terraform apply -input=false tf.plan

- name: Terraform get output
id: terraform-output
run: echo "domain=$(terraform output -raw api_gateway_domain)" >> "$GITHUB_OUTPUT"

# - name: Purge CDN cache
# uses: yc-actions/yc-cdn-cache@v1
# with:
# yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
# cdn-resource-id: bc8eyazsip6i4r4bqjsa

e2e-test:
# Хороший end-to-end тест представляет из себя более сложную конструкцию, чем curl, проверяющий статус ответа главной страницы стенда. Такой простой тест использован для целей демонстрации
runs-on: ubuntu-latest
needs: deploy
steps:
- run: |
curl '${{ needs.deploy.outputs.domain }}/'
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
jobs:
build:
name: Build
uses: ./.github/workflows/build.yml
uses: ./.github/workflows/build-container.yml
with:
environment: development
secrets:
Expand All @@ -26,7 +26,7 @@ jobs:
deploy:
name: Deploy
needs: build
uses: ./.github/workflows/deploy.yml
uses: ./.github/workflows/deploy-container.yml
with:
image_id: ${{ needs.build.outputs.docker_image }}
stage_name: pr-${{ github.event.number }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
build:
name: Build
# needs: release-name
uses: ./.github/workflows/build.yml
uses: ./.github/workflows/build-container.yml
with:
environment: production
secrets:
Expand All @@ -48,7 +48,7 @@ jobs:
name: Deploy
needs:
- build
uses: ./.github/workflows/deploy.yml
uses: ./.github/workflows/deploy-container.yml
with:
image_id: ${{ needs.build.outputs.docker_image }}
stage_name: production
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,12 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc

# Sentry Config File
.sentryclirc

# @yandex-cloud/serverless-live-debug
.live-debug

# OpenNext
.open-next
5 changes: 5 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# https://pnpm.io/npmrc#registry
# The base URL of the npm package registry (trailing slash included).
registry=https://registry.npmjs.org/

# https://pnpm.io/npmrc#node-linker
# Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don't support symlinks.
# An alternative solution for this problem is to bundle your application before deployment.
node-linker=hoisted
Loading
Loading