들어가며
“이제와서 시작하는 GitHub 마스터하기” 시리즈의 열여덟 번째 시간입니다. 이번에는 GitHub Codespaces를 활용하여 어디서나 즉시 사용할 수 있는 클라우드 개발 환경을 구축하는 방법을 알아보겠습니다. Codespaces는 브라우저에서 바로 개발할 수 있는 완전한 개발 환경을 제공합니다.
1. GitHub Codespaces 개요
Codespaces란?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| GitHub Codespaces:
정의: 클라우드 기반 개발 환경
특징:
- 브라우저에서 즉시 코딩 가능
- VS Code 완전 지원
- 사전 구성된 개발 환경
- 어디서나 접근 가능
장점:
- 환경 설정 시간 절약
- 일관된 개발 환경
- 강력한 클라우드 리소스
- 팀 전체 표준화
요금제:
- Free: 60시간/월 (2-core)
- Pro: 90시간/월 (2-core)
- Team: 사용자당 요금
- Enterprise: 맞춤형
|
Codespaces 아키텍처
flowchart TB
subgraph User[사용자]
Browser[브라우저]
VSCode[VS Code]
CLI[GitHub CLI]
end
subgraph GitHub
Repo[GitHub Repository]
Config[devcontainer.json]
Secrets[Codespaces Secrets]
end
subgraph Cloud[클라우드 환경]
Container[Dev Container]
Runtime[런타임 환경]
Storage[영구 스토리지]
Prebuild[사전 빌드 이미지]
end
Browser --> Container
VSCode --> Container
CLI --> Container
Repo --> Config
Config --> Container
Secrets --> Runtime
Container --> Runtime
Runtime --> Storage
Config --> Prebuild
Prebuild --> Container
style Cloud fill:#e1f5fe
style GitHub fill:#fff3e0
style User fill:#f3e5f5
지원되는 기능
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| 개발 환경:
- 모든 프로그래밍 언어
- 터미널 액세스
- Git 통합
- 포트 포워딩
- 환경 변수
- 시크릿 관리
확장 기능:
- VS Code 확장 지원
- 커스텀 dotfiles
- 사전 빌드
- GPU 지원 (베타)
통합:
- GitHub 저장소
- Pull Request
- Issues
- Actions
|
2. Codespaces 시작하기
저장소에서 Codespace 생성
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| 방법 1: 웹 브라우저에서
1. GitHub 저장소로 이동
2. Code 버튼 클릭
3. Codespaces 탭 선택
4. "Create codespace on main" 클릭
방법 2: VS Code에서
1. VS Code 열기
2. Command Palette (Cmd/Ctrl + Shift + P)
3. "Codespaces: Create New Codespace" 선택
4. 저장소 선택
방법 3: GitHub CLI에서
```bash
# Codespace 생성
gh codespace create --repo owner/repo
# 기존 Codespace 열기
gh codespace code
# Codespace 목록 보기
gh codespace list
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
### 빠른 시작 예제
```yaml
# 새 프로젝트에서 Codespace 시작
1. 저장소 생성 또는 Fork
2. Code → Codespaces → Create codespace
3. 자동으로 VS Code 환경 로드
4. 터미널에서 바로 작업 시작
# 예제:
터미널에서:
npm install
npm run dev
포트 전달:
자동으로 localhost로 전달됨
PORTS 탭에서 확인 가능
|
3. Dev Container 설정
기본 devcontainer.json
.devcontainer/devcontainer.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
| {
"name": "My Project",
"image": "mcr.microsoft.com/devcontainers/universal:2",
// 또는 Dockerfile 사용
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "ubuntu-22.04"
}
},
// 기능 추가
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "18"
},
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
// VS Code 설정
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-python.python",
"ms-azuretools.vscode-docker",
"github.copilot"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.autoSave": "onFocusChange"
}
}
},
// 포트 전달
"forwardPorts": [3000, 8080],
"portsAttributes": {
"3000": {
"label": "Application",
"onAutoForward": "notify"
},
"8080": {
"label": "API Server",
"onAutoForward": "openBrowser"
}
},
// 시작 시 실행할 명령
"postCreateCommand": "npm install && npm run prepare",
"postStartCommand": "npm run dev",
"postAttachCommand": "echo 'Welcome to Codespaces!'",
// 환경 변수
"remoteEnv": {
"NODE_ENV": "development",
"API_ENDPOINT": "https://api.example.com"
},
// 사용자 설정
"remoteUser": "vscode",
"containerUser": "vscode",
// 호스트 요구사항
"hostRequirements": {
"cpus": 4,
"memory": "8gb",
"storage": "32gb"
}
}
|
고급 Dev Container 설정
.devcontainer/Dockerfile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| # 베이스 이미지
FROM mcr.microsoft.com/devcontainers/javascript-node:18-bullseye
# 추가 도구 설치
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
postgresql-client \
redis-tools \
vim \
tmux \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Global npm 패키지 설치
RUN npm install -g \
@nestjs/cli \
typescript \
pm2 \
nodemon
# Python 환경 설정
RUN apt-get update && apt-get install -y python3-pip \
&& pip3 install --upgrade pip \
&& pip3 install \
black \
flake8 \
pytest
# 사용자 설정
USER vscode
# Oh My Zsh 설치
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 작업 디렉토리
WORKDIR /workspace
|
다중 컨테이너 설정
.devcontainer/docker-compose.yml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| version: '3.8'
services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
volumes:
- ..:/workspace:cached
command: sleep infinity
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/myapp
- REDIS_URL=redis://cache:6379
depends_on:
- db
- cache
db:
image: postgres:15
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: myapp
cache:
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis-data:/data
volumes:
postgres-data:
redis-data:
|
.devcontainer/devcontainer.json (docker-compose용):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| {
"name": "My App with Services",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg"
]
}
},
"forwardPorts": [3000, 5432, 6379],
"postCreateCommand": "docker-compose exec app npm install",
"remoteUser": "vscode"
}
|
4. 개발 환경 커스터마이징
Dotfiles 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| # GitHub에 dotfiles 저장소 생성
# https://github.com/username/dotfiles
# install.sh
#!/bin/bash
# Zsh 설정
cp .zshrc ~
# Git 설정
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global pull.rebase false
# Vim 설정
cp .vimrc ~
# 별칭 설정
echo "alias ll='ls -la'" >> ~/.zshrc
echo "alias gs='git status'" >> ~/.zshrc
echo "alias gc='git commit'" >> ~/.zshrc
echo "alias gp='git push'" >> ~/.zshrc
# 도구 설치
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
# VS Code 테마 및 설정
code --install-extension dracula-theme.theme-dracula
code --install-extension vscode-icons-team.vscode-icons
|
Secrets 및 환경 변수
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| # Codespaces Secrets 설정
# Settings → Codespaces → Secrets
예시 Secrets:
- NPM_TOKEN
- DATABASE_PASSWORD
- API_KEY
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
# devcontainer.json에서 사용
{
"remoteEnv": {
"NPM_TOKEN": "${localEnv:NPM_TOKEN}",
"API_KEY": "${localEnv:API_KEY}"
}
}
|
Prebuilds 설정
.github/workflows/codespaces-prebuild.yml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| name: Codespaces Prebuilds
on:
push:
branches: [ main ]
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # 매일 자정
jobs:
createPrebuild:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Codespace prebuild
uses: github/codespaces-prebuild-action@v1
with:
regions: 'WestUs2,EastUs,WestEurope,SoutheastAsia'
sku_name: 'standardLinux32gb'
|
VS Code 설정 동기화
.vscode/settings.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| {
// 에디터 설정
"editor.fontSize": 14,
"editor.fontFamily": "'Fira Code', Consolas, 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.renderWhitespace": "trailing",
"editor.rulers": [80, 120],
"editor.minimap.enabled": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.suggestSelection": "first",
"editor.snippetSuggestions": "top",
// 터미널 설정
"terminal.integrated.fontSize": 14,
"terminal.integrated.shell.linux": "/bin/zsh",
"terminal.integrated.fontFamily": "'MesloLGS NF', monospace",
// 파일 탐색기
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": true,
"**/.next": true,
"**/dist": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true
},
// 언어별 설정
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
// Git 설정
"git.autofetch": true,
"git.confirmSync": false,
"git.enableSmartCommit": true,
// 확장 설정
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"prettier.semi": true,
"prettier.singleQuote": true,
"prettier.tabWidth": 2
}
|
5. 팀 협업을 위한 Codespaces
팀 표준 환경 설정
.devcontainer/team-setup.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
| {
"name": "Team Development Environment",
"image": "mcr.microsoft.com/devcontainers/universal:2",
// 팀 표준 도구
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "18",
"nodeGypDependencies": true
},
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11",
"installTools": true
},
"ghcr.io/devcontainers/features/go:1": {
"version": "1.20"
},
"ghcr.io/devcontainers/features/rust:1": {},
"ghcr.io/devcontainers/features/java:1": {
"version": "17",
"installMaven": true,
"installGradle": true
}
},
// 팀 표준 확장
"customizations": {
"vscode": {
"extensions": [
// 필수 확장
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"eamodio.gitlens",
"github.copilot",
"ms-vscode.live-share",
// 언어별 확장
"ms-python.python",
"ms-python.vscode-pylance",
"golang.go",
"rust-lang.rust-analyzer",
"vscjava.vscode-java-pack",
// 유틸리티
"streetsidesoftware.code-spell-checker",
"yzhang.markdown-all-in-one",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools"
],
"settings": {
// 팀 코드 스타일
"editor.formatOnSave": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}
}
},
// 팀 스크립트
"postCreateCommand": ".devcontainer/team-setup.sh",
// 팀 환경 변수
"remoteEnv": {
"TEAM_NAME": "${localEnv:GITHUB_REPOSITORY_OWNER}",
"ENVIRONMENT": "development"
}
}
|
팀 설정 스크립트
.devcontainer/team-setup.sh:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| #!/bin/bash
echo "Setting up team development environment..."
# 프로젝트 의존성 설치
echo "Installing project dependencies..."
if [ -f "package.json" ]; then
npm install
fi
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
fi
if [ -f "go.mod" ]; then
go mod download
fi
# 개발 데이터베이스 설정
if [ -f "docker-compose.yml" ]; then
echo "Starting development services..."
docker-compose up -d
fi
# Git hooks 설정
echo "Setting up Git hooks..."
if [ -f ".husky/pre-commit" ]; then
npm run prepare
fi
# 팀 규칙 표시
if [ -f "CONTRIBUTING.md" ]; then
echo ""
echo "===================================="
echo "Please read CONTRIBUTING.md"
echo "for team development guidelines"
echo "===================================="
echo ""
fi
echo "Team environment setup complete!"
|
6. 성능 최적화
Codespaces 머신 타입 비교
| 머신 타입 | vCPU | RAM | 스토리지 | 적합한 용도 | 시간당 비용 |
| 2-core | 2 | 4GB | 32GB | 가벼운 개발 | $0.18 |
| 4-core | 4 | 8GB | 32GB | 일반 개발 | $0.36 |
| 8-core | 8 | 16GB | 64GB | 대형 프로젝트 | $0.72 |
| 16-core | 16 | 32GB | 64GB | 엔터프라이즈 | $1.44 |
| 32-core | 32 | 64GB | 128GB | 고성능 빌드 | $2.88 |
| GPU | 4 | 16GB | 64GB | ML/AI 개발 | $4.00+ |
대용량 프로젝트를 위한 설정
.devcontainer/performance-optimized.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| {
"name": "High Performance Dev Environment",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
// 성능 최적화
"mounts": [
// node_modules를 볼륨으로 분리
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume",
// 캐시 디렉토리 분리
"source=${localWorkspaceFolderBasename}-cache,target=/home/vscode/.cache,type=volume"
],
"postCreateCommand": "sudo chown -R vscode node_modules && npm install",
// 더 높은 사양
"hostRequirements": {
"cpus": 8,
"memory": "16gb",
"storage": "64gb"
},
// 파일 감시 최적화
"customizations": {
"vscode": {
"settings": {
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/**": true,
"**/.next/**": true,
"**/dist/**": true,
"**/coverage/**": true,
"**/.cache/**": true
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/dist": true,
"**/coverage": true
},
"typescript.tsserver.maxTsServerMemory": 4096,
"files.maxMemoryForLargeFilesMB": 4096
}
}
}
}
|
Prebuild 최적화
.github/codespaces/prebuild.yml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| version: 1
prebuild:
# Prebuild 트리거
triggers:
- "push"
- "pull_request"
- "schedule"
# 빌드 단계
commands:
- name: "Install dependencies"
command: "npm ci --prefer-offline --no-audit"
- name: "Build project"
command: "npm run build"
- name: "Generate cache"
command: |
npm run lint
npm run test -- --coverage --passWithNoTests
- name: "Warm up language servers"
command: |
# TypeScript 서버 워밍업
npx typescript --version
# ESLint 캐시 생성
npx eslint --cache --cache-location .eslintcache src
# 캐시 설정
cache:
- path: "node_modules"
key: "npm-{{ checksum package-lock.json }}"
- path: ".next/cache"
key: "nextjs-{{ checksum package-lock.json }}"
- path: ".eslintcache"
key: "eslint-"
|
7. 실제 사용 시나리오
프론트엔드 개발 환경
.devcontainer/frontend-dev.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| {
"name": "Frontend Development",
"image": "mcr.microsoft.com/devcontainers/typescript-node:18",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "18",
"nodeGypDependencies": true
}
},
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss",
"dsznajder.es7-react-js-snippets",
"styled-components.vscode-styled-components",
"prisma.prisma"
],
"settings": {
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"typescript": "typescriptreact"
}
}
}
},
"forwardPorts": [3000, 3001],
"postCreateCommand": "npm install && npm run dev",
"features": {
"ghcr.io/devcontainers/features/chrome:1": {},
"ghcr.io/devcontainers/features/firefox:1": {}
}
}
|
백엔드 API 개발 환경
.devcontainer/backend-dev.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| {
"name": "Backend API Development",
"dockerComposeFile": "docker-compose.yml",
"service": "api",
"workspaceFolder": "/workspace",
"customizations": {
"vscode": {
"extensions": [
"humao.rest-client",
"rangav.vscode-thunder-client",
"42Crunch.vscode-openapi",
"mongodb.mongodb-vscode",
"mtxr.sqltools",
"ckolkman.vscode-postgres"
]
}
},
"forwardPorts": [8080, 5432, 6379, 27017],
"portsAttributes": {
"8080": {
"label": "API",
"onAutoForward": "notify",
"protocol": "https"
}
},
"postCreateCommand": "chmod +x scripts/setup.sh && ./scripts/setup.sh"
}
|
데이터 사이언스 환경
.devcontainer/datascience.json:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| {
"name": "Data Science Environment",
"image": "mcr.microsoft.com/devcontainers/anaconda:3",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.11",
"installJupyterlab": true
},
"ghcr.io/devcontainers/features/r:1": {},
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"ms-toolsai.jupyter-keymap",
"ms-toolsai.jupyter-renderers",
"ms-toolsai.vscode-jupyter-cell-tags",
"ms-toolsai.vscode-jupyter-slideshow"
]
}
},
"postCreateCommand": "pip install -r requirements.txt",
"hostRequirements": {
"cpus": 4,
"memory": "16gb",
"storage": "64gb",
"gpu": true
}
}
|
8. 문제 해결 및 팁
일반적인 문제 해결
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| Codespace가 시작되지 않을 때:
1. devcontainer.json 문법 확인
2. Dockerfile 빌드 오류 확인
3. postCreateCommand 실패 여부 확인
4. 로그 확인: View → Command Palette → "Codespaces: View Creation Log"
포트 포워딩 문제:
1. PORTS 탭에서 포트 상태 확인
2. 방화벽 설정 확인
3. portsAttributes에서 protocol 설정
4. 프라이빗/퍼블릭 설정 확인
성능 문제:
1. 더 높은 사양의 머신 타입 선택
2. 불필요한 파일 감시 제외
3. node_modules를 볼륨으로 분리
4. Prebuild 사용
확장 프로그램 문제:
1. 호환성 확인 (일부 확장은 웹에서 미지원)
2. 대체 확장 프로그램 사용
3. settings.json에서 확장 설정 확인
|
최적화 팁
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # 1. Git 설정 최적화
git config core.preloadindex true
git config core.fscache true
git config gc.auto 256
# 2. npm 캐시 최적화
npm config set cache /workspace/.npm-cache --global
npm config set prefer-offline true
# 3. 디스크 사용량 확인
df -h
du -sh /workspace/*
# 4. 프로세스 모니터링
htop
|
보안 모범 사례
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| 보안 체크리스트:
✓ Secrets를 코드에 하드코딩하지 않기
✓ Codespaces Secrets 사용
✓ 공개 포트 최소화
✓ 정기적인 이미지 업데이트
✓ 최소 권한 원칙 적용
✓ 민감한 데이터는 볼륨에서 제외
# .gitignore에 추가
.env
.env.local
*.pem
*.key
.secrets/
|
9. 고급 기능
GPU 지원 Codespaces
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| {
"name": "GPU Development",
"image": "nvidia/cuda:11.8.0-devel-ubuntu22.04",
"hostRequirements": {
"gpu": "true"
},
"features": {
"ghcr.io/devcontainers/features/nvidia-cuda:1": {
"installCudnn": true,
"cudnnVersion": "8.6"
}
},
"postCreateCommand": "nvidia-smi && python -c 'import torch; print(torch.cuda.is_available())'"
}
|
커스텀 CLI 도구
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| #!/bin/bash
# .devcontainer/codespace-cli.sh
# Codespace 정보 출력
codespace_info() {
echo "Codespace Name: $CODESPACE_NAME"
echo "Repository: $GITHUB_REPOSITORY"
echo "Branch: $(git branch --show-current)"
echo "User: $GITHUB_USER"
echo "Region: $CODESPACE_REGION"
}
# 포트 상태 확인
check_ports() {
echo "Active ports:"
netstat -tlnp 2>/dev/null | grep LISTEN
}
# 리소스 사용량
resource_usage() {
echo "CPU: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}')%"
echo "Memory: $(free -h | awk '/^Mem:/ {print $3 "/" $2}')"
echo "Disk: $(df -h /workspace | awk 'NR==2 {print $3 "/" $2}')"
}
# 별칭 등록
alias csinfo='codespace_info'
alias csports='check_ports'
alias csres='resource_usage'
|
Live Share 통합
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| {
"customizations": {
"vscode": {
"extensions": [
"ms-vsliveshare.vsliveshare"
],
"settings": {
"liveshare.authenticationProvider": "GitHub",
"liveshare.features": "stable",
"liveshare.shareExternalFiles": "false",
"liveshare.showInStatusBar": "whileCollaborating"
}
}
},
"postStartCommand": "echo 'Live Share ready for collaboration!'"
}
|
10. 비용 관리
Codespaces 활용 패턴
graph TD
A[프로젝트 시작] --> B{개발 환경 필요?}
B -->|로컬 가능| C[로컬 개발]
B -->|복잡한 설정| D[Codespaces 사용]
D --> E{프로젝트 규모}
E -->|소규모| F[2-core 머신]
E -->|중규모| G[4-8 core 머신]
E -->|대규모| H[16+ core 머신]
F --> I[Prebuild 설정]
G --> I
H --> I
I --> J{사용 패턴}
J -->|지속적| K[장기 실행]
J -->|간헐적| L[필요시만 실행]
K --> M[자동 중지 설정]
L --> N[사용 후 삭제]
M --> O[비용 최적화]
N --> O
style D fill:#bbdefb
style I fill:#c8e6c9
style O fill:#ffccbc
사용량 모니터링
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| // GitHub API를 사용한 Codespaces 사용량 확인
const { Octokit } = require('@octokit/rest');
async function getCodespacesUsage() {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
});
try {
// 현재 활성 Codespaces
const { data: codespaces } = await octokit.codespaces.listForAuthenticatedUser();
console.log(`Active Codespaces: ${codespaces.total_count}`);
codespaces.codespaces.forEach(cs => {
console.log(`- ${cs.name}`);
console.log(` Machine: ${cs.machine.display_name}`);
console.log(` Created: ${cs.created_at}`);
console.log(` State: ${cs.state}`);
});
// 사용량 정보 (조직 계정인 경우)
const { data: billing } = await octokit.billing.getGithubActionsBillingOrg({
org: 'your-org'
});
console.log(`\nBilling Information:`);
console.log(`- Used minutes: ${billing.total_minutes_used}`);
console.log(`- Paid minutes: ${billing.total_paid_minutes_used}`);
} catch (error) {
console.error('Error fetching usage:', error);
}
}
|
자동 정리 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| # .github/workflows/codespace-cleanup.yml
name: Codespace Cleanup
on:
schedule:
- cron: '0 0 * * 0' # 매주 일요일
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: List and clean old Codespaces
env:
GH_TOKEN: $
run: |
# 7일 이상 된 중지된 Codespaces 삭제
gh codespace list --json name,state,createdAt \
--jq '.[] | select(.state == "Shutdown") | select((now - (.createdAt | fromdateiso8601)) > (7 * 24 * 60 * 60)) | .name' | \
while read -r codespace; do
echo "Deleting old codespace: $codespace"
gh codespace delete -c "$codespace" --force
done
|
마무리
GitHub Codespaces는 클라우드 기반 개발의 미래를 보여주는 강력한 도구입니다.
Codespaces vs 로컬 개발 환경
| 항목 | Codespaces | 로컬 환경 |
| 초기 설정 | 즉시 사용 | 수시간 ~ 수일 |
| 팀 표준화 | 자동 | 수동 관리 필요 |
| 리소스 | 클라우드 무제한 | 로컬 하드웨어 제한 |
| 비용 | 사용한 만큼 | 초기 투자 필요 |
| 접근성 | 어디서나 | 특정 기기에서만 |
| 유지보수 | GitHub 관리 | 개인 관리 |
| 성능 | 선택 가능 | 하드웨어 의존 |
| 보안 | GitHub 관리 | 개인 책임 |
핵심 포인트:
- 즉시 사용 가능한 개발 환경
- 팀 전체의 환경 표준화
- 강력한 커스터마이징 옵션
- 어디서나 접근 가능
- 리소스 효율적 사용
로컬 개발 환경 설정에 시간을 낭비하지 말고, Codespaces로 바로 코딩을 시작하세요!
다음 편에서는 GitHub CLI를 활용한 효율적인 작업 방법에 대해 알아보겠습니다.
📚 GitHub 마스터하기 시리즈
🌱 기초편 (입문자)
- GitHub 시작하기
- Repository 기초
- Git 기본 명령어
- Branch와 Merge
- Fork와 Pull Request
💼 실전편 (중급자)
- Issues 활용법
- Projects로 프로젝트 관리
- Code Review 잘하기
- GitHub Discussions
- Team 협업 설정
- GitHub Pages
🚀 고급편 (전문가)
- GitHub Actions 입문
- Actions 고급 활용
- Webhooks와 API
- GitHub Apps 개발
- 보안 기능
- GitHub Packages
- [Codespaces] (현재 글)(/posts/github-advanced-07-codespaces/)
- GitHub CLI
- 통계와 인사이트
🏆 심화편 (전문가+)
- Git Submodules & Subtree
- Git 내부 동작 원리
- 고급 브랜치 전략과 릴리스 관리
- GitHub GraphQL API
-