Skip to content
87 changes: 87 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Deploy to Staging

on:
push:
branches:
- dev

jobs:
Deploy:
runs-on: ubuntu-latest

permissions:
deployments: write

steps:
- name: Github Repository 파일 불러오기
uses: actions/checkout@v4

- name: JDK v21 설치
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- name: application-dev.yml 파일 만들기
run: echo '${{ secrets.APPLICATION_DEV_PROPERTIES }}' > ./src/main/resources/application.yml

- name: application-test.yml 파일 만들기
run: echo '${{ secrets.APPLICATION_TEST_PROPERTIES }}' > ./src/main/resources/application-test.yml

- name: credentials.json 파일 만들기
run: echo '${{ secrets.CREDENTIAL_JSON }}' > ./src/main/resources/credentials.json

- name: log4j2.xml 파일 만들기
run: echo '${{ secrets.LOG4J2_XML }}' > ./src/main/resources/log4j2.xml

- name: 테스트 및 빌드하기
run: ./gradlew clean build

- name: Docker hub 로그인
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

- name: build and release to DockerHub
env:
NAME: ${{ secrets.DOCKERHUB_USERNAME }}
REPO: attraction-api-server
run: |
docker build -t $REPO .
docker tag $REPO:latest $NAME/$REPO:latest
docker push $NAME/$REPO:latest

- name: 배포 작업 생성
uses: chrnorm/deployment-action@v2
id: deployment
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment-url: https://attraction.run
environment: dev
ref: ${{ github.ref }}

- name: SSH로 EC2에 접속하기
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEV_EC2_HOST }}
username: ${{ secrets.DEV_EC2_USERNAME }}
key: ${{ secrets.DEV_EC2_PRIVATE_KEY }}
script_stop: true
script: |
cd /home/ec2-user/app
wget -O docker-compose.yml https://raw.githubusercontent.com/Atractorrr/Attraction-Server/dev/docker-compose.yml
export DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
# docker-compose 명령 실행
docker-compose down || true
docker-compose pull
docker-compose up -d

- name: 슬랙 알림
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
if: always()
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
redis-server:
image: redis:latest
container_name: redis-server
ports:
- "6379:6379"
networks:
- app-network

attraction-api-server:
image: ${DOCKERHUB_USERNAME}/attraction-api-server:latest
container_name: attraction-api-server
ports:
- "8080:8080"
environment:
- TZ=Asia/Seoul
volumes:
- /home/ec2-user/workspace/logs:/logs
depends_on:
- redis-server
networks:
- app-network

networks:
app-network:
driver: bridge
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ public record NewsletterDTO(
Long id,
String name,
Category category,
String thumbnailUrl
String thumbnailUrl,
String homepageUrl,
String prevArticleListUrl
) {
@QueryProjection
public NewsletterDTO(Newsletter newsletter) {
this(
newsletter.getId(),
newsletter.getName(),
newsletter.getCategory(),
newsletter.getThumbnailUrl()
newsletter.getThumbnailUrl(),
newsletter.getHomepageUrl(),
newsletter.getPrevArticleListUrl()
);
}

Expand All @@ -26,7 +30,9 @@ public static NewsletterDTO from(Newsletter newsletter) {
newsletter.getId(),
newsletter.getName(),
newsletter.getCategory(),
newsletter.getThumbnailUrl()
newsletter.getThumbnailUrl(),
newsletter.getHomepageUrl(),
newsletter.getPrevArticleListUrl()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long>, Article
@Query("""
SELECT DISTINCT new run.attraction.api.v1.home.service.dto.search.ArticleSearchDto(
a.id, a.title, a.thumbnailUrl, a.contentSummary, a.readingTime, a.receivedAt,
new run.attraction.api.v1.archive.dto.NewsletterDTO(n.id, n.name, n.category, n.thumbnailUrl)
new run.attraction.api.v1.archive.dto.NewsletterDTO(n.id, n.name, n.category, n.thumbnailUrl, n.mainLink, n.prevArticleListUrl)
)
FROM Article a JOIN Newsletter n ON a.newsletterEmail = n.email
WHERE (a.title LIKE %:search%)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class Newsletter extends AuditableEntity {
@Column(nullable = false)
private String subscribeLink;

@Column
private String prevArticleListUrl;

@Column(nullable = false)
private String thumbnailUrl;

Expand All @@ -71,4 +74,8 @@ public class Newsletter extends AuditableEntity {
@Default
@Column(nullable = false, columnDefinition = "BOOLEAN DEFAULT FALSE")
private boolean isDeleted = false;

public String getHomepageUrl() {
return this.mainLink;
}
}
1 change: 1 addition & 0 deletions src/test/resources/sql/data-h2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE IF NOT EXISTS newsletter
nickname VARCHAR(255),
subscribe_link VARCHAR(255),
thumbnail_url VARCHAR(255),
prev_article_list_url VARCHAR(255),
upload_days VARCHAR(255),
has_confirmation_email BOOLEAN,
is_auto_subscribe_enabled BOOLEAN,
Expand Down