update ahhachul secret #260
Workflow file for this run
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 Spring Boot | |
on: | |
push: | |
branches: | |
- feature/223 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.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 ./ahachul_backend/gradlew | |
shell: bash | |
- name: Build with Gradle | |
run: cd ./ahachul_backend && SPRING_PROFILES_ACTIVE=test ./gradlew clean copyDocument jar build | |
shell: bash | |
- name: Upload build artifact (JAR and Dockerfile) | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: | | |
./ahachul_backend/build/libs/*.jar | |
./ahachul_backend/Dockerfile | |
dockerize: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- 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: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.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 ${{ secrets.ECR_REPOSITORY_URI }} | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.ECR_REPOSITORY_URI }}:latest . | |
- name: Push Docker image to Amazon ECR | |
run: docker push ${{ secrets.ECR_REPOSITORY_URI }}:latest | |
generate-appspec: | |
runs-on: ubuntu-latest | |
needs: dockerize | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
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: Get the latest Task Definition ARN | |
id: task_definition | |
run: | | |
TASK_DEF_ARN=$(aws ecs describe-services \ | |
--cluster ${{ secrets.ECS_CLUSTER_NAME }} \ | |
--services ${{ secrets.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: "api-container" | |
ContainerPort: 8080 | |
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: 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: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Create Codedeploy deployment | |
run: | | |
APPSPEC_CONTENT=$(cat appspec.yaml | jq -sR .) | |
aws deploy create-deployment \ | |
--application-name ${{ secrets.CODEDEPLOY_APP_NAME }} \ | |
--deployment-group-name ${{ secrets.CODEDEPLOY_DEPLOYMENT_GROUP }} \ | |
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \ | |
--revision "{\"revisionType\":\"AppSpecContent\",\"appSpecContent\":{\"content\":$APPSPEC_CONTENT}}" | |