Skip to content

Commit

Permalink
Merge pull request #5 from LearnMate-Dev/feature/3-implements-deploy-…
Browse files Browse the repository at this point in the history
…settings

[Feature] Implements Deploy Settings
  • Loading branch information
L-U-Ready authored Nov 5, 2024
2 parents 838f762 + f3ef562 commit 25e791b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 3 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build and Push Docker Image with Jib

on:
push:
branches: ["main"]
permissions:
contents: read

jobs:
build-and-push-image:
runs-on: self-hosted
steps:
- name: Checkout Repository and Submodules
uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.ACTIONS_TOKEN }}

- name: Copy application.yml from submodule
run: |
mkdir -p src/main/resources
cp application-config/application-prod.yml src/main/resources/application-prod.yml
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: "21"
distribution: "temurin"

- name: Build and push Docker image
run: |
./gradlew jib -x test \
-Djib.to.tags=${{ github.sha }} \
-Djib.to.auth.username=${{ secrets.DOCKER_USERNAME }} \
-Djib.to.auth.password=${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image to EC2 server
env:
DOCKER_IMAGE: "${{ secrets.DOCKER_USERNAME }}/learnMate:${{ github.sha }}"
run: |
ssh -o "StrictHostKeyChecking=no" -i ${{ secrets.EC2_SSH_KEY }} ec2-user@${{ secrets.EC2_HOST }} "docker pull $DOCKER_IMAGE && docker run -d -p 8080:8080 $DOCKER_IMAGE"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ out/

### VS Code ###
.vscode/

### env
.env
20 changes: 20 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
id 'com.google.cloud.tools.jib' version '3.3.2'

}

group = 'LearnMate'
Expand Down Expand Up @@ -42,6 +44,8 @@ dependencies {

implementation 'mysql:mysql-connector-java:8.0.33'

implementation 'me.paulschwarz:spring-dotenv:2.5.4'

// jwt & json
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
Expand All @@ -54,6 +58,22 @@ dependencies {
implementation 'org.json:json:20230227'
}

jib {
from {
image = 'openjdk:21-jdk'
}
to {
image = "${System.getenv('DOCKER_USERNAME')}/learnMate"
tags = ['latest']
}
container {
ports = ['8080']
environment = [
'DATABASE_URL': System.getenv('DATABASE_URL')
]
}
}

tasks.named('test') {
useJUnitPlatform()
}
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
app:
env_file:
- .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void commence(HttpServletRequest request, HttpServletResponse response,

if (exception == null) {
log.info("No exception found, setting default error");
exception = ErrorStatus._JWT_UNKNOWN; // 기본 예외 상태 설정
exception = ErrorStatus._JWT_UNKNOWN_ERROR; // 기본 예외 상태 설정
}

log.info("JwtAuthenticationEntryPoint - Exception Control : " + exception);
Expand All @@ -35,7 +35,7 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
} else if (exception.equals(ErrorStatus._JWT_EXPIRED)) {
exceptionHandler(response, ErrorStatus._JWT_EXPIRED, HttpServletResponse.SC_UNAUTHORIZED);
} else {
exceptionHandler(response, ErrorStatus._JWT_UNKNOWN, HttpServletResponse.SC_UNAUTHORIZED);
exceptionHandler(response, ErrorStatus._JWT_UNKNOWN_ERROR, HttpServletResponse.SC_UNAUTHORIZED);
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/application-config/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
application:
name: The_Monitor

config:
import: optional:file:.env[.properties]
datasource:
url: ${DATABASE_URL}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}

jwt:
secret_key: ${JWT_SECRET_KEY}
access_token_expire: ${JWT_ACCESS_TOKEN_EXPIRE}
refresh_token_expire: ${JWT_REFRESH_TOKEN_EXPIRE}
10 changes: 10 additions & 0 deletions src/main/resources/application-config/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
spring:
application:
name: The_Monitor

profiles:
active: local
group:
local: "local"
dev: "dev"
prod: "prod"
1 change: 0 additions & 1 deletion src/main/resources/application.yml

This file was deleted.

0 comments on commit 25e791b

Please sign in to comment.