null
vuild_
Nodes
Flows
Hubs
Login
MENU
GO
Notifications
Login
⌂
"Docker 실전 — 개발자를 위한 컨테이너 가이드"
Structure
concepts
•
"Docker가 필요한 이유"
dockerfile
•
"Dockerfile 모범 사례"
compose
•
"Compose 실전 스택"
cicd
•
"GitHub Actions로 Docker 자동 빌드·배포"
Flow Structure
"Compose 실전 스택"
4 / 4
Next
☆ Star
↗ Full
"GitHub Actions로 Docker 자동 빌드·배포"
#docker
#github-actions
#cicd
#devops
#자동화
@devpc
|
2026-04-27 06:24:11
|
GET /api/v1/flows/14/nodes/267?fv=1&nv=1
Context:
Flow v1
→
Node v1
0
Views
1
Calls
## CI/CD 파이프라인 개요 ``` git push (main) ↓ GitHub Actions 트리거 ↓ ① 테스트 실행 ↓ ② Docker 이미지 빌드 ↓ ③ GHCR(GitHub Container Registry)에 푸시 ↓ ④ 서버에 배포 (SSH → docker compose pull && up) ``` --- ## 완성형 워크플로우 ```yaml # .github/workflows/deploy.yml name: Build & Deploy on: push: branches: [main] pull_request: branches: [main] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run tests with Docker Compose run: | docker compose -f docker-compose.test.yml up --abort-on-container-exit docker compose -f docker-compose.test.yml down build-push: needs: test runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' permissions: contents: read packages: write steps: - uses: actions/checkout@v4 - name: Log in to GHCR uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=sha,prefix=sha- type=raw,value=latest - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} cache-from: type=gha # GitHub Actions 캐시 활용 cache-to: type=gha,mode=max deploy: needs: build-push runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - name: Deploy to server uses: appleboy/ssh-action@v1 with: host: ${{ secrets.SERVER_HOST }} username: ${{ secrets.SERVER_USER }} key: ${{ secrets.SERVER_SSH_KEY }} script: | cd /app echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin docker compose pull docker compose up -d --no-build docker image prune -f ``` --- ## Secrets 설정 GitHub 레포 → Settings → Secrets and variables → Actions: | Secret | 값 | |--------|---| | `SERVER_HOST` | 서버 IP 또는 도메인 | | `SERVER_USER` | SSH 사용자 (예: ubuntu) | | `SERVER_SSH_KEY` | SSH 개인키 (`cat ~/.ssh/id_rsa`) | `GITHUB_TOKEN`은 자동으로 제공되므로 별도 설정 불필요. --- ## 테스트용 Compose ```yaml # docker-compose.test.yml version: '3.9' services: test: build: . command: pytest -v environment: - DATABASE_URL=postgresql://test:test@testdb:5432/testdb depends_on: testdb: condition: service_healthy testdb: image: postgres:15-alpine environment: POSTGRES_USER: test POSTGRES_PASSWORD: test POSTGRES_DB: testdb healthcheck: test: ["CMD-SHELL", "pg_isready -U test"] interval: 5s retries: 5 ``` --- ## 배포 서버 초기 설정 서버에서 최초 1회: ```bash # docker-compose.yml 복사 또는 git clone git clone https://github.com/your/repo.git /app cd /app # .env.prod 생성 cp .env.example .env.prod # ... 값 채우기 # 최초 실행 docker compose --env-file .env.prod up -d ``` 이후부터는 Actions가 자동으로 `docker compose pull && up`. --- ## 이미지 태그 전략 ``` latest — main 브랜치 최신 sha-abc123 — 특정 커밋 (롤백용) v1.2.3 — 릴리즈 태그 ``` 롤백: ```bash # 이전 버전으로 롤백 docker compose down IMAGE_TAG=sha-abc123 docker compose up -d ``` --- ## 정리 1. **테스트** — Compose로 격리된 환경에서 실행 2. **빌드** — `docker/build-push-action`으로 GHCR에 푸시 3. **캐시** — `cache-from: type=gha`로 빌드 시간 단축 4. **배포** — SSH로 서버 접속 → `docker compose pull && up` 5. **롤백** — SHA 태그로 언제든 이전 버전으로 복귀 가능
"Compose 실전 스택"
Next
// COMMENTS
Newest First
ON THIS PAGE
No content selected.