heroku 도전 2차 시기

min·2022년 7월 3일
0

우선 spring boot 하위에 react 프로젝트를 집어 넣은 형태로 도전
추후에 서버 두개 나눠서 관리하는 방법을 다시 알아보자
참고 url: https://sundries-in-myidea.tistory.com/112

1차 시기에서는 빌드는 성공했지만 올리는 과정에서 spring 서버는 올라가고 react 서버는 올라가지 않은 상태인 것 같은 찝찝한 로그를 남기며 반쪽짜리 성공을 맛봤다..

관련 로그 일부..

2022-07-01T13:17:03.445904+00:00 app[web.1]: ... 16 more
2022-07-01T13:17:03.586908+00:00 heroku[web.1]: Process exited with status 1
2022-07-01T13:17:03.676791+00:00 heroku[web.1]: State changed from starting to crashed
2022-07-03T03:04:21.903423+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" hos

오늘은 2차 도전을 작성해본다..
이걸 보고
https://hanaweb.tistory.com/35
이번에는 따로 따로 build 설정을 해보는 것이 아니라 gradle에 react 빌드 설정을 넣고 동시에 돌리면 되지 않을까? 라는 생각이 들었다.

근데 ㅋㅋ 일단
fronted/config/paths.js 여기에 뭔가 설정을 해주라는데 우리 리액트 프로젝트에는 그런 파일이 없어서 (??) 상태가 되었다. 아무리봐도 뭔가 빌드 path를 더 지정해주는 느낌인데 물음표다...

       > Task :nodeSetup SKIPPED
       > Task :npmSetup SKIPPED
       > Task :appNpmInstall FAILED
       
       FAILURE: Build failed with an exception.
       
       * What went wrong:
       Execution failed for task ':appNpmInstall'.
       > A problem occurred starting process 'command 'npm''

이번에는 빌드 실패
뭔가 아무리 봐도 npm 관련 부분에서 실패...
nodeSetup이 과연 스킵해도 되는 부분일까...? 누가봐도 set up인데..

뭔가 node, npm이 제대로 설치 안되었다는 느낌이 강했다.
느낌 빌드.. build.gradle만 잘 고치면 될거 같은 강렬한 느낌..

우선 gradle build를 통해서 react를 빌드시키려면 node.js가 필요할거 같으니까 heroku buildpack에 node.js를 추가해봤다.

근데 일단 원래 intellij에서 빌드가 성공된다고 생각했었으나 buildJar를 선택해서 빌드를 돌렸으므로 spring만 ^-^ 잘 성공되고 있었던것.. build를 돌리니까 똑같은 로그가 나서 로컬에서 우선 테스트를 목표로..

plugins {
	id 'org.springframework.boot' version '2.6.3'
	id 'io.spring.dependency-management' version '1.0.11.RELEASE'
	id 'java'
	id 'com.github.node-gradle.node' version '3.4.0'
}

apply plugin: 'com.github.node-gradle.node'

group = 'com.studygram'
version = '0.0.1-SNAPSHOT'
targetCompatibility = '1.8'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
	implementation 'junit:junit:4.12'
	implementation 'org.projectlombok:lombok:1.18.20'
	runtimeOnly 'mysql:mysql-connector-java:8.0.25'
	testImplementation 'org.springframework.boot:spring-boot-starter-test:2.6.3'
	// Security & OAuth2 dependencies
	implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	implementation 'org.springframework.boot:spring-boot-starter-validation'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-log4j2'
	implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
	implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.2'
	runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
	runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'
	compileOnly 'org.projectlombok:lombok'

	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.security:spring-security-test'
	testImplementation 'io.rest-assured:rest-assured:3.0.3'

	testImplementation('org.springframework.boot:spring-boot-starter-oauth2-client')
//	implementation "com.github.node-gradle:gradle-node-plugin:3.4.0"
}

configurations {
	all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
	all*.exclude group: 'org.springframework.boot', module: 'logback-classic'
}

test {
	useJUnitPlatform()
}


def webappDir = "$projectDir/frontend"

node {
	version = '16.14.2'
	download=true
	workDir = file("${project.projectDir}/frontend/build/nodejs")
	npmWorkDir=file("${project.projectDir}/frontend/build/npm")
}

task appNpmInstall(type: NpmTask) {
	workingDir = file("${project.projectDir}/frontend")
	args = ["install"]
}

task appNpmBuild(type: NpmTask) {
	workingDir = file("${project.projectDir}/frontend")
	args = ["build"]
}

// 빌드된 결과 resources로 이동
task copyWebApp(type: Copy) {
	from "frontend/build"
	into "build/resources/main/static/."
}

task runReactServer(type: NpmTask) {
	workingDir = file("${project.projectDir}/frontend")
	args = ['start']
}

bootJar {
	destinationDirectory = file("./target")
}

appNpmBuild.dependsOn(appNpmInstall)
copyWebApp.dependsOn(appNpmBuild)
compileJava.dependsOn(copyWebApp)

여기까지 오는데도 많은... 시행착오가 있었다.
1. 우선 gradle이 버전이 오르고 하면서 계속 참고하고 있던 2020년 블로그들이랑 최신 버전이 차이가 있는 듯 하다
2. com.github.node-gradle.node 얘가 차이가 가장 큰거 같고
3. 내가 경로를.. 잘 못 지정한다..^-^ 까지..

node 다운 받고
node install, build 이후에 서버 띄우는 과정까지 더한 build.gradle인데 우선 node 다운 받고, build 실행하는 경로가 조금 이상한거 같아서 다시 도전...

기존에 skipped 되던 nodeSetup은 node를 다운 받는 저 과정에서 해결되는 것 같고 실제 node가 16버전으로 다운 되는 것도 확인했다.. 일단 지금 이상한 점은 build 명령어 실행 위치가 이상하다..
근데 사실 이 과정이 필요한걸까..? 배포마다..? 여튼.. 일단.. 고..


task appNpmBuild(type: NpmTask) {
	workingDir = file("${project.projectDir}/frontend")
	args = ["build"]
}

"buid"부분으로 "run", "build"로 변경하니까 build가 진행됬다.
그리고 npm 관련 에러로 변경됨..


약속 시간 6분전..

..
로컬에서는 성공했는데..
헤로쿠에서는.... 실패..

remote:        Daemon will be stopped at the end of the build
remote:
remote:        FAILURE: Build failed with an exception.
remote:
remote:        * What went wrong:
remote:        Task 'stage' not found in root project 'backend'.
remote:
remote:        * Try:
remote:        > Run gradlew tasks to get a list of available tasks.
remote:        > Run with --stacktrace option to get the stack trace.
remote:        > Run with --info or --debug option to get more log output.
remote:        > Run with --scan to get full insights.
remote:
remote:        * Get more help at https://help.gradle.org
remote:
remote:        BUILD FAILED in 9s
remote:
remote:  !     ERROR: Failed to run Gradle!
remote:        It looks like your project does not contain a 'stage' task, which Heroku needs in order
remote:        to build your app. Our Dev Center article on preparing a Gradle application for Heroku
remote:        describes how to create this task:

이건 또 처음 보네..
일단 약속 시간이 다와서 스슥..

profile
발등에 불이 따뜻하다..

2개의 댓글