Skip to content

Commit

Permalink
Merge branch 'main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin committed Jul 19, 2024
2 parents 68743a9 + 6678b3b commit ba77360
Show file tree
Hide file tree
Showing 26 changed files with 323 additions and 88 deletions.
221 changes: 221 additions & 0 deletions .github/workflows/deploy-ecs-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
name: Deploy to Amazon ECS - v2

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "staging" ]

env:
AWS_REGION: ap-northeast-2 # AWS region 설정
ECR_REPOSITORY: gyeongdan-spring # Amazon ECR repository 이름
ECS_SERVICE: GyeongdanSpring # Amazon ECS 서비스 이름
ECS_CLUSTER: Gyeongdan # Amazon ECS 클러스터 이름
ECS_TASK_DEFINITION: tf-staging.json # Amazon ECS task definition 파일 경로
CONTAINER_NAME: Spring # 컨테이너 이름
PROGRESS_SLACK_CHANNEL: C07BRCDNBMF # Slack 채널 ID

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

steps:
- name: Post Slack Channel that Build Start
id: slack-build-start
uses: slackapi/[email protected]
with:
channel-id: ${{ env.PROGRESS_SLACK_CHANNEL }}
payload: |
{
"text": ":leaves: *Spring Spring ${{ github.ref_name }}* 배포가 시작되었습니다.",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":mega: *Gyeongdan Spring ${{ github.ref_name }}* 배포가 시작되었습니다."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "깃허브액션에서 확인하기."
},
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.PROGRESS_SLACK_CHANNEL_TOKEN }}

- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: List build directory
run: ls -R build/libs

- 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: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker build & Push Docker image to Amazon ECR
id: build-image
uses: docker/build-push-action@v5
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
with:
context: .
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}
build-args: |
SPRING_DATASOURCE_PASSWORD=${{ secrets.SPRING_DATASOURCE_PASSWORD }}
SPRING_DATASOURCE_URL=${{ secrets.SPRING_DATASOURCE_URL }}
SPRING_DATASOURCE_USERNAME=${{ secrets.SPRING_DATASOURCE_USERNAME }}
JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}
KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}
KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}
OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}
cache-from: type=gha
cache-to: type=gha,mode=min,ignore-error=true

- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}

- name: Deploy Amazon ECS task definition
id: ecs-deploy
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
wait-for-minutes: 10

- name: Verify New Task Definition is Deployed
run: |
CURRENT_TASK_DEF_ARN=$(aws ecs describe-services --cluster ${{ env.ECS_CLUSTER }} --service ${{ env.ECS_SERVICE }} --query services[0].deployments[0].taskDefinition | jq -r ".")
NEW_TASK_DEF_ARN=${{ steps.ecs-deploy.outputs.task-definition-arn }}
echo "Current task arn: $CURRENT_TASK_DEF_ARN"
echo "New task arn: $NEW_TASK_DEF_ARN"
if [ "$CURRENT_TASK_DEF_ARN" != "$NEW_TASK_DEF_ARN" ]; then
echo "Deployment failed."
exit 1
fi
- name: Post Slack Channel that Build Success
if: success()
id: slack-build-success
uses: slackapi/[email protected]
with:
channel-id: ${{ env.PROGRESS_SLACK_CHANNEL }}
payload: |
{
"text": ":white_check_mark: *Gyeongdan Spring ${{ github.ref_name }}* 배포가 성공했습니다.",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":pedro: *Gyeongdan Spring ${{ github.ref_name }}* 배포가 성공했습니다."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "깃허브액션에서 확인하기."
},
"style": "primary",
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.PROGRESS_SLACK_CHANNEL_TOKEN }}

- name: Post Slack Channel that Build Fail
if: failure()
id: slack-build-fail
uses: slackapi/[email protected]
with:
channel-id: ${{ env.PROGRESS_SLACK_CHANNEL }}
payload: |
{
"text": ":x: *Gyeongdan Spring ${{ github.ref_name }}* 배포가 실패했습니다.",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":typingcat: *Gyeongdan Spring ${{ github.ref_name }}* 배포가 실패했습니다."
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"emoji": true,
"text": "깃허브액션에서 확인하기."
},
"style": "danger",
"value": "click_me_123",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
]
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.PROGRESS_SLACK_CHANNEL_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gyeongdan.article.article.controller;
package gyeongdan.article.controller;

