diff --git a/.ebextensions/00-makeFiles.config b/.ebextensions/00-makeFiles.config new file mode 100644 index 0000000..7cdf32c --- /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 + killall java + java -Dfile.encoding=UTF-8 -jar $JAR_PATH \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7f2a46f..4133c01 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,39 +1,69 @@ -name: dev-spring-springboot +name: beanstalk-springboot-deploy on: push: branches: - - dev # (1).브랜치 이름 - workflow_dispatch: # (2).수동 실행 + - main + workflow_dispatch: jobs: build: - runs-on: ubuntu-latest # (3).OS환경 - + runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 # (4).코드 check out + uses: actions/checkout@v3 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1.4.3 + #JDK Setting + - name: Set up JDK 11 + uses: actions/setup-java@v3 with: - java-version: 1.8 # (5).자바 설치 + java-version: '11' + distribution: 'temurin' + #Grant gradlew Permission - name: Grant execute permission for gradlew run: chmod +x ./gradlew - shell: bash # (6).권한 부여 + shell: bash + + #Create dotenv file + - name: Make env file + run: | + touch ./.env + echo "$ENV_PROPERTIES" > ./.env + env: + ENV_PROPERTIES_DEV: ${{ secrets.ENV_PROPERTIES }} - name: Build with Gradle run: ./gradlew clean build - shell: bash # (7).build 시작 + shell: bash - 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 시점의 시간확보 + utcOffset: "+09:00" - name: Show Current Time run: echo "CurrentTime=$" - shell: bash # (9).확보한 시간 보여주기 \ No newline at end of file + shell: bash + + - name: Generate deployment package + run: | + mkdir -p deploy + cp build/libs/*.jar deploy/application.jar + cp Procfile deploy/Procfile + cp -r .ebextensions 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_ACCESS_KEY_ID }} + aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + application_name: naechinso + environment_name: Naechinso-env + version_label: github-action-$ + region: ap-northeast-2 + deployment_package: deploy/deploy.zip \ No newline at end of file diff --git a/.platform/nginx/nginx.conf b/.platform/nginx/nginx.conf new file mode 100644 index 0000000..55e64ea --- /dev/null +++ b/.platform/nginx/nginx.conf @@ -0,0 +1,58 @@ +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 https://api.naechinso.com; + 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/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/src/main/java/com/tikitaka/naechinso/global/config/redis/RedisConfig.java b/src/main/java/com/tikitaka/naechinso/global/config/redis/RedisConfig.java index cbb291a..54c65a4 100644 --- a/src/main/java/com/tikitaka/naechinso/global/config/redis/RedisConfig.java +++ b/src/main/java/com/tikitaka/naechinso/global/config/redis/RedisConfig.java @@ -12,10 +12,10 @@ * @author gengminy (220812) */ @Configuration public class RedisConfig { - @Value("${REDIS_HOST}") + @Value("${spring.datasource.redis.host}") private String host; - @Value("${REDIS_PORT}") + @Value("${spring.datasource.redis.port}") private int port; @Bean diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index b70f2cd..88277d3 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,6 +6,10 @@ spring: config: activate: on-profile: dev + datasource: + redis: + host: ${REDIS_HOST} + port: ${REDIS_PORT} jpa: # local - create diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 830eb11..2bad291 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -6,6 +6,10 @@ spring: config: activate: on-profile: local + datasource: + redis: + host: localhost + port: 6379 jpa: # local - create diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 8431170..3e765b8 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -6,6 +6,10 @@ spring: config: activate: on-profile: local + datasource: + redis: + host: ${REDIS_HOST} + port: ${REDIS_PORT} jpa: # local - create