[AWS] EC2에서 Gradle 빌드하기

Posted by 김성철

AWS - 아마존 EC2에서 그래들 프로젝트 컴파일 하기

https://may9noy.tistory.com/546  

Java 설치

Java 설치는 이전에 작성한 아래의 링크를 보고 진행하면됨  
  
https://github.com/kkimsungchul/study/blob/master/Cloud/%5BAWS%5D%20EC2%EC%97%90%20Java%20%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0.txt  

Git 설치

=================================================================================================================  
$ yum install git  
=================================================================================================================  

Git Clone

사용자 디렉토리에 바로 만들어도 되지만 관리하기쉽게 디렉토리를 하나 생성하고 클론을 했음  
=================================================================================================================  
$ mkdir camping  
$ cd camping  
$ git clone https://github.com/kkimsungchul/camping.git  
=================================================================================================================  

권한 설정

gradlew 파일은 바로 실행이 안됨, 권한설정을 해주어야 함  
=================================================================================================================  
$ chmod -R 755 camping/  
=================================================================================================================  

빌드

아래의 명령어로 빌드를 진행  
 -x check --parallel 옵션은 테스트를 하지 않겠다는 옵션  
=================================================================================================================  
$ ./gradlew build  -x check --parallel  
=================================================================================================================  
  
※ 윈도우의 경우 아래의 명령어로 빌드, 혹시모르니 관리자 권한으로 실행  
=================================================================================================================  
gradlew.bat build  
=================================================================================================================  
  
빌드가 완료되면 해당프로젝트의 build/libs에  camping-0.0.1-SNAPSHOT.jar 파일이 생성되어 있음  
	ex)  
		/home/ec2-user/camping/camping/build/libs  
  
※ 오류발생함, 권한문제로 하위 디렉토리까지 전부다 755룰 주면 해결됨  
chmod -R 755 camping/  
=================================================================================================================  
$ ./gradlew build  
  
	> Task :test FAILED  
  
	FAILURE: Build failed with an exception.  
  
	* What went wrong:  
	Execution failed for task ':test'.  
	> Unable to connect to the child process 'Gradle Test Executor 1'.  
	  It is likely that the child process have crashed - please find the stack trace in the build log.  
	  This exception might occur when the build machine is extremely loaded.  
	  The connection attempt hit a timeout after 120.0 seconds (last known process state: STARTED, running: true).  
  
	* Try:  
	Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.  
  
	* Get more help at https://help.gradle.org  
  
	Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.  
	Use '--warning-mode all' to show the individual deprecation warnings.  
	See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html##sec:command_line_warnings  
=================================================================================================================  

실행

=================================================================================================================  
$ cd /home/ec2-user/camping/camping/build/libs  
$ nohup java -jar camping-0.0.1-SNAPSHOT.jar &  
=================================================================================================================  
  
오류 발생 1. 권한문제  
※ 실행 안됨, 이거 권한문제였음, 권한 문제로 인해서 컴파일이 제대로 진행되지 안았었음  
=================================================================================================================  
$ cd /home/ec2-user/camping/camping/build/libs  
$ nohup java –jar camping-0.0.1-SNAPSHOT.jar &  
$ vim nohup.out  
Error: Could not find or load main class –jar  
=================================================================================================================  
  
오류 발생 2. 하이픈 문제  
아래의 명령어로 실행하면 잘됨.. 그냥 잘됨  
=================================================================================================================  
$ java -jar camping-0.0.1-SNAPSHOT.jar  
=================================================================================================================  
  
그래서 뭔가 이상해서 직접 타이핑을 해봄  
=================================================================================================================  
$ nohup java -jar camping-0.0.1-SNAPSHOT.jar &  
=================================================================================================================  
  
실행됨..  
아래를 보면 복사한 코드의 경우 - 모양이 좀 이상한것을 알수 있음  
이거 코드를 내가AWS에서 사용하고 history 에서 복사해온건데 이상하게 된거임  
=================================================================================================================  
$ nohup java –jar camping-0.0.1-SNAPSHOT.jar &		-- 복사한 코드  
$ nohup java -jar camping-0.0.1-SNAPSHOT.jar &		-- 직접 타이핑한 코드  
=================================================================================================================  

로그확인

파일 확인  
=================================================================================================================  
$ vim nohup.out  
=================================================================================================================  
  
실시간 확인  
=================================================================================================================  
$ tail -f nohup.out  
=================================================================================================================  

서비스 중지

======================================================================================================  
$ ps -ef | grep jar  
ec2-user  1940 14732  1 01:49 pts/0    00:00:17 java -jar camping-0.0.1-SNAPSHOT.jar  
ec2-user 12574 14732  0 02:08 pts/0    00:00:00 grep --color=auto jar  
  
$ sudo kill -9 종료시킬 PID 번호  
$ sudo kill -9 1940  
======================================================================================================  

깃 덮어쓰기

원격 저장소에 있는 내용으로 로컬의 내용을 덮어쓰기  
=================================================================================================================  
$ git fetch --all  
$ git reset --hard origin/master  
=================================================================================================================