diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..5fea6ea --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @CChuYong diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ef42ee7..9bdc30f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,9 @@ name: 이미지 빌드 & 푸쉬 on: workflow_call: + outputs: + image-url: + value: ${{ jobs.build.outputs.image-url }} inputs: ecr-repository-name: required: true @@ -24,6 +27,9 @@ jobs: runs-on: [ ubuntu-latest ] name: 이미지 빌드하기 + outputs: + image-url: ${{ steps.build-image.outputs.image-url }} + permissions: id-token: write contents: read @@ -54,7 +60,9 @@ jobs: ECR_REGISTRY_PREFIX: '${{ secrets.AWS_ECR_REGISTRY_URL }}/' run: | chmod +x scripts/dockerBuild.sh && + chmod +x ./gradlew && /bin/bash scripts/dockerBuild.sh \ ${{ env.ECR_REGISTRY_PREFIX }}${{ inputs.ecr-repository-name }} \ ${{ inputs.image-tag }} \ - ${{ inputs.spring-profile }} + ${{ inputs.spring-profile }} && + echo "image-url=${{ inputs.ecr-repository-name }}:${{ inputs.image-tag }}" >> $GITHUB_OUTPUT diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 446a3d7..853dbb2 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,9 +1,32 @@ name: AWS ECS 배포 on: workflow_call: - + inputs: + ecs-service: + required: true + type: string + ecs-cluster: + required: true + type: string + ecr-task-definition: + required: true + type: string + image-url: + required: true + type: string + environment: + required: true + type: string + secrets: + AWS_ASSUME_ROLE_ARN: + required: true + AWS_ECR_REGISTRY_URL: + required: true + AWS_REGION: + required: true jobs: deploy: + environment: ${{ inputs.environment }} runs-on: [ ubuntu-latest ] name: ECS 배포하기 @@ -12,6 +35,31 @@ jobs: contents: read steps: - - name: AWS ECR 로그인하기 - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 + - name: AWS 인증정보 준비하기 + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_ARN }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: AWS 태스크 정의 파일 내려받기 + run: | + aws ecs describe-task-definition \ + --task-definition ${{ inputs.ecr-task-definition }} \ + --query taskDefinition \ + > task-definition.json + + - name: AWS 태스크 정의 파일에 이미지 버전 업데이트하기 + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: task-definition.json + container-name: api + image: "${{ secrets.AWS_ECR_REGISTRY_URL }}/${{ inputs.image-url }}" + + - name: AWS 태스크 정의 배포하고 서비스 업데이트하기 + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ inputs.ecs-service }} + cluster: ${{ inputs.ecs-cluster }} + wait-for-service-stability: true # ECS 배포후 롤링업데이트까지 성공해야 태스크가 완료됩니다. diff --git a/.github/workflows/prod.yaml b/.github/workflows/prod.yaml index 24ca9d9..09be4ad 100644 --- a/.github/workflows/prod.yaml +++ b/.github/workflows/prod.yaml @@ -1,7 +1,7 @@ name: 프로덕션 워크플로우 on: push: - branches: [ 'main' ] + #branches: [ 'main' ] paths: - 'src/**' # 어드민 API 코드가 변경된 경우 - '.github/workflows/**' # 워크플로우와 관련된 파일이 변경된 경우 @@ -11,6 +11,9 @@ on: env: ECR_REPOSITORY_NAME: nagaza-backend-prod SPRING_PROFILE: prod + ECS_SERVICE: nagaza-backend + ECS_CLUSTER: nagaza-cluster-prod + ECR_TASK_DEFINITION: nagaza-backend-prod concurrency: group: api @@ -23,6 +26,9 @@ jobs: ecr-repository-name: ${{ steps.setup-env.outputs.ecr-repository-name }} image-tag: ${{ steps.setup-env.outputs.image-tag }} spring-profile: ${{ steps.setup-env.outputs.spring-profile }} + ecs-service: ${{ env.ECS_SERVICE }} + ecs-cluster: ${{ env.ECS_CLUSTER }} + ecr-task-definition: ${{ env.ECR_TASK_DEFINITION }} steps: - name: GitHub 에서 레포 받아오기 uses: actions/checkout@v3 @@ -33,6 +39,10 @@ jobs: echo "ecr-repository-name=$ECR_REPOSITORY_NAME" >> $GITHUB_OUTPUT echo "image-tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT echo "spring-profile=$SPRING_PROFILE" >> $GITHUB_OUTPUT + echo "ecs-service=$ECS_SERVICE" >> $GITHUB_OUTPUT + echo "ecs-cluster=$ECS_CLUSTER" >> $GITHUB_OUTPUT + echo "ecr-task-definition=$ECR_TASK_DEFINITION" >> $GITHUB_OUTPUT + call-build-workflow: if: github.event_name == 'push' needs: [ prepare-variables ] @@ -49,3 +59,22 @@ jobs: AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }} AWS_ECR_REGISTRY_URL: ${{ secrets.AWS_ECR_REGISTRY_URL }} AWS_REGION: ${{ secrets.AWS_REGION }} + + call-deploy-workflow: + if: github.event_name == 'push' + needs: [ prepare-variables, call-build-workflow ] + name: AWS ECS 배포 + uses: ./.github/workflows/deploy.yaml + permissions: + id-token: write + contents: read + with: + environment: production + ecs-service: ${{ needs.prepare-variables.outputs.ecs-service }} + ecs-cluster: ${{ needs.prepare-variables.outputs.ecs-cluster }} + ecr-task-definition: ${{ needs.prepare-variables.outputs.ecr-task-definition }} + image-url: ${{ needs.call-build-workflow.outputs.image-url }} + secrets: + AWS_ASSUME_ROLE_ARN: ${{ secrets.AWS_ASSUME_ROLE_ARN }} + AWS_ECR_REGISTRY_URL: ${{ secrets.AWS_ECR_REGISTRY_URL }} + AWS_REGION: ${{ secrets.AWS_REGION }} diff --git a/build.gradle.kts b/build.gradle.kts index 113794c..0ac39de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,7 +41,7 @@ dependencies { runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5") implementation("com.github.f4b6a3:ulid-creator:5.2.0") implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") - runtimeOnly("org.springdoc:springdoc-openapi-kotlin:1.7.0") + //runtimeOnly("org.springdoc:springdoc-openapi-kotlin:1.7.0") implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt index 37147f9..6e3f7e2 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt @@ -39,7 +39,7 @@ class CafeEntity( val addressOne: String?, @Column(name = "addr_2") - val addressTwo: String? + val addressTwo: String?, ) { fun toModel() = Cafe( id = cafeId, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/MeApi.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/MeApi.kt index a7f3ab6..7e6ceb9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/MeApi.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/MeApi.kt @@ -24,7 +24,7 @@ interface MeApi { @Operation(summary = "내가 작성한 리뷰 목록 조회", description = "내가 작성한 리뷰 목록을 조회합니다.") @GetMapping("/reviews") fun getMyReviews( - @RequestUser userId: String + @RequestUser userId: String, ): List @Operation(summary = "닉네임 변경", description = "내 닉네임을 변경합니다.") diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql index a6e799c..e215986 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/migration/V1__init.sql @@ -4,9 +4,9 @@ CREATE TABLE app_info in_service BOOLEAN NOT NULL COMMENT '서비스 여부', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_At DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY app_info_pk(app_version) -) DEFAULT CHARSET=utf8mb4 - COLLATE=utf8mb4_unicode_ci COMMENT='앱정보'; + PRIMARY KEY app_info_pk (app_version) +) DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_unicode_ci COMMENT ='앱정보'; CREATE TABLE user ( @@ -43,7 +43,7 @@ CREATE TABLE cafe cafe_id CHAR(26) NOT NULL, franchise_id CHAR(26) DEFAULT NULL, cafe_name VARCHAR(128) NOT NULL, - description TEXT NOT NULL DEFAULT '', + description TEXT NOT NULL, address VARCHAR(255), web_url VARCHAR(255), phone_number VARCHAR(36), @@ -64,7 +64,7 @@ CREATE TABLE cafe_room timeout INT NOT NULL, recommend_user INT NOT NULL, room_img_url VARCHAR(128), - description TEXT NOT NULL DEFAULT '', + description TEXT NOT NULL, PRIMARY KEY (room_id), FOREIGN KEY cafe_room_fk1 (cafe_id) REFERENCES cafe (cafe_id) ON DELETE CASCADE ) DEFAULT CHARSET = utf8mb4 @@ -121,6 +121,7 @@ CREATE TABLE cafe_room_review_det_opt ) DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci comment '방탈출카페방리뷰디테일선택'; -# -MOCK DML -INSERT INTO user (user_id, nickname, profile_img_url) VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png'); +#MOCK DML +INSERT INTO user (user_id, nickname, profile_img_url) +VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', + 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png');