Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend#105/https설정 #113

Merged
merged 20 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 63 additions & 35 deletions .github/workflows/githubAction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ name: Java CI with Gradle

on:
push:
branches: [ "develop" ]
branches: [ "develop","Backend#105/https설정" ] # develop 브랜치에 푸쉬하면 스크립트 실행
pull_request:
branches: [ "develop" ]
branches: [ "develop" ] # develop 브랜치에 풀리퀘되면 스크립트 실행

# 실제 실행될 내용들을 정의한다.
jobs:
build:

Expand All @@ -21,47 +22,74 @@ jobs:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- uses: actions/checkout@v4

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

# gradle을 통해 소스를 빌드
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test
working-directory: ./backend/shareNote

# Jar 파일을 빌드
- name: Build with Gradle 8.5
run: ./gradlew bootJar
working-directory: ./backend/shareNote

# dockerfile을 통해 이미지를 빌드하고, 이를 docker repo로 push 합니다.
# 이 때 사용되는 ${{ secrets.DOCKER_REPO }}/directors-dev 는 docker-hub에서 만든 것

- name: Docker build backend & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f ./backend/shareNote/dockerfile --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }}:backend ./backend/shareNote
docker push ${{ secrets.DOCKER_REPO }}:backend

- name: Docker build frontend & push to docker repo
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f ./frontend/dockerfile --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }}:frontend ./frontend
docker push ${{ secrets.DOCKER_REPO }}:frontend

# appleboy/ssh-action@master 액션을 사용하여 지정한 서버에 ssh로 접속하고, script를 실행합니다.
# script의 내용은 도커의 기존 프로세스들을 제거하고, docker repo로부터 방금 위에서 push한 내용을 pull 받아 실행하는 것입니다.
# 실행 시, docker-compose를 사용합니다.

- name: Deploy to server
uses: appleboy/ssh-action@master
id: deploy
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
sudo docker pull ${{ secrets.DOCKER_REPO }}:backend
sudo docker pull ${{ secrets.DOCKER_REPO }}:frontend
docker-compose up -d
docker image prune -f

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
#- name: Setup Gradle
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

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

# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
# with:
# gradle-version: '8.5'
#
# - name: Build with Gradle 8.5
# run: gradle build

dependency-submission:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0


3 changes: 3 additions & 0 deletions backend/shareNote/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ bootJar {
archiveBaseName = 'shareNote'
archiveFileName = 'shareNote.jar' // 원하는 JAR 파일의 이름으로 변경
archiveVersion = "0.0.0"
}
jar {
enabled = false // -plain 안생김, 기본 JAR 파일 생성을 비활성화
}
2 changes: 2 additions & 0 deletions backend/shareNote/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ services:





Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class WebConfig implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
// .allowedOrigins("http://localhost") // local용
.allowedOrigins("http://sharenote.shop") // 배포시 변경
.allowedMethods("GET", "POST", "PUT", "DELETE")
.allowedHeaders("Authorization", "Content-Type")
.exposedHeaders("Custom-Header")
Expand Down
3 changes: 2 additions & 1 deletion frontend/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN rm /etc/nginx/conf.d/default.conf
RUN rm -rf /etc/nginx/conf.d/*
COPY ./nginx.conf /etc/nginx/conf.d/


COPY --from=builder frontend/build /usr/share/nginx/html
EXPOSE 80
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
3 changes: 2 additions & 1 deletion frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ upstream api {

server {
listen 80;
server_name localhost;
server_name www.sharenote.shop;
#server_name localhost;
charset utf-8;

# 요청받은 uri로 연결 eg) http://127.0.0.1/login
Expand Down
1 change: 1 addition & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@fortawesome/free-regular-svg-icons": "6.5.1",
"@fortawesome/free-solid-svg-icons": "6.5.1",
"@fortawesome/react-fontawesome": "0.2.0",
"http-proxy-middleware": "^2.0.6",
"jquery": "^3.7.1",
"prosemirror-example-setup": "^1.2.2",
"prosemirror-image-plugin": "^2.9.0",
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/Component/Page/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import { keymap } from "prosemirror-keymap";


import { updateImageNode, imagePlugin } from "prosemirror-image-plugin";
import "./prosemirror_css/prosemirror_image_plugin/common.css";
import "./prosemirror_css/prosemirror_image_plugin/withResize.css";
import "./prosemirror_css/prosemirror_image_plugin/sideResize.css";
import "./prosemirror_css/prosemirror_image_plugin/withoutResize.css";
import "./prosemirror_css/ProseMirror.css";
import "./ProseMirror_css/prosemirror_image_plugin/common.css";
import "./ProseMirror_css/prosemirror_image_plugin/withResize.css";
import "./ProseMirror_css/prosemirror_image_plugin/sideResize.css";
import "./ProseMirror_css/prosemirror_image_plugin/withoutResize.css";
import "./ProseMirror_css/ProseMirror.css";

// yjs 라이브러리(동시편집)
import { WebsocketProvider } from "y-websocket";
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:8080', // 서버 URL or localhost:설정한포트번호
target: 'http://sharenote.shop:8080', // 서버 URL or localhost:설정한포트번호
changeOrigin: true,
})
);
Expand Down