import gyeongdan.article.article.domain.Article;
import gyeongdan.article.article.dto.ArticleUpdateRequest;
import gyeongdan.article.article.service.ArticleService;
import gyeongdan.article.domain.Article;
import gyeongdan.article.dto.ArticleUpdateRequest;
import gyeongdan.article.service.ArticleService;
import gyeongdan.util.CommonResponse;
import gyeongdan.util.annotation.AdminAuthenticated;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package gyeongdan.article.article.controller;
package gyeongdan.article.controller;

import gyeongdan.article.article.domain.Article;
import gyeongdan.article.article.dto.ArticleAllResponse;
import gyeongdan.article.article.dto.ArticleDetailResponse;
import gyeongdan.article.article.dto.PopularArticleResponse;
import gyeongdan.article.related_documents.service.ArticleRelatedDocumentsService;
import gyeongdan.article.article.service.ArticleService;
import gyeongdan.article.domain.Article;
import gyeongdan.article.dto.ArticleAllResponse;
import gyeongdan.article.dto.ArticleDetailResponse;
import gyeongdan.article.dto.PopularArticleResponse;
import gyeongdan.article.service.ArticleService;
import gyeongdan.util.CommonResponse;
import gyeongdan.util.JwtUtil;
import jakarta.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gyeongdan.article.recommend.controller;
package gyeongdan.article.controller;

import gyeongdan.article.article.dto.ArticleAllResponse;
import gyeongdan.article.recommend.service.RecommendService;
import gyeongdan.article.dto.ArticleAllResponse;
import gyeongdan.article.service.RecommendService;
import gyeongdan.util.CommonResponse;
import gyeongdan.util.JwtUtil;
import jakarta.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gyeongdan.article.type_test.controller;
package gyeongdan.article.controller;

import gyeongdan.util.CommonResponse;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package gyeongdan.article.article.domain;
package gyeongdan.article.domain;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import gyeongdan.article.related_documents.domain.ArticleRelatedDocuments;
import gyeongdan.article.view_history.domain.ArticleViewHistory;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.hibernate.annotations.Type;

@Entity
Expand All @@ -28,24 +26,28 @@ public class Article {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;
private String comment;

@Enumerated(EnumType.STRING)
private ArticlePublisher publisher;

private String simpleTitle;
private String publisher;
private String simpleContent;
private LocalDateTime createdAt;

@Nullable
private LocalDateTime publishedAt;
private String url;

@Type(JsonBinaryType.class)
@Column(columnDefinition = "jsonb")
private Map<String, Object> phrase;

private String category;
@Nullable
private Boolean isValid;
private Long viewCount;
private String url;

@Nullable
private String imageUrl;

Expand All @@ -55,11 +57,14 @@ public class Article {
@OneToMany(mappedBy = "article", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ArticleRelatedDocuments> relatedDocuments;

@Nullable
private Boolean isValid;

// 활용 메서드들
public LocalDateTime getPublishedAt() {
return publishedAt != null ? publishedAt : createdAt;
}

// 활용 메서드들
public boolean isValid() {
if (isValid == null) {
return false;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/gyeongdan/article/domain/ArticlePublisher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gyeongdan.article.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum ArticlePublisher {
MAE_KYUNG("매일경제"),
HAN_KYUNG("한국경제"),
;

private final String name;

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package gyeongdan.article.related_documents.domain;
package gyeongdan.article.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import gyeongdan.article.article.domain.Article;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@Table(name = "article_related_documents", schema = "gyeongdan")
@Getter
Expand All @@ -16,6 +16,7 @@
@AllArgsConstructor
@RequiredArgsConstructor
public class ArticleRelatedDocuments {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gyeongdan.article.view_history.domain;
package gyeongdan.article.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import gyeongdan.article.article.domain.Article;
import gyeongdan.article.domain.Article;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Loading

0 comments on commit ba77360

Please sign in to comment.