♻️ allow origin pattern 변경 app-dev에서 app.dev로 변경 (#273) (#274) #34
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: CI/CD Pipeline for Dev API | |
on: | |
push: | |
branches: | |
- develop | |
paths-ignore: | |
- 'scheduler/**' | |
- '.github/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
MODULE_NAME: application | |
steps: | |
- name: Parse combined secrets | |
id: parse_secrets | |
run: | | |
echo "Extracting secrets..." | |
echo '${{ secrets.DEV_API_META_DATA }}' | jq -r 'to_entries | .[] | "echo \(.key)=\(.value) >> $GITHUB_ENV"' | bash | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ env.TOKEN_GITHUB }} | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: SPRING_PROFILES_ACTIVE=test ./gradlew :${{ env.MODULE_NAME }}:clean :${{ env.MODULE_NAME }}:copyDocument :${{ env.MODULE_NAME }}:jar :${{ env.MODULE_NAME }}:build | |
shell: bash | |
- name: Upload build artifact (JAR and Dockerfile) | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: | | |
./${{ env.MODULE_NAME }}/build/libs/*.jar | |
./${{ env.MODULE_NAME }}/Dockerfile | |
dockerize: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Parse combined secrets | |
id: parse_secrets | |
run: | | |
echo "Extracting secrets..." | |
echo '${{ secrets.DEV_API_META_DATA }}' | jq -r 'to_entries | .[] | "echo \(.key)=\(.value) >> $GITHUB_ENV"' | bash | |
- name: Download build artifact (JAR and Dockerfile) | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Log in to Amazon ECR Public | |
run: | | |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ env.ECR_REPOSITORY_URI }} | |
- name: Build Docker image | |
run: docker build --build-arg PROFILE=${{ env.ENVIRONMENT }} -t ${{ env.ECR_REPOSITORY_URI }}:latest . | |
- name: Push Docker image to Amazon ECR | |
run: docker push ${{ env.ECR_REPOSITORY_URI }}:latest | |
generate-appspec: | |
runs-on: ubuntu-latest | |
needs: dockerize | |
steps: | |
- name: Parse combined secrets | |
id: parse_secrets | |
run: | | |
echo "Extracting secrets..." | |
echo '${{ secrets.DEV_API_META_DATA }}' | jq -r 'to_entries | .[] | "echo \(.key)=\(.value) >> $GITHUB_ENV"' | bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Get the latest Task Definition ARN | |
id: task_definition | |
run: | | |
TASK_DEF_ARN=$(aws ecs describe-services \ | |
--cluster ${{ env.ECS_CLUSTER_NAME }} \ | |
--services ${{ env.ECS_SERVICE_NAME }} \ | |
--query 'services[0].taskDefinition' --output text) | |
echo "TASK_DEF_ARN=$TASK_DEF_ARN" >> $GITHUB_ENV | |
- name: Generate appspec.yaml | |
run: | | |
cat <<EOF > ./appspec.yaml | |
version: 0.0 | |
Resources: | |
- TargetService: | |
Type: AWS::ECS::Service | |
Properties: | |
TaskDefinition: "$TASK_DEF_ARN" | |
LoadBalancerInfo: | |
ContainerName: ${{ env.CONTAINER_NAME }} | |
ContainerPort: ${{ env.CONTAINER_PORT }} | |
CapacityProviderStrategy: | |
- CapacityProvider: "FARGATE_SPOT" | |
Base: 0 | |
Weight: 1 | |
EOF | |
- name: Upload appspec.yaml | |
uses: actions/upload-artifact@v3 | |
with: | |
name: appspec-artifact | |
path: ./appspec.yaml | |
deploy: | |
runs-on: ubuntu-latest | |
needs: generate-appspec | |
steps: | |
- name: Parse combined secrets | |
id: parse_secrets | |
run: | | |
echo "Extracting secrets..." | |
echo '${{ secrets.DEV_API_META_DATA }}' | jq -r 'to_entries | .[] | "echo \(.key)=\(.value) >> $GITHUB_ENV"' | bash | |
- name: Download appspec artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: appspec-artifact | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Create Codedeploy deployment | |
run: | | |
APPSPEC_CONTENT=$(cat appspec.yaml | jq -sR .) | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODEDEPLOY_APP_NAME }} \ | |
--deployment-group-name ${{ env.CODEDEPLOY_DEPLOYMENT_GROUP }} \ | |
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \ | |
--revision "{\"revisionType\":\"AppSpecContent\",\"appSpecContent\":{\"content\":$APPSPEC_CONTENT}}" |