From 7d75a1b12d9186d5392dc52e83e2f72c40db2c59 Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:37:06 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[ci/#26]:=20ci=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - baas 배포 ci 설정 (aws) --- .github/workflows/dev_deploy.yml | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/dev_deploy.yml diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml new file mode 100644 index 0000000..35151aa --- /dev/null +++ b/.github/workflows/dev_deploy.yml @@ -0,0 +1,61 @@ +name: wekids-baas 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 == 'test' + + steps: + - name: Checkout + uses: actions/checkout@v3 # (4).코드 check out + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 # (5).자바 설치 + distribution: 'adopt' + + - 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: wekdis-baas-dev + environment_name: Wekdis-baas-dev-env + version_label: github-action-${{ steps.current-time.outputs.formattedTime }} + region: ap-northeast-1 + deployment_package: deploy/deploy.zip + wait_for_deployment: false \ No newline at end of file From e059f5f283c8e93685f7a78dd2c03b6bb72d9a13 Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:37:17 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[ci/#26]:=20nginx=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .platform/nginx.conf | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .platform/nginx.conf 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 From cdf6596f156cdc0b6cdac3d7a031d1817a3f6c79 Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:37:36 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[ci/#26]:=20AWS=20EB=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .ebextensions-dev/00-makeFiles.config | 12 +++++++++ .ebextensions-dev/01-set-timezone.config | 3 +++ .ebextensions-dev/02-https-redirect.config | 30 ++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 .ebextensions-dev/00-makeFiles.config create mode 100644 .ebextensions-dev/01-set-timezone.config create mode 100644 .ebextensions-dev/02-https-redirect.config diff --git a/.ebextensions-dev/00-makeFiles.config b/.ebextensions-dev/00-makeFiles.config new file mode 100644 index 0000000..2ee43c4 --- /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 + killalljava + 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..4249da0 --- /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/.ebextensions-dev/02-https-redirect.config b/.ebextensions-dev/02-https-redirect.config new file mode 100644 index 0000000..a01ad14 --- /dev/null +++ b/.ebextensions-dev/02-https-redirect.config @@ -0,0 +1,30 @@ +Resources: + AWSEBV2LoadBalancerListener: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + DefaultActions: + - Type: redirect + RedirectConfig: + Protocol: HTTPS + Port: '443' + Host: '#{host}' + Path: '/#{path}' + Query: '#{query}' + StatusCode: HTTP_301 + LoadBalancerArn: + Ref: AWSEBV2LoadBalancer + Port: 80 + Protocol: HTTP + AWSEBV2LoadBalancerListener443: + Type: 'AWS::ElasticLoadBalancingV2::Listener' + Properties: + Certificates: + - CertificateArn: Replace with Certificate ARN + DefaultActions: + - Type: forward + TargetGroupArn: + Ref: AWSEBV2LoadBalancerTargetGroup + LoadBalancerArn: + Ref: AWSEBV2LoadBalancer + Port: 443 + Protocol: HTTPS \ No newline at end of file From 936a1fb8d29f12e67b36bf34db769d4fdb5662b6 Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:38:03 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[ci/#26]:=20AWS=20EB=20jar=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 112f894..e77119a 100644 --- a/build.gradle +++ b/build.gradle @@ -41,3 +41,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +jar { + enabled=false +} \ No newline at end of file From 4a8312e09ed87e9dec34ff1d018e5f20d3c65f2b Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:38:25 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[ci/#26]:=20AWS=20=EB=A6=AC=EB=88=85?= =?UTF-8?q?=EC=8A=A4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Procfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Procfile 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 From d6962c4ba79651119d34a75a5dc5624e76395892 Mon Sep 17 00:00:00 2001 From: Kang Hyun Woo Date: Wed, 27 Nov 2024 16:38:34 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[ci/#26]:=20health=20check=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/wekids/baas/aws/HealthController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/com/wekids/baas/aws/HealthController.java diff --git a/src/main/java/com/wekids/baas/aws/HealthController.java b/src/main/java/com/wekids/baas/aws/HealthController.java new file mode 100644 index 0000000..5e63681 --- /dev/null +++ b/src/main/java/com/wekids/baas/aws/HealthController.java @@ -0,0 +1,12 @@ +package com.wekids.baas.aws; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HealthController { + @GetMapping("/health") + public String healthCheck() { + return "I'm healthy"; + } +}