From 1a7a17aa2347a55af86df636b48dd0426549a951 Mon Sep 17 00:00:00 2001 From: enble Date: Tue, 5 Nov 2024 18:35:48 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ci/cd=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ebextensions/00-makeFiles.config | 12 +++++ .ebextensions/01-set-timezone.config | 3 ++ .github/workflows/dev_deploy.yml | 63 ++++++++++++++++++++++ .platform/nginx.conf | 63 ++++++++++++++++++++++ Procfile | 1 + build.gradle | 78 +++++++++++++++------------- src/main/resources/application.yml | 2 +- 7 files changed, 184 insertions(+), 38 deletions(-) create mode 100644 .ebextensions/00-makeFiles.config create mode 100644 .ebextensions/01-set-timezone.config create mode 100644 .github/workflows/dev_deploy.yml create mode 100644 .platform/nginx.conf create mode 100644 Procfile diff --git a/.ebextensions/00-makeFiles.config b/.ebextensions/00-makeFiles.config new file mode 100644 index 0000000..932a122 --- /dev/null +++ b/.ebextensions/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 + killalljava + java -Dfile.encoding=UTF-8 -Dspring.profiles.active=dev -jar $JAR_PATH diff --git a/.ebextensions/01-set-timezone.config b/.ebextensions/01-set-timezone.config new file mode 100644 index 0000000..9eb3596 --- /dev/null +++ b/.ebextensions/01-set-timezone.config @@ -0,0 +1,3 @@ +commands: + set_time_zone: + command: ln -f -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml new file mode 100644 index 0000000..04be96b --- /dev/null +++ b/.github/workflows/dev_deploy.yml @@ -0,0 +1,63 @@ +name: UMC Dev CI/CD # workflow 이름 + +on: # 이벤트 설정 + pull_request: + types: [ closed ] + workflow_dispatch: # 수동 실행도 가능하도록 설정 + +jobs: + build: # job 이름 + runs-on: ubuntu-latest # OS환경 + # PR이 merge되었고, 'dev' 브랜치일 경우 수행 + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' + + steps: + - name: Checkout + uses: actions/checkout@v2 # 코드 check-out + # '.github' 디렉토리가 포함된 디렉토리의 하위 코드들 + + - name: Set up JDK 17 + uses: actions/setup-java@v4.0.0 # 자바 설치 + with: + java-version: 17 # 버전 + distribution: 'adopt' # 배포판 + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + shell: bash # gradle wrapper 권한 부여 + + - name: Build with Gradle + run: ./gradlew clean build -x test + shell: bash # gradle build + + - name: Get current time + uses: 1466587594/get-current-time@v2 # build시점의 시간 확보 + id: current-time + with: + format: YYYY-MM-DDTHH-mm-ss + utcOffset: "+09:00" # 서울 UTC 적용 + + - name: Show Current Time + run: echo "CurrentTime=$" # 확보한 시간 보여주기 + shell: bash + + - 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_GITHUB_ACTIONS_ACCESS_KEY_ID }} + aws_secret_key: ${{ secrets.AWS_GITHUB_ACTIONS_SECRET_ACCESS_KEY }} + application_name: pictalk-dev + environment_name: Pictalk-dev-env + version_label: github-action-${{ steps.current-time.outputs.formattedTime }} + region: ap-northeast-2 + deployment_package: deploy/deploy.zip + wait_for_deployment: false diff --git a/.platform/nginx.conf b/.platform/nginx.conf new file mode 100644 index 0000000..0b36bac --- /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; + } +} diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d7df372 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: appstart diff --git a/build.gradle b/build.gradle index d0c9b89..af5ac3c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,66 +1,70 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.3.4' - id 'io.spring.dependency-management' version '1.1.6' + id 'java' + id 'org.springframework.boot' version '3.3.4' + id 'io.spring.dependency-management' version '1.1.6' } group = 'com' version = '0.0.1-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' - compileOnly 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.springframework.boot:spring-boot-starter-web' + compileOnly 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' - // Security - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' - implementation 'org.springframework.security:spring-security-crypto' + // Security + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' + implementation 'org.springframework.security:spring-security-crypto' // implementation('org.springframework.security:spring-security-oauth2-client') - implementation 'org.springframework.security:spring-security-test' + implementation 'org.springframework.security:spring-security-test' - // JWT - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' + // JWT + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' - // Validation - implementation 'org.springframework.boot:spring-boot-starter-validation' + // Validation + implementation 'org.springframework.boot:spring-boot-starter-validation' - // Environment + // Environment // developmentOnly 'org.springframework.boot:spring-boot-docker-compose' - implementation 'io.github.cdimascio:dotenv-java:2.2.0' + implementation 'io.github.cdimascio:dotenv-java:2.2.0' - // Database - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - runtimeOnly 'com.mysql:mysql-connector-j' - implementation 'com.h2database:h2:2.1.214' + // Database + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + runtimeOnly 'com.mysql:mysql-connector-j' + implementation 'com.h2database:h2:2.1.214' - // Lombok - annotationProcessor 'org.projectlombok:lombok' + // Lombok + annotationProcessor 'org.projectlombok:lombok' - // Swagger - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() +} + +jar { + enabled = false } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 13ecc1c..70ac93a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -31,4 +31,4 @@ jwt: refresh: expiration: 86400000 header: Refresh - secret: ${JWT_SECURITY_KEY} \ No newline at end of file + secret: ${JWT_SECURITY_KEY}