github repository에서 git action탭에 java with gradle workflow 생성
빌드를 할려면 application.yml이 필요한데 그곳엔 각종 secret key가 뭉쳐있다.
git secret 기능을 사용해서 각종 비밀 키나 application.yml 파일을 통째로 저장해서 불러와서 사용하기로 했다.
자 이제 gradle.yml을 만들어준다.
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: <https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle>
name: Java CI with Gradle
on:
push:
branches: [ "ci-cd-test" ] --> ci-cd-test라는 브랜치에 push 했을 때 ci 트리거 동작
permissions:
contents: read
env:
S3_BUCKET_NAME: jys3 --> 변수설정
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin' --> JDK 빌드 환경 설정
- name: Run chmod to make gradlew executable --> gradle 권한 설정
run: chmod +x ./gradlew
## create application-test.yml
- name: make application.yml
if: contains(github.ref, 'ci-cd-test') # branch가 ci-cd-test일 때
run:
echo "${{ secrets.PROPERTIES_TEST }}" > ./src/main/resources/application.yml
shell: bash --> git secret에서 가져와 yml파일 생성
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build --> 빌드
- name: Make zip file
run: zip -r ./test-cd-jar.zip . --> zip 파일로 압축
shell: bash
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_JYS }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY_JYS }} --> aws s3 연결
aws-region: ap-northeast-2
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./test-cd-jar.zip s3://$S3_BUCKET_NAME/test-cd-jar.zip
--> s3에 압축된 jar파일 전송
- name: Code Deploy -> aws codedeploy 설정
run: >
aws deploy create-deployment --application-name jys-aws-code-deploy
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name jys-aws-code-deploy-group
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=test-cd-jar.zip