Merge pull request #35 from AnnyangService/docs/swagger #25
This file contains hidden or 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: Build and Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # 수동 실행을 위한 트리거 | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write # OIDC에 필요한 권한 | |
| contents: read # 코드 체크아웃에 필요한 권한 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_ARN }} | |
| aws-region: ap-northeast-2 | |
| - name: Get Parameters from SSM | |
| id: get-ssm-params | |
| run: | | |
| API_SERVER_URL=$(aws ssm get-parameter --name "/annyang/api-server/url" --query "Parameter.Value" --output text) | |
| echo "API_SERVER_URL=$API_SERVER_URL" >> $GITHUB_ENV | |
| # CodeDeploy 관련 파라미터 가져오기 | |
| CODEDEPLOY_APP_NAME=$(aws ssm get-parameter --name "/annyang/server-deploy/app_name" --query "Parameter.Value" --output text) | |
| CODEDEPLOY_GROUP_NAME=$(aws ssm get-parameter --name "/annyang/server-deploy/ai-server/group_name" --query "Parameter.Value" --output text) | |
| CODEDEPLOY_BUCKET=$(aws ssm get-parameter --name "/annyang/server-deploy/bucket" --query "Parameter.Value" --output text) | |
| # CodeDeploy 파라미터를 환경 변수로 저장 | |
| echo "CODEDEPLOY_APP_NAME=$CODEDEPLOY_APP_NAME" >> $GITHUB_ENV | |
| echo "CODEDEPLOY_GROUP_NAME=$CODEDEPLOY_GROUP_NAME" >> $GITHUB_ENV | |
| echo "CODEDEPLOY_BUCKET=$CODEDEPLOY_BUCKET" >> $GITHUB_ENV | |
| - name: Replace environment variables in .env.production | |
| run: | | |
| sed -i "s|\${API_SERVER_URL}|${{ env.API_SERVER_URL }}|g" .env.production | |
| sed -i "s|\${GEMINI_API_KEY}|${{ secrets.GEMINI_API_KEY }}|g" .env.production | |
| - name: Fetch files from S3 | |
| run: | | |
| mkdir -p app/diagnosis/models/step1 | |
| mkdir -p app/diagnosis/models/step2 | |
| aws s3 cp s3://${{ env.CODEDEPLOY_BUCKET }}/step1 app/diagnosis/models/step1/step1 | |
| aws s3 cp s3://${{ env.CODEDEPLOY_BUCKET }}/step2 app/diagnosis/models/step2/step2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| run: | | |
| docker build --target production -t my-app-image -f Dockerfile . | |
| - name: Save Docker image as tar | |
| run: | | |
| docker save my-app-image -o my-app-image.tar | |
| - name: Compress Docker image using gzip | |
| run: | | |
| gzip my-app-image.tar | |
| - name: Prepare Deployment Bundle | |
| run: | | |
| mkdir -p codedeploy-bundle | |
| cp my-app-image.tar.gz codedeploy-bundle/my-app-image.tar.gz | |
| cp .github/deploy/appspec.yml codedeploy-bundle/ | |
| cp -r .github/deploy/scripts codedeploy-bundle/ | |
| cd codedeploy-bundle | |
| zip -r ../deploy.zip . | |
| cd .. | |
| - name: Upload to S3 | |
| run: | | |
| aws s3 cp deploy.zip s3://${{ env.CODEDEPLOY_BUCKET }}/ai-server-deploy.zip | |
| - name: Create CodeDeploy Deployment | |
| run: | | |
| aws deploy create-deployment \ | |
| --application-name ${{ env.CODEDEPLOY_APP_NAME }} \ | |
| --deployment-group-name ${{ env.CODEDEPLOY_GROUP_NAME }} \ | |
| --s3-location bucket=${{ env.CODEDEPLOY_BUCKET }},key=ai-server-deploy.zip,bundleType=zip \ | |
| --description "Deployment from GitHub Actions workflow" | |
| - name: Clean up | |
| run: | | |
| rm -f my-app-image.tar.gz | |
| docker rmi my-app-image || true |