728x90
gitignore로 DB나 AWS의 민감 정보들을 숨겨놓은 후, github actions를 활용하여 gradle build를 진행할 때 secrets를 활용해서 빌드를 성공하는 방법이다.
cloud:
aws:
s3:
bucket: ${S3_BUCKET}
credentials:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
region:
static: ${S3_REGION}
auto: false
stack:
auto: false
먼저 aws S3 관련 설정을 application.yml에 다음과 같이 넣어두었다.
application-private.yml 파일에 민감정보들을 담아두고 gitignore로 깃헙에 업로드되지 않게 하였다.
repository의 설정 탭에 가면
Secrets and variables -> Actions에서 secrets를 설정할 수 있다.
위 사진처럼 이름을 key, value에 민감 정보를 넣어둘 수 있다.
이를 gradle build에 적용하기 위해서는 workflow에 환경변수를 적용하는 step을 추가해야 한다.
ame: Java CI with Gradle
on:
push:
branches: [ "main" ]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
...
uses: microsoft/variable-substitution@v1
with:
files: {application.yml파일 위치}
env:
cloud.aws.s3.bucket: ${{ secrets.S3_BUCKET }}
cloud.aws.credentials.access-key: ${{ secrets.S3_ACCESS_KEY }}
cloud.aws.credentials.secret-key: ${{ secrets.S3_SECRET_KEY }}
cloud.aws.region.static: ${{ secrets.S3_REGION }}
...
files에 appliction.yml 파일의 위치를 루트 디렉토리부터 상대경로로 적는다.
env: 에는 적용할 변수들을 나열하면 된다.
** 이때 application.yml에 이미 해당 변수들이 추가가 되어 있어야 올바르게 값을 적용하는 것 같다.
추가하지 않으면 에러가 났다
application.yml에 임의의 값으로 해당 변수들을 초기화한 후, secrets에 저장한 값으로 이를 대체하면 빌드에 성공할 수 있다.
728x90
'GitHub' 카테고리의 다른 글
[GitHub] Pull Request로 팀원들과 코드 리뷰하기 (0) | 2022.08.31 |
---|