문제 상황
travis.yml 파일에서
이 코드를 실행할 때 에러가 발생했다.
카카오 로그인을 위한 passport/kakao.js 에서 options.clientID가 없다는 에러...
이를 고치기 위해 해당 파일의 코드를 확인해보니 .env파일에서 value를 불러와 담고 있었다.
그렇다면 .env 파일을 인식 못하는 이유가 뭔지 생각해보니 Travis에서는 Git 기반으로 소스를 가져올 텐데, gitignore 처리된 것이 보일 수가 없었다. 이에 대해서 gitignore된 .env 파일을 Travis에서 다루기 위한 방법을 찾아보니, travis encrypt을 이용하는 것이었다.
travis encrypt는 대략적으로 credential이 담긴 파일을 암호화하고, .travis.yml에서 정의한 before_install에서 복호화해서 환경변수를 사용한다.
문제 해결
travis encrypt를 사용하려면 travis가 설치되어 있어야 한다.
travis 설치 명령어
gem install travis
위 코드를 실행하려면 ruby가 설치되어 있어야한다.. ㅠㅠㅠ
ruby설치: https://www.ruby-lang.org/en/downloads/
Download Ruby
Here you can get the latest Ruby distributions in your favorite flavor. The current stable version is 3.1.1. Please be sure to read Ruby’s License. Ways of Installing Ruby We have several tools on each major platform to install Ruby: On Linux/UNIX, you c
www.ruby-lang.org
travis를 설치하고 나서 travis -v를 입력하면 travis의 버전이 나온다.
travis 로그인
github 로그인 후 settings - Developer settings - Personal access tokens - Generate new token 으로 토큰을 발급해준다.
이렇게 토큰을 생성 한 후 해당 토큰을 이용해 로그인 한다.
travis login --pro --github-token [본인 계정 토큰]
그 후 암호화 하고자 하는 위치로 이동한 후 암호화 한다.
travis encrypt-file .env --add
★travis endpoint 설정하기
default 값이 org로 되어있기 때문에
travis endpoint를 com으로 바꿔준다.
travis endpoint --set-default --com
★ --add 옵션은 .travis.yml의 before_install에 암호화된 파일을 복호화 하는 문구가 추가된다.
reference: Travis Org에서 Com으로 변경 - coder-question-ko.com
Travis Org에서 Com으로 변경 - coder-question-ko.com
© 2021 coder-question-ko.com / | CC 4.x sa 저작권 협의 체결 Privacy Policy Contact US sitemap
coder-question-ko.com
원하는 파일을 암호화 하고 난 후 환경변수 설정에서 _iv와 _key가 생겼는지 확인한다.
.travis.yml 파일의 before_install 에 문구가 추가된걸 확인할 수 있다.
마지막으로 script에 env file 옵션을 추가한다.
script:
- docker run -e CI=true --env-file .env tjddnjs7559/nemo_test npm run dev
docker run 옵션은 공식문서 참조
docker run | Docker Documentation
docker run
docker run: The `docker run` command first `creates` a writeable container layer over the specified image, and then `starts` it using the specified command. That is, `docker run` is equivalent...
docs.docker.com
이제 gitignore된 .env파일을 사용할 수 있게 됐다.
※ 리눅스나 맥os가 아닌 windows에서 진행할때 bad encrypt 오류가 발생한다는 이슈 리포트가 있다. 아래참조
(나도 window지만 오류는 없었다..)
File decryption fails (wrong final block length) on Windows · Issue #4746 · travis-ci/travis-ci
Decrypting my file fails with bad decrypt: wrong final block length. I used travis encrypt-file file under Windows to encrypt my file without problems. Also I added the generated decryption command...
github.com
'[항해99]' 카테고리의 다른 글
배포 에러 해결 (dockerrun.aws.json수정) (0) | 2022.03.28 |
---|---|
DOCKER, TRAVIS CI, GITHUB, EB 연결 (2) - aws (EB) 연동 (0) | 2022.03.26 |
DOCKER, TRAVIS CI, GITHUB 연결 (1) (0) | 2022.03.24 |
프로젝트에 도커 도입 (0) | 2022.03.23 |
[TIL] CSRF, Same Site 쿠키 (0) | 2022.03.14 |
댓글