๐Ÿ“Œ ์‚ฌ์šฉ ๊ณ„๊ธฐ 

๊นƒํ—™์— ์˜ฌ๋ฆฌ์ง€ ๋ชปํ•˜๋Š” ๊ณ„์ • ์ •๋ณด๊ฐ€ ๋‹ด๊ธด properties ๋ฅผ ์ž๋™ ๋ฐฐํฌํ•  ๋•Œ ์–ด๋–ป๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์‹ค์Šต

 

๐Ÿ“Œ ๋‚˜์˜ ์ƒํ™ฉ 

๊ธฐ๋ณธ application.properties๋Š” ๋‘๊ณ  ๋ณ„๋„์˜ application-secret.properties๋ฅผ ๋‘์–ด ๊ณต๊ฐœ๋˜์ง€ ๋ง์•„์•ผํ•˜๋Š” ์ •๋ณด๋ฅผ ๋„ฃ์–ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  application.properties์— ์•„๋ž˜์ฒ˜๋Ÿผ ๋„ฃ์–ด์„œ application-secret.properties๋ฅผ ๋Œ์–ด์˜ค๋Š” ๋ฐฉ์‹.

(์•„๋ž˜์ฒ˜๋Ÿผ ์ธ์‹ํ•ด์„œ ๊ฐ€์ ธ์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋Œ์–ด์˜ค๋Š” ํŒŒ์ผ ๋ช…์€ application-[์›ํ•˜๋Š”์ด๋ฆ„].properties ๋กœ)

spring.profiles.include=secret

 

์ด ํ˜•์‹์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ๊ธฐ๋ณธ application.properties๋Š” ๊นƒํ—™์— ์˜ฌ๋ผ๊ฐ€๊ฒŒ ๋‘๊ณ , application-secret.properties๋Š” .gitignore์— ์ถ”๊ฐ€ํ•ด ๊นƒํ—™์— ์˜ฌ๋ผ๊ฐ€์ง€ ์•Š๊ฒŒ ์„ค์ •ํ–ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  github์˜ secrets์—๋Š” application-secret์˜ ๋‚ด์šฉ์„ ๋„ฃ์„ ์˜ˆ์ •

 

 

๐Ÿ“Œ ์‹ค์Šต 

๐Ÿ“Github Secrets ์„ค์ • 

Github > Settings > Secrets and variables > Actions > New repository secret ํด๋ฆญ

 

๐Ÿ“gradle.yml ์ˆ˜์ • (๋ฉ”์ธ์ด๋˜๋Š” yml ํŒŒ์ผ)

yml ํŒŒ์ผ์—์„œ jobs > steps ๋ถ€๋ถ„์—์„œ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•˜๋Š” ๋ฐ ๋ฐ˜๋“œ์‹œ build๊ณผ์ • ์ „์—! ์ด ์ฝ”๋“œ๊ฐ€ ์žˆ์–ด์•ผํ•œ๋‹ค. 

๊นƒํ—™ ํ”„๋กœ์ ํŠธ ๋ฐฐํฌ ๊ณผ์ •์—์„œ application-secret.properties๋ฅผ ํฌํ•จ์‹œ์ผœ์ค€ ๋’ค ๋นŒ๋“œ๋ฅผ ํ•˜๊ณ  ๊ทธ jar๋ฅผ ๋ณต์‚ฌํ•ด EC2์—์„œ ์‹คํ–‰ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ. ๋นŒ๋“œ ๋’ค์— ๋“ค์–ด๊ฐ€๋ฒ„๋ฆฌ๋ฉด jarํŒŒ์ผ์—์„œ ๋น ์ ธ๋ฒ„๋ ค ์ •์ƒ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

      # ์ค‘์š” ํ‚ค ์ •๋ณด ์žˆ๋Š” properties ๋”ฐ๋กœ ๊ด€๋ฆฌ
    - name: make application-secret.properties
      run: |
        cd ./src/main/resources
        touch ./application-secret.properties                                      
        echo "${{ secrets.PROPERTIES_SECRET }}" > ./application-secret.properties
      shell: bash

 

1) name : ์ž‘์—…์˜ ์ด๋ฆ„

2) run : ์‹คํ–‰ํ•  ๋ช…๋ น์–ด ๋‚˜์—ด

cd ๊ฒฝ๋กœ : ๊ฒฝ๋กœ๋กœ ์ด๋™
touch ๊ฒฝ๋กœ์™€ ํŒŒ์ผ๋ช… : ํ•ด๋‹น ๊ฒฝ๋กœ์™€ ํŒŒ์ผ๋ช…์œผ๋กœ ํŒŒ์ผ ์ƒ์„ฑ
echo "${{ secrets.PROPERTIES_SECRET }}" > ./application-secret.properties
๋ณ€์ˆ˜๋ช…์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ’์„ ์ถœ๋ ฅํ•ด ํ˜„์žฌ์œ„์น˜ ํด๋”์— ์žˆ๋Š” application-secret.properties์— ์“ด๋‹ค

- echo : ์ถœ๋ ฅ

- ${{ secrets.PROPERTIES_SECRET }} : ์œ—๋‹จ๊ณ„์—์„œ ์šฐ๋ฆฌ๊ฐ€ ๊นƒํ—™ settings์— ์ €์žฅํ•œ ๋ณ€์ˆ˜๋ช…์„ ์ด๋Ÿฐ ํ˜•ํƒœ๋กœ ์ ์–ด์ฃผ๋ฉด ๊ทธ ๋ณ€์ˆ˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜จ๋‹ค 
- > : ์™ผ์ชฝ ๋‚ด์šฉ์„ ์˜ค๋ฅธ์ชฝ์— ์”€ (> : write and overwrite , >> : append) 

 3) shell : ์‚ฌ์šฉํ•  ์‰˜ 

 


์ด๋Ÿฌ๋ฉด ์ง€์ผœ์•ผํ•˜๋Š” ์ •๋ณด๋ฅผ ์ผ๋ฐ˜์ €๊ธด ๊นƒํ—™ํŒŒ์ผ๋กœ ์˜ฌ๋ฆฌ์ง€ ์•Š๊ณ  ๋‹ค๋ฅธ ๋ฃจํŠธ๋กœ ์ž๋™๋ฐฐํฌ์— ํฌํ•จ์‹œํ‚ฌ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค. ๊ฐ„๋‹จ! 

 

 

 

 


์‹ค์Šตํ•œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ

 

GitHub - littlezero48/CICD_githubActions: CI/CD GithubAction์„ ์—ฐ์Šต

CI/CD GithubAction์„ ์—ฐ์Šต. Contribute to littlezero48/CICD_githubActions development by creating an account on GitHub.

github.com

 

+ Recent posts