This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into develop
# Conflicts: # .github/workflows/deploy-dev.yml # compose-blue.yml # compose-green.yml
- Loading branch information
Showing
102 changed files
with
2,052 additions
and
575 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
name: Run Docker Compose Production | ||
|
||
on: | ||
workflow_call: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
fe-build: | ||
uses: ./.github/workflows/build-fe-prod.yml | ||
secrets: inherit | ||
|
||
be-build: | ||
uses: ./.github/workflows/build-be-prod.yml | ||
secrets: inherit | ||
|
||
deploy: | ||
runs-on: [self-hosted,prod] | ||
runs-on: [self-hosted, prod] | ||
needs: [fe-build, be-build] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: create .env | ||
run: | | ||
touch .env | ||
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env | ||
echo "SPRING_PROFILES_ACTIVE=${{ vars.SPRING_PROFILES_ACTIVE_PRODUCTION }}" >> .env | ||
echo "INFRA_PROFILE=${{ vars.INFRA_PROFILE_PRODUCTION}}" >> .env | ||
## deploy to production | ||
- name: Deploy to prod | ||
run: | | ||
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
sudo docker compose down | ||
sudo docker compose pull | ||
sudo docker compose up -d | ||
sudo docker image prune -af | ||
- uses: actions/checkout@v3 | ||
- name: create .env | ||
run: | | ||
touch .env | ||
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> .env | ||
echo "SPRING_PROFILES_ACTIVE=${{ vars.SPRING_PROFILES_ACTIVE_PRODUCTION }}" >> .env | ||
echo "INFRA_PROFILE=${{ vars.INFRA_PROFILE_PRODUCTION}}" >> .env | ||
## deploy to production | ||
- name: Deploy to prod | ||
run: | | ||
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
sudo chmod +x ./deploy.sh | ||
sudo ./deploy.sh ${{ vars.INFRA_PROFILE_PRODUCTION }} | ||
sudo docker image prune -af |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Application stage | ||
FROM amazoncorretto:17-alpine-jdk | ||
EXPOSE 8080 | ||
COPY ./build/libs/backend-0.0.1-SNAPSHOT.jar /app.jar | ||
ENTRYPOINT [ \ | ||
"java",\ | ||
"-javaagent:/javaagent/dd-java-agent.jar",\ | ||
"-jar",\ | ||
"-Duser.timezone=Asia/Seoul",\ | ||
"app.jar"\ | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Application stage | ||
FROM amazoncorretto:17-alpine-jdk | ||
EXPOSE 8080 | ||
COPY ./build/libs/backend-0.0.1-SNAPSHOT.jar /app.jar | ||
ENTRYPOINT [ \ | ||
"java",\ | ||
"-jar",\ | ||
"-Duser.timezone=Asia/Seoul",\ | ||
"app.jar"\ | ||
] |
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/org/donggle/backend/application/client/BlogClient.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package org.donggle.backend.application.client; | ||
|
||
import org.donggle.backend.application.service.request.ImageUploadRequest; | ||
import org.donggle.backend.application.service.request.PublishRequest; | ||
import org.donggle.backend.domain.blog.BlogType; | ||
import org.donggle.backend.ui.response.ImageUploadResponse; | ||
import org.donggle.backend.ui.response.PublishResponse; | ||
|
||
public interface BlogClient { | ||
|
||
PublishResponse publish(String accessToken, String content, PublishRequest publishRequest, final String titleValue); | ||
|
||
ImageUploadResponse uploadImage(String accessToken, ImageUploadRequest imageUploadRequest); | ||
|
||
BlogType getBlogType(); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/org/donggle/backend/application/client/FileDownloadClient.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.donggle.backend.application.client; | ||
|
||
import org.springframework.core.io.buffer.DataBuffer; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FileDownloadClient { | ||
Optional<byte[]> download(String url); | ||
|
||
Flux<DataBuffer> downloadAsFlux(String url); | ||
} |
2 changes: 1 addition & 1 deletion
2
...infrastructure/file/FileUploadClient.java โ .../application/client/FileUploadClient.java
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
30 changes: 0 additions & 30 deletions
30
backend/src/main/java/org/donggle/backend/application/service/blog/PublishFacadeService.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
...d/src/main/java/org/donggle/backend/application/service/publish/PublishFacadeService.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.donggle.backend.application.service.publish; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.donggle.backend.application.client.FileDownloadClient; | ||
import org.donggle.backend.application.service.request.ImageUploadRequest; | ||
import org.donggle.backend.application.service.request.PublishRequest; | ||
import org.donggle.backend.application.service.request.PublishWritingRequest; | ||
import org.donggle.backend.domain.blog.Blog; | ||
import org.donggle.backend.domain.blog.BlogClients; | ||
import org.donggle.backend.domain.blog.BlogType; | ||
import org.donggle.backend.domain.renderer.html.HtmlRenderer; | ||
import org.donggle.backend.domain.writing.BlockType; | ||
import org.donggle.backend.domain.writing.Writing; | ||
import org.donggle.backend.domain.writing.block.Block; | ||
import org.donggle.backend.domain.writing.block.Depth; | ||
import org.donggle.backend.domain.writing.block.ImageBlock; | ||
import org.donggle.backend.domain.writing.block.ImageUrl; | ||
import org.donggle.backend.domain.writing.block.NormalBlock; | ||
import org.donggle.backend.domain.writing.block.RawText; | ||
import org.donggle.backend.ui.response.ImageUploadResponse; | ||
import org.donggle.backend.ui.response.PublishResponse; | ||
import org.springframework.core.io.buffer.DataBuffer; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import reactor.core.publisher.Flux; | ||
|
||
import java.net.URLConnection; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PublishFacadeService { | ||
private final PublishService publishService; | ||
private final HtmlRenderer htmlRenderer; | ||
private final BlogClients blogClients; | ||
private final FileDownloadClient fileDownloadClient; | ||
|
||
public void publishWriting(final Long memberId, final Long writingId, final BlogType blogType, final PublishRequest publishRequest) { | ||
final PublishWritingRequest request = publishService.findPublishWriting(memberId, writingId, blogType); | ||
final Blog blog = request.blog(); | ||
final Writing writing = request.writing(); | ||
List<Block> blocks = writing.getBlocks(); | ||
|
||
if (blogType == BlogType.TISTORY) { | ||
blocks = replaceTistoryImage(blogType, blocks, request.accessToken()); | ||
} | ||
|
||
final String content = htmlRenderer.render(blocks); | ||
|
||
final PublishResponse response = blogClients.publish(blogType, publishRequest, content, request.accessToken(), writing.getTitleValue()); | ||
publishService.saveProperties(blog, writing, response); | ||
} | ||
|
||
private List<Block> replaceTistoryImage(final BlogType blogType, final List<Block> blocks, final String accessToken) { | ||
final List<Block> replacedBlocks = new ArrayList<>(); | ||
for (int i = 0; i < blocks.size(); i++) { | ||
if (blocks.get(i).getBlockType() == BlockType.IMAGE) { | ||
final ImageBlock imageBlock = (ImageBlock) blocks.get(i); | ||
final ImageUrl imageUrl = imageBlock.getImageUrl(); | ||
final Flux<DataBuffer> imageData = fileDownloadClient.downloadAsFlux(imageUrl.getImageUrl()); | ||
final MediaType mediaType = parseMediaTypeFromFileName(imageUrl.getImageUrl()); | ||
final ImageUploadRequest imageUploadRequest = new ImageUploadRequest(imageData, mediaType); | ||
final ImageUploadResponse imageUploadResponse = blogClients.uploadImage(blogType, accessToken, imageUploadRequest); | ||
final NormalBlock imageReplacer = new NormalBlock(Depth.empty(), BlockType.PARAGRAPH, RawText.from(imageUploadResponse.replacer()), List.of()); | ||
replacedBlocks.add(imageReplacer); | ||
} else { | ||
replacedBlocks.add(blocks.get(i)); | ||
} | ||
} | ||
return replacedBlocks; | ||
} | ||
|
||
private MediaType parseMediaTypeFromFileName(final String fileName) { | ||
return Optional.ofNullable(URLConnection.guessContentTypeFromName(fileName)) | ||
.map(MediaType::parseMediaType) | ||
.orElseGet(() -> MediaType.APPLICATION_OCTET_STREAM); | ||
} | ||
} |
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
Oops, something went wrong.