fix: Revise publication logic for better data handling & querying #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Server CI | |
on: | |
push: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
server-CI: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 체크아웃 | |
uses: actions/checkout@v3 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "11" | |
distribution: "corretto" | |
- name: Cache Gradle packages | |
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: Gradle 빌드 | |
run: | | |
mkdir -p src/main/resources/ | |
echo ${{ secrets.APPLICATION_PROD_YML }} | base64 -d > src/main/resources/application-prod.yml | |
chmod +x gradlew | |
./gradlew build -Pprofile=prod | |
shell: bash | |
- name: Configure AWS credentials | |
if: ${{ github.ref == 'refs/heads/main' }} | |
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: ${{ secrets.AWS_REGION }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Build and push image to Amazon ECR | |
if: ${{ github.ref == 'refs/heads/main' }} | |
env: | |
REGISTRY: 211125363878.dkr.ecr.ap-northeast-2.amazonaws.com | |
REPOSITORY: lifebookshelf-server | |
IMAGE_TAG: latest | |
run: | | |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $REGISTRY | |
cp build/libs/*.jar deploy-main/ | |
cd deploy-main | |
docker buildx build --platform linux/amd64,linux/arm64 -t $REGISTRY/$REPOSITORY:$IMAGE_TAG --push . | |
rm *.jar | |
- name: Upload build file to S3 and trigger CodeDeploy | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
mkdir -p deploy && cp -r deploy-main/* deploy/ | |
zip -r deploy.zip deploy | |
aws s3 cp deploy.zip s3://${{ secrets.AWS_S3_DEPLOY_MAIN_BUCKET_NAME }}/deploy.zip | |
DEPLOYMENT_ID=$(aws deploy create-deployment \ | |
--application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \ | |
--file-exists-behavior OVERWRITE \ | |
--s3-location bucket=${{ secrets.AWS_S3_DEPLOY_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip \ | |
--output text --query 'deploymentId') | |
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV | |
- name: Check Deployment Status and Notify | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
TIMEOUT=600 | |
INTERVAL=15 | |
ELAPSED=0 | |
while [ $ELAPSED -le $TIMEOUT ]; do | |
STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID --output text --query 'deploymentInfo.status') | |
if [[ "$STATUS" == "Succeeded" ]]; then | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "Deployment succeeded! 🚀"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
exit 0 | |
elif [[ "$STATUS" == "Failed" || "$STATUS" == "Stopped" ]]; then | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "Deployment failed. 🚨"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
exit 1 | |
fi | |
sleep $INTERVAL | |
let ELAPSED=ELAPSED+INTERVAL | |
done | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "Deployment timed out. ⏲️"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
exit 1 | |
shell: bash |