Skip to content

fix: Flyway baseline 설정 경로 오류 수정 #19

fix: Flyway baseline 설정 경로 오류 수정

fix: Flyway baseline 설정 경로 오류 수정 #19

name: Deploy - Auto (Staging)
on:
push:
branches: [ "develop" ]
# 연속 push로 배포 겹치는 것 방지
concurrency:
group: deploy-staging
cancel-in-progress: true
jobs:
verify:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: ci_db
MYSQL_USER: ci_user
MYSQL_PASSWORD: ci_password
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=10
env:
SPRING_PROFILES_ACTIVE: ci
TZ: Asia/Seoul
CI_DB_HOST: 127.0.0.1
CI_DB_PORT: 3306
CI_DB_NAME: ci_db
CI_DB_USER: ci_user
CI_DB_PASSWORD: ci_password
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
- run: chmod +x gradlew
- name: Wait for MySQL
run: |
for i in {1..30}; do
mysqladmin ping \
-h 127.0.0.1 \
-P 3306 \
-u root \
-proot \
--silent && echo "✅ MySQL is up" && exit 0
echo "Waiting for MySQL..."
sleep 2
done
echo "❌ MySQL not ready"
exit 1
- name: Run tests
run: |
./gradlew test --stacktrace --info \
-Duser.timezone=Asia/Seoul \
-Dspring.profiles.active=test \
-Dlogging.level.org.hibernate.SQL=DEBUG \
-Dlogging.level.org.hibernate.orm.jdbc.bind=TRACE \
-Dlogging.level.org.springframework.transaction=TRACE
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
build/reports/tests/test
build/test-results/test
build/reports/problems
retention-days: 7
build_and_deploy:
runs-on: ubuntu-latest
environment:
name: staging
needs: verify
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Make Directory
run: mkdir -p deploy
- name: Copy Jar
run: cp ./build/libs/*.jar ./deploy
- name: Make zip file
run: |
cp appspec.yml ./deploy/
cp -r scripts ./deploy/
cd deploy
zip -r ../mooi-server-${{ github.run_number }}.zip .
cd ..
- name: Configure AWS credentials (staging)
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }}
aws-region: ap-northeast-2
- name: Upload to S3 (staging)
run: |
aws s3 cp --region ap-northeast-2 ./mooi-server-${{ github.run_number }}.zip s3://${{ vars.S3_BUCKET_NAME_STAGING }}/
echo "✅ Artifact uploaded: mooi-server-${{ github.run_number }}.zip"
# 업로드 검증
- name: Verify artifact exists on S3
run: |
aws s3 ls s3://${{ vars.S3_BUCKET_NAME_STAGING }}/mooi-server-${{ github.run_number }}.zip
echo "✅ Artifact verified on S3"
- name: Create Release Info
run: |
cat > release-info.json << EOF
{
"version": "${{ github.run_number }}",
"branch": "${{ github.ref_name }}",
"commit": "${{ github.sha }}",
"commit_message": "${{ github.event.head_commit.message }}",
"artifact_key": "mooi-server-${{ github.run_number }}.zip",
"created_at": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"workflow_run_id": "${{ github.run_id }}",
"build_status": "success"
}
EOF
- name: Store Release Info (staging)
run: |
aws s3 cp --region ap-northeast-2 release-info.json s3://${{ vars.S3_BUCKET_NAME_STAGING }}/releases/release-${{ github.run_number }}.json
echo "✅ Release info stored"
- name: Deploy to Staging via CodeDeploy (auto)
id: deployment
run: |
DEPLOYMENT_ID=$(aws deploy create-deployment \
--application-name ${{ vars.APPLICATION_NAME_STAGING }} \
--deployment-group-name ${{ vars.DEPLOY_GROUP_NAME_STAGING }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ vars.S3_BUCKET_NAME_STAGING }},bundleType=zip,key=mooi-server-${{ github.run_number }}.zip \
--region ap-northeast-2 \
--description "AUTO staging deploy - Version: ${{ github.run_number }} (develop)" \
--query 'deploymentId' --output text)
echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
echo "✅ Deployment ID: $DEPLOYMENT_ID"
- name: Wait for deployment completion
run: |
DEPLOYMENT_ID="${{ steps.deployment.outputs.deployment_id }}"
echo "Waiting for deployment: $DEPLOYMENT_ID"
while true; do
STATUS=$(aws deploy get-deployment --deployment-id "$DEPLOYMENT_ID" --query 'deploymentInfo.status' --output text)
echo "Deployment status: $STATUS"
if [ "$STATUS" = "Succeeded" ]; then
echo "✅ Deployment succeeded!"
break
elif [ "$STATUS" = "Failed" ] || [ "$STATUS" = "Stopped" ]; then
echo "❌ Deployment failed: $STATUS"
echo "---- deployment detail ----"
aws deploy get-deployment --deployment-id "$DEPLOYMENT_ID" --output json || true
exit 1
fi
sleep 20
done
- name: Notify success
run: |
echo "✅ Staging auto deploy completed"
echo "Version: ${{ github.run_number }}"
echo "Commit: ${{ github.sha }}"
echo "Message: ${{ github.event.head_commit.message }}"
echo "Deployment ID: ${{ steps.deployment.outputs.deployment_id }}"