Skip to content

BackEnd - CI/CD - deploy #108

BackEnd - CI/CD - deploy

BackEnd - CI/CD - deploy #108

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: BackEnd - CI/CD - deploy
on:
push:
branches: [ "main" ]
workflow_dispatch: # 수동 실행을 위한 설정
permissions:
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v3
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
- name: Gradle 캐싱
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make application.yml
run: |
cd ./src/main
cd ./resources
touch ./application.yml
echo "$APPLICATION" > ./application.yml
env:
APPLICATION: ${{ secrets.APPLICATION }}
shell: bash
- name: Gradle 권한 부여
run: chmod +x gradlew
- name: Gradle로 빌드 실행
run: ./gradlew bootjar
- name: appspec.yml 존재 화인
run: |
if [ ! -f ./appspec.yml ]; then
echo "Error: appspec.yml file not found in the root directory"
exit 1
fi
echo "appspec.yml file found, contents:"
cat ./appspec.yml
- name: Create .env for Docker Compose
run: |
mkdir -p deploy
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" > ./deploy/.env
shell: bash
- name: zip file 생성
run: |
cp ./docker/docker-compose.blue.yml ./deploy/
cp ./docker/docker-compose.green.yml ./deploy/
cp ./docker/docker-compose.redis.yml ./deploy/
cp ./appspec.yml ./deploy/
cp ./docker/Dockerfile ./deploy/
cp ./scripts/*.sh ./deploy/
cp ./build/libs/*.jar ./deploy/
zip -r -qq -j ./spring-build.zip ./deploy
- name: AWS 연결
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: S3에 프로젝트 업로드
run: |
aws s3 cp \
--region ap-northeast-2 \
./spring-build.zip s3://backend-podostore
- name: Code Deploy 배포 요청
run: |
aws deploy create-deployment \
--application-name deploy \
--deployment-config-name CodeDeployDefault.OneAtATime \
--deployment-group-name spring-deploy-group \
--s3-location bucket=backend-podostore,bundleType=zip,key=spring-build.zip \
--ignore-application-stop-failures
- name: 배포 완료 Slack 알림
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: "#깃헙액션-배포"
SLACK_COLOR: ${{ job.status == 'success' && 'good' || 'danger' }}
SLACK_MESSAGE: |
*배포 결과:* ${{ job.status == 'success' && '✅ 성공' || '❌ 실패' }}
*프로젝트:* 포도상점 - BackEnd CI/CD - Deploy
*브랜치:* ${{ github.ref_name }}
*커밋 메시지:* ${{ github.event.head_commit.message }}
*커밋 작성자:* ${{ github.event.head_commit.author.name }}
SLACK_TITLE: "배포 결과 알림"
SLACK_USERNAME: "Notification-Bot"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()