Postgres 설정 예제
이 가이드는 Postgres 의존성이 있는 프로젝트를 위한 지속적 통합(CI) 파이프라인 설정 방법을 다룹니다. Drone이 처음이라면 먼저 튜토리얼과 빌드 설정 가이드를 읽어 보세요.
출처: Drone CI Docs
본문
기본 예제
아래 예제는 Postgres 서비스 컨테이너를 실행하는 파이프라인을 보여줘요. 데이터베이스 서버는 database:5432에서 접근할 수 있으며, 호스트명은 서비스 컨테이너 이름과 일치합니다.
kind: pipeline
name: default
steps:
- name: test
image: postgres:9-alpine
commands:
- psql -U postgres -d test -h database
services:
- name: database
image: postgres:9-alpine
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test
데이터베이스 설정
공식 Postgres 이미지는 시작 시 사용되는 환경변수를 제공해서 기본 사용자명, 비밀번호, 데이터베이스 등을 생성해요. 자세한 내용은 공식 이미지 문서를 참고하세요.
services:
- name: database
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test
자주 겪는 문제
초기화
Postgres 컨테이너에 연결할 수 없다면 Postgres가 초기화를 마치고 연결을 받기 시작할 충분한 시간을 주고 있는지 확인하세요.
kind: pipeline
name: default
steps:
- name: test
image: postgres
commands:
- sleep 15
- psql -U postgres -d test -h database
잘못된 호스트명
Postgres 컨테이너에 연결할 때 127.0.0.1이나 localhost는 사용할 수 없어요. Postgres 컨테이너에 연결할 수 없다면 postgres 서비스 컨테이너 이름에 해당하는 올바른 호스트명을 사용하고 있는지 확인하세요.
잘못된 예:
steps:
- name: test
image: postgres
commands:
- sleep 15
- psql -U postgres -d test -h localhost
올바른 예:
steps:
- name: test
image: postgres
commands:
- sleep 15
- psql -U postgres -d test -h database