CI 를 위한 데이터베이스 설정

hyuckhoon.ko·2021년 1월 5일
0

What I learned in first year

목록 보기
41/146

1. terraform plan

아래 명령어를 입력하면

postgres 데이터베이스의 비밀번호를 입력하라는 창이 나온다.

docker-compose -f deploy/docker-compose.yml run --rm terraform plan


위와 같은 변수 입력창이 나오는 이유는

variables.tf에 데이터베이스의 username과 password 관련 description을 입력했기 때문이다.



2. sample.tfvars 생성

최상위 경로에 위치한 deploy 디렉토리 안에
sample.tfvars 파일을 생성한다.


  • sample.tfvars
db_username = "recipeapp"
db_password = "changeme"

마찬가지로
최상위 경로에 위치한 deploy 디렉토리 안에
terraform.tfvars 파일을 생성한다.


  • terraform.tfvars
db_username = "recipeapp"
db_password = "changeme"

이제 다시 아래 명령어를 입력해보자. 무엇이 달라졌을까

docker-compose -f deploy/docker-compose.yml run --rm terraform plan

초기와 같이
username과 password 를 입력하라고 하지 않는다.



이제 코드를 CI pipeline을 통해 staging서버에 배포해보자.

3. gitlab 셋팅 변경

gitlab에 접속하여 해당하는 프로젝트를 찾자.

좌측의 settgins -> CI/CD를 클릭하자.



환경변수를 추가하자.





데이터베이스 변수관련 설정을 끝마쳤으니
staging 서버에 배포를 해보자.


merge request 하자.





4. 과제


  • database.tf
resource "aws_db_instance" "main" {
    engine              = "mysql"
    engine_version      = "5.7"
    instance_class      = "db.t2.micro"
    username            = "user"
    password            = "password"
    allocated_storage   = 5
    skip_final_snapshot = true
}

0개의 댓글