Skip to content

[Feat] Create env.properties 더미 #20

[Feat] Create env.properties 더미

[Feat] Create env.properties 더미 #20

Workflow file for this run

# 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://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Deploy WAS
on:
push:
branches: [ "develop" ]
env:
IMAGE_TAG: ${{ github.sha }}
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
CODE_DEPLOY_APPLICATION_NAME: ${{ secrets.CODE_DEPLOY_APPLICATION_NAME }}
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME : ${{ secrets.DEPLOYMENT_GROUP_NAME }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
# Gradlew 실행 허용
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
# JDK 17 세팅
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 환경 변수 설정
- name: Make env.properties
run: |
echo "${{ secrets.ENV }}" > ./src/main/resources/properties/env.properties
# 환경 변수 설정
- name: Make application.yml
run: |
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.yml
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle Wrapper
run: ./gradlew clean bootJar -x test
# AWS credentials
- name: AWS IAM 사용자 설정
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.IAMARN }}
aws-region: ${{ env.AWS_REGION }}
# ECR login
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
# Docker build
- name: Docker build & push
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
#code deploy용 env file 생성
- name: Create env file
run: |
echo "ECR_REGISTRY=${{ steps.login-ecr.outputs.registry }}" > scripts/env.sh
echo "ECR_REPOSITORY=${{ secrets.ECR_REPOSITORY }}" >> scripts/env.sh
echo "IMAGE_TAG=${{ github.sha }}" >> scripts/env.sh
# S3에 스크립트 업로드(code deploy)
- name: upload to s3
run: |
zip -r deploy-$IMAGE_TAG.zip ./scripts appspec.yml
aws s3 cp --region ap-northeast-2 --acl private ./deploy-$IMAGE_TAG.zip s3://$S3_BUCKET_NAME/$ECR_REPOSITORY
# Deploy
# S3에 업로드 했던 내용을 가지고 와서, code deploy 실행
- name: Deploy
run: |
aws deploy create-deployment \
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \
--s3-location bucket=$S3_BUCKET_NAME,key=$ECR_REPOSITORY,bundleType=zip