diff --git a/.ebextensions_dev/00-makeFiles.config b/.ebextensions_dev/00-makeFiles.config new file mode 100644 index 0000000..741411b --- /dev/null +++ b/.ebextensions_dev/00-makeFiles.config @@ -0,0 +1,12 @@ +files: + "/sbin/appstart": + mode: "000755" + owner: webapp + group: webapp + content: | + #!/usr/bin/env bash + JAR_PATH=/var/app/current/application.jar + + # run app + killall java + java -Dfile.encoding=UTF-8 -Dspring.profiles.active=dev -jar $JAR_PATH \ No newline at end of file diff --git a/.ebextensions_dev/01-set-timezone.config b/.ebextensions_dev/01-set-timezone.config new file mode 100644 index 0000000..f137cd5 --- /dev/null +++ b/.ebextensions_dev/01-set-timezone.config @@ -0,0 +1,3 @@ +commands: +set_time_zone: +command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime \ No newline at end of file diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml new file mode 100644 index 0000000..a13c3a3 --- /dev/null +++ b/.github/workflows/dev_deploy.yml @@ -0,0 +1,71 @@ +name: UGG dev CI/CD + +on: + pull_request: + types: [closed] + workflow_dispatch: # (2).수동 실행도 가능하도록 + +jobs: + build: + runs-on: ubuntu-latest # (3).OS환경 + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'dev' + + steps: + - name: Checkout + uses: actions/checkout@v2 # (4).코드 check out + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 # (5).자바 설치 + distribution: 'adopt' + + - name: ENV 파일 생성 + run: | + touch .env + echo "$ENV" > .env + env: + ENV: ${{ secrets.ENV }} + + shell: bash + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + shell: bash # (6).권한 부여 + + - name: Build with Gradle + run: ./gradlew clean build -x test + shell: bash # (7).build시작 + + - name: Get current time + uses: 1466587594/get-current-time@v2 + id: current-time + with: + format: YYYY-MM-DDTHH-mm-ss + utcOffset: "+09:00"# (8).build시점의 시간확보 + + - name: Show Current Time + run: echo "CurrentTime=$" + shell: bash # (9).확보한 시간 보여주기 + + - name: Generate deployment package + run: | + mkdir -p deploy + cp build/libs/*.jar deploy/application.jar + cp Procfile deploy/Procfile + cp -r .ebextensions_dev deploy/.ebextensions + cp -r .platform deploy/.platform + cd deploy && zip -r deploy.zip . + + - name: Beanstalk Deploy + uses: einaregilsson/beanstalk-deploy@v20 + with: + aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} + aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} + application_name: UGG-dev + environment_name: UGG-dev-env + version_label: github-action-${{ steps.current-time.outputs.formattedTime }} + region: ap-northeast-1 + deployment_package: deploy/deploy.zip + wait_for_deployment: false + diff --git a/.gitignore b/.gitignore index c2065bc..c89b1c7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ build/ .settings .springBeans .sts4-cache +.env bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ diff --git a/.platform/nginx.conf b/.platform/nginx.conf new file mode 100644 index 0000000..612092e --- /dev/null +++ b/.platform/nginx.conf @@ -0,0 +1,63 @@ +user nginx; +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; +worker_processes auto; +worker_rlimit_nofile 33282; + +events { + use epoll; + worker_connections 1024; + multi_accept on; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + include conf.d/*.conf; + + map $http_upgrade $connection_upgrade { + default "upgrade"; + } + + upstream springboot { + server 127.0.0.1:8080; + keepalive 1024; + } + + server { + listen 80 default_server; + listen [::]:80 default_server; + + location / { + proxy_pass http://springboot; + # CORS 관련 헤더 추가 + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS'; + add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type'; + proxy_http_version 1.1; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Upgrade $http_upgrade; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + access_log /var/log/nginx/access.log main; + + client_header_timeout 60; + client_body_timeout 60; + keepalive_timeout 60; + gzip off; + gzip_comp_level 4; + + # Include the Elastic Beanstalk generated locations + include conf.d/elasticbeanstalk/healthd.conf; + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8c727b8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# open jdk 17 버전의 환경을 구성 +FROM openjdk:17-jdk-slim +# build가 되는 시점에 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언 +# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로 +ARG JAR_FILE=build/libs/*.jar + +# JAR_FILE을 app.jar로 복사 +COPY ${JAR_FILE} app.jar + +# 운영 및 개발에서 사용되는 환경 설정을 분리 +ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=prod", "/app.jar"] \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..58dab8d --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: appstart \ No newline at end of file diff --git a/build.gradle b/build.gradle index 464e189..6cd2187 100644 --- a/build.gradle +++ b/build.gradle @@ -40,3 +40,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +jar { + enabled = false +} \ No newline at end of file diff --git a/src/main/java/org/example/ugg/web/controller/RootController.java b/src/main/java/org/example/ugg/web/controller/RootController.java new file mode 100644 index 0000000..044be07 --- /dev/null +++ b/src/main/java/org/example/ugg/web/controller/RootController.java @@ -0,0 +1,12 @@ +package org.example.ugg.web.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RootController { + @GetMapping("/health") + public String healthCheck(){ + return "OK"; + } +}