환경 관리 및 CI/CD
개발, 스테이징, 운영 환경을 관리하고 수파베이스를 지속적 통합 및 지속적 배포 파이프라인에 통합하는 방법을 학습합니다.
환경 관리 및 CI/CD은(는) CoddyKit의 무료 Supabase Backend as a Service 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Supabase Backend as a Service 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Multiple Environments?
When building applications, it's crucial to manage different stages of development. These stages are called environments.
Typically, you'll work with three main environments:
- Development (Dev): Where developers write and test new features.
- Staging: A pre-production environment for testing by QA or stakeholders.
- Production (Prod): The live application used by your end-users.
Each environment helps isolate changes and prevent issues in the live app.
Supabase & Your Environments
For effective environment management, it's best practice to have separate Supabase projects for each major environment.
This means you'd have:
- One Supabase project for your development database, auth, storage.
- Another Supabase project for staging.
- A final, distinct Supabase project for production.
This isolation prevents accidental data loss or breaking changes from affecting your live application.
Managing Configuration
Each environment often requires different configurations, such as database connection strings, API keys, or external service URLs.
These sensitive details should never be hardcoded directly into your application's source code.
Instead, we use environment variables. These variables are loaded at runtime and provide the necessary configuration specific to the environment your application is running in.
Local Dev Setup with .env
During local development, you'll often use a .env file to manage your environment variables. This file stores key-value pairs specific to your local setup.
Tools like the Supabase client libraries can automatically load these variables, making it easy to switch between local and deployed environments.
Remember to add .env to your .gitignore to prevent accidentally committing sensitive information!
SUPABASE_URL="http://localhost:54321"
SUPABASE_ANON_KEY="YOUR_LOCAL_ANON_KEY"
DATABASE_URL="postgresql://postgres:password@localhost:54322/db"Introduction to CI/CD
CI/CD stands for Continuous Integration and Continuous Deployment (or Delivery). It's a set of practices that automate the building, testing, and deployment of software.
For Supabase, CI/CD helps you:
- Automatically apply database schema changes.
- Deploy Edge Functions.
- Ensure consistent deployments across environments.
This automation reduces manual errors and speeds up your development cycle.
Database Migrations
As your application evolves, your database schema will change. Database migrations are version-controlled scripts that track and apply these changes.
The Supabase CLI provides powerful tools for managing migrations:
supabase migration new <name>: Creates a new migration file.supabase db diff: Generates a migration script by comparing your local schema to your Supabase project.supabase db push: Applies local migrations to your Supabase project.
These commands are essential for safely evolving your database schema.
# Create a new migration file
supabase migration new create_users_table
# Generate migration from local changes
supabase db diff -f new_feature_migration
# Apply all pending migrations
supabase db pushCI/CD Workflow Overview
A typical CI/CD pipeline for a Supabase project might involve these steps:
- Build: Compile your application code (e.g., client-side app, Edge Functions).
- Test: Run unit and integration tests against a development or staging Supabase project.
- Deploy Schema: Apply pending database migrations to the target Supabase project.
- Deploy Functions: Deploy updated Supabase Edge Functions.
- Deploy Application: Deploy your client-side application (e.g., to Vercel, Netlify).
Each step ensures your changes are validated before reaching production.
Automating Deployments
You can use CI/CD platforms like GitHub Actions, GitLab CI, or CircleCI to automate these steps. For Supabase, a common task is to automate database migrations.
Here's a conceptual snippet of a GitHub Actions step that could apply migrations to a Supabase project. It uses the Supabase CLI and environment variables for authentication.
# This is a conceptual snippet for a CI/CD pipeline.
# It assumes SUPABASE_ACCESS_TOKEN and SUPABASE_PROJECT_REF
# are set as secrets in your CI/CD environment.
- name: Apply Supabase Migrations
run: |
# Install Supabase CLI
npm i -g supabase
# Link to your Supabase project (e.g., staging)
supabase link --project-ref ${{ secrets.SUPABASE_PROJECT_REF_STAGING }}
# Apply migrations
supabase db push
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}Quick Check
Which of the following are good practices when managing Supabase projects across different environments?
Recap: Secure & Streamlined
In this lesson, we explored how to effectively manage different environments (development, staging, production) for your Supabase projects. We also introduced the power of CI/CD.
- Separate Projects: Essential for isolating environments.
- Environment Variables: Securely manage configuration.
- Supabase CLI Migrations: Automate database schema changes.
- CI/CD: Streamline deployments and reduce errors.
By adopting these practices, you can build more robust, secure, and scalable applications with Supabase.
자주 묻는 질문
“환경 관리 및 CI/CD” 강의는 무료인가요?
네 — “환경 관리 및 CI/CD” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Supabase Backend as a Service 강의 전체를 잠금 해제할 수 있습니다. Supabase Backend as a Service 강의에는 총 4개의 강의가 포함되어 있습니다.
“환경 관리 및 CI/CD”에서 뭘 배우나요?
개발, 스테이징, 운영 환경을 관리하고 수파베이스를 지속적 통합 및 지속적 배포 파이프라인에 통합하는 방법을 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 Supabase Backend as a Service을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Supabase Backend as a Service을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Supabase Backend as a Service은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“환경 관리 및 CI/CD” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Supabase Backend as a Service 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Supabase Backend as a Service 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 환경 관리 및 CI/CD
- 백업, 복원 및 재해 복구
- 보안 감사 및 모범 사례
- 모니터링, 로깅 및 관측 가능성