From bd13ac839d546d634e3f87f88408180e74c879b1 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 15:21:56 +0900 Subject: [PATCH 01/21] add script for continuous deploy --- cd/appspec.yml | 17 +++++++++++++++++ cd/buildspec.yml | 17 +++++++++++++++++ cd/healthCheck.sh | 2 ++ cd/initialize.sh | 1 + cd/start.sh | 5 +++++ 5 files changed, 42 insertions(+) create mode 100644 cd/appspec.yml create mode 100644 cd/buildspec.yml create mode 100644 cd/healthCheck.sh create mode 100644 cd/initialize.sh create mode 100644 cd/start.sh diff --git a/cd/appspec.yml b/cd/appspec.yml new file mode 100644 index 0000000..1dc5980 --- /dev/null +++ b/cd/appspec.yml @@ -0,0 +1,17 @@ +version: 0.0 +os: linux +files: + - source: / + destination: /home/ubuntu/api +hooks: + BeforeInstall: + - location: /initialize.sh + runas: root + + ApplicationStart: + - location: /start.sh + runas: root + ValidateService: + - location: /healthCheck.sh + runas: ubuntu + # ubuntu의 $HOME 환경변수를 이용해보려고 runas ubuntu \ No newline at end of file diff --git a/cd/buildspec.yml b/cd/buildspec.yml new file mode 100644 index 0000000..09402d6 --- /dev/null +++ b/cd/buildspec.yml @@ -0,0 +1,17 @@ +version: 0.2 + +phases: + install: + runtime-versions: + nodejs: 18.18 + commands: + - npm install + - pwd + run-as: root + +artifacts: + files: + - "**/*" +cache: + paths: + - "node_modules/**/*" \ No newline at end of file diff --git a/cd/healthCheck.sh b/cd/healthCheck.sh new file mode 100644 index 0000000..4a85572 --- /dev/null +++ b/cd/healthCheck.sh @@ -0,0 +1,2 @@ +echo "Health Check... connect to localhost:3000" +curl "http://localhost:3000" \ No newline at end of file diff --git a/cd/initialize.sh b/cd/initialize.sh new file mode 100644 index 0000000..c4cc9e5 --- /dev/null +++ b/cd/initialize.sh @@ -0,0 +1 @@ +if [ -d "/home/ubuntu/api" ]; then rm -Rf "/home/ubuntu/api"; fi \ No newline at end of file diff --git a/cd/start.sh b/cd/start.sh new file mode 100644 index 0000000..cf1edd0 --- /dev/null +++ b/cd/start.sh @@ -0,0 +1,5 @@ +cd /home/ubuntu/api + +# 원래 node 프로세스 종료 +sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` +nohup npm start >/home/ubuntu/logs 2>&1 Date: Tue, 24 Oct 2023 15:55:01 +0900 Subject: [PATCH 02/21] add script for continuous deploy --- cd/buildspec.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/cd/buildspec.yml b/cd/buildspec.yml index 09402d6..84eed4f 100644 --- a/cd/buildspec.yml +++ b/cd/buildspec.yml @@ -6,6 +6,7 @@ phases: nodejs: 18.18 commands: - npm install + - nest build - pwd run-as: root From a5dd2c46e2dcd0222ef3e81741ad9b202a772c0d Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 16:12:40 +0900 Subject: [PATCH 03/21] add script for continuous deploy --- cd/buildspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cd/buildspec.yml b/cd/buildspec.yml index 84eed4f..9ad3840 100644 --- a/cd/buildspec.yml +++ b/cd/buildspec.yml @@ -3,7 +3,7 @@ version: 0.2 phases: install: runtime-versions: - nodejs: 18.18 + nodejs: 18 commands: - npm install - nest build From a4496b25724110c5980f995011bfdc0f8892c9f4 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 16:16:28 +0900 Subject: [PATCH 04/21] add script for continuous deploy --- cd/buildspec.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/cd/buildspec.yml b/cd/buildspec.yml index 9ad3840..9bf31a5 100644 --- a/cd/buildspec.yml +++ b/cd/buildspec.yml @@ -9,7 +9,6 @@ phases: - nest build - pwd run-as: root - artifacts: files: - "**/*" From 5f48fe198fbdfa304fd3b867f7eb12e5dbe69500 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 16:18:40 +0900 Subject: [PATCH 05/21] add script for continuous deploy --- cd/buildspec.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cd/buildspec.yml b/cd/buildspec.yml index 9bf31a5..c4756e9 100644 --- a/cd/buildspec.yml +++ b/cd/buildspec.yml @@ -6,9 +6,11 @@ phases: nodejs: 18 commands: - npm install - - nest build - pwd run-as: root + build: + commands: + - nest build artifacts: files: - "**/*" From b0eee815ab1d96a5fc27081a786878afbd23c2f1 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 16:23:31 +0900 Subject: [PATCH 06/21] add script for continuous deploy --- cd/appspec.yml => appspec.yml | 0 cd/buildspec.yml => buildspec.yml | 0 cd/healthCheck.sh => healthCheck.sh | 0 cd/initialize.sh => initialize.sh | 0 cd/start.sh => start.sh | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename cd/appspec.yml => appspec.yml (100%) rename cd/buildspec.yml => buildspec.yml (100%) rename cd/healthCheck.sh => healthCheck.sh (100%) rename cd/initialize.sh => initialize.sh (100%) rename cd/start.sh => start.sh (100%) diff --git a/cd/appspec.yml b/appspec.yml similarity index 100% rename from cd/appspec.yml rename to appspec.yml diff --git a/cd/buildspec.yml b/buildspec.yml similarity index 100% rename from cd/buildspec.yml rename to buildspec.yml diff --git a/cd/healthCheck.sh b/healthCheck.sh similarity index 100% rename from cd/healthCheck.sh rename to healthCheck.sh diff --git a/cd/initialize.sh b/initialize.sh similarity index 100% rename from cd/initialize.sh rename to initialize.sh diff --git a/cd/start.sh b/start.sh similarity index 100% rename from cd/start.sh rename to start.sh From 107c848d06f255de2652cd35cc846ae64f1b4bf8 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 16:46:03 +0900 Subject: [PATCH 07/21] add script for continuous deploy --- buildspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildspec.yml b/buildspec.yml index c4756e9..46cb0cd 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -10,7 +10,7 @@ phases: run-as: root build: commands: - - nest build + - npx @nestjs/cli build artifacts: files: - "**/*" From e1d44ed264eb670cb66f9122e4a580745ebff2db Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 17:10:57 +0900 Subject: [PATCH 08/21] add script for continuous deploy --- appspec.yml | 4 ---- start.sh | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/appspec.yml b/appspec.yml index 1dc5980..73f2b47 100644 --- a/appspec.yml +++ b/appspec.yml @@ -4,10 +4,6 @@ files: - source: / destination: /home/ubuntu/api hooks: - BeforeInstall: - - location: /initialize.sh - runas: root - ApplicationStart: - location: /start.sh runas: root diff --git a/start.sh b/start.sh index cf1edd0..5cd5007 100644 --- a/start.sh +++ b/start.sh @@ -2,4 +2,4 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` -nohup npm start >/home/ubuntu/logs 2>&1 /home/ubuntu/logs 2>&1 Date: Tue, 24 Oct 2023 17:25:04 +0900 Subject: [PATCH 09/21] add script for continuous deploy --- appspec.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 73f2b47..a91ebbc 100644 --- a/appspec.yml +++ b/appspec.yml @@ -10,4 +10,3 @@ hooks: ValidateService: - location: /healthCheck.sh runas: ubuntu - # ubuntu의 $HOME 환경변수를 이용해보려고 runas ubuntu \ No newline at end of file From 5eafe7e75e288a2da725599e43b2f592e1d02fca Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 17:39:11 +0900 Subject: [PATCH 10/21] add script for continuous deploy --- appspec.yml | 7 +++++-- buildspec.yml | 2 ++ cd/afterInstall.sh | 1 + healthCheck.sh => cd/healthCheck.sh | 0 initialize.sh => cd/initialize.sh | 0 start.sh => cd/start.sh | 0 6 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 cd/afterInstall.sh rename healthCheck.sh => cd/healthCheck.sh (100%) mode change 100644 => 100755 rename initialize.sh => cd/initialize.sh (100%) rename start.sh => cd/start.sh (100%) diff --git a/appspec.yml b/appspec.yml index a91ebbc..f2afaef 100644 --- a/appspec.yml +++ b/appspec.yml @@ -4,9 +4,12 @@ files: - source: / destination: /home/ubuntu/api hooks: + BeforeInstall: + - location: /cd/beforeInstall.sh + runas: root ApplicationStart: - - location: /start.sh + - location: /cd/start.sh runas: root ValidateService: - - location: /healthCheck.sh + - location: /cd/healthCheck.sh runas: ubuntu diff --git a/buildspec.yml b/buildspec.yml index 46cb0cd..9744b56 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -11,6 +11,8 @@ phases: build: commands: - npx @nestjs/cli build + - rm -rf node_modules + run-as: root artifacts: files: - "**/*" diff --git a/cd/afterInstall.sh b/cd/afterInstall.sh new file mode 100644 index 0000000..b66c116 --- /dev/null +++ b/cd/afterInstall.sh @@ -0,0 +1 @@ +npm install \ No newline at end of file diff --git a/healthCheck.sh b/cd/healthCheck.sh old mode 100644 new mode 100755 similarity index 100% rename from healthCheck.sh rename to cd/healthCheck.sh diff --git a/initialize.sh b/cd/initialize.sh similarity index 100% rename from initialize.sh rename to cd/initialize.sh diff --git a/start.sh b/cd/start.sh similarity index 100% rename from start.sh rename to cd/start.sh From dbe5899439d9847ddbd7eceed17a2607e05aefbf Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 17:48:19 +0900 Subject: [PATCH 11/21] add script for continuous deploy --- cd/{afterInstall.sh => beforeInstall.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cd/{afterInstall.sh => beforeInstall.sh} (100%) diff --git a/cd/afterInstall.sh b/cd/beforeInstall.sh similarity index 100% rename from cd/afterInstall.sh rename to cd/beforeInstall.sh From 0265bc67ac9973b3e576955e5e0d7fc5ac4fc73e Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 18:12:18 +0900 Subject: [PATCH 12/21] add script for continuous deploy --- appspec.yml | 2 +- cd/{beforeInstall.sh => afterInstall.sh} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cd/{beforeInstall.sh => afterInstall.sh} (100%) diff --git a/appspec.yml b/appspec.yml index f2afaef..08b487f 100644 --- a/appspec.yml +++ b/appspec.yml @@ -5,7 +5,7 @@ files: destination: /home/ubuntu/api hooks: BeforeInstall: - - location: /cd/beforeInstall.sh + - location: /cd/afterInstall.sh runas: root ApplicationStart: - location: /cd/start.sh diff --git a/cd/beforeInstall.sh b/cd/afterInstall.sh similarity index 100% rename from cd/beforeInstall.sh rename to cd/afterInstall.sh From c26f4e0bce5a1fda915270ea0de87b1889dc63fc Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 18:15:41 +0900 Subject: [PATCH 13/21] add script for continuous deploy --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 08b487f..91a3732 100644 --- a/appspec.yml +++ b/appspec.yml @@ -4,7 +4,7 @@ files: - source: / destination: /home/ubuntu/api hooks: - BeforeInstall: + AfterInstall: - location: /cd/afterInstall.sh runas: root ApplicationStart: From f9f7a9c051ca1ef8d83421bcae6538bb55680d75 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 18:57:16 +0900 Subject: [PATCH 14/21] add script for continuous deploy --- appspec.yml | 3 --- cd/start.sh | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/appspec.yml b/appspec.yml index 91a3732..5e7bd5f 100644 --- a/appspec.yml +++ b/appspec.yml @@ -4,9 +4,6 @@ files: - source: / destination: /home/ubuntu/api hooks: - AfterInstall: - - location: /cd/afterInstall.sh - runas: root ApplicationStart: - location: /cd/start.sh runas: root diff --git a/cd/start.sh b/cd/start.sh index 5cd5007..509f902 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -2,4 +2,5 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` +npm install nohup npm run start:dev >/home/ubuntu/logs 2>&1 Date: Tue, 24 Oct 2023 19:23:41 +0900 Subject: [PATCH 15/21] add script for continuous deploy --- appspec.yml | 2 +- cd/afterInstall.sh | 1 - cd/start.sh | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 cd/afterInstall.sh diff --git a/appspec.yml b/appspec.yml index 5e7bd5f..0e6420e 100644 --- a/appspec.yml +++ b/appspec.yml @@ -9,4 +9,4 @@ hooks: runas: root ValidateService: - location: /cd/healthCheck.sh - runas: ubuntu + runas: root diff --git a/cd/afterInstall.sh b/cd/afterInstall.sh deleted file mode 100644 index b66c116..0000000 --- a/cd/afterInstall.sh +++ /dev/null @@ -1 +0,0 @@ -npm install \ No newline at end of file diff --git a/cd/start.sh b/cd/start.sh index 509f902..a601478 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -2,5 +2,6 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` -npm install -nohup npm run start:dev >/home/ubuntu/logs 2>&1 /home/ubuntu/log/logs 2>&1 Date: Tue, 24 Oct 2023 20:09:23 +0900 Subject: [PATCH 16/21] add script for continuous deploy --- appspec.yml | 4 ++-- buildspec.yml | 4 ++-- cd/start.sh | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/appspec.yml b/appspec.yml index 0e6420e..1b49066 100644 --- a/appspec.yml +++ b/appspec.yml @@ -6,7 +6,7 @@ files: hooks: ApplicationStart: - location: /cd/start.sh - runas: root + runas: ubuntu ValidateService: - location: /cd/healthCheck.sh - runas: root + runas: ubuntu diff --git a/buildspec.yml b/buildspec.yml index 9744b56..37935c8 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -7,12 +7,12 @@ phases: commands: - npm install - pwd - run-as: root + run-as: ubuntu build: commands: - npx @nestjs/cli build - rm -rf node_modules - run-as: root + run-as: ubuntu artifacts: files: - "**/*" diff --git a/cd/start.sh b/cd/start.sh index a601478..fec14c7 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -2,6 +2,6 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` -sudo npm install +npm install nohup npm run start:dev >/home/ubuntu/log/logs 2>&1 Date: Tue, 24 Oct 2023 20:17:46 +0900 Subject: [PATCH 17/21] add script for continuous deploy --- buildspec.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 37935c8..9744b56 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -7,12 +7,12 @@ phases: commands: - npm install - pwd - run-as: ubuntu + run-as: root build: commands: - npx @nestjs/cli build - rm -rf node_modules - run-as: ubuntu + run-as: root artifacts: files: - "**/*" From 663b3c201bb04c166cdcbae7b2588f919c438a2a Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Tue, 24 Oct 2023 20:29:04 +0900 Subject: [PATCH 18/21] add script for continuous deploy --- cd/start.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cd/start.sh b/cd/start.sh index fec14c7..0b57f6d 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -2,6 +2,8 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` +sudo chmod 777 /home/ubuntu/api npm install nohup npm run start:dev >/home/ubuntu/log/logs 2>&1 Date: Tue, 24 Oct 2023 20:36:58 +0900 Subject: [PATCH 19/21] add script for continuous deploy --- cd/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cd/start.sh b/cd/start.sh index 0b57f6d..0d6b4ce 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -2,7 +2,7 @@ cd /home/ubuntu/api # 원래 node 프로세스 종료 sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` -sudo chmod 777 /home/ubuntu/api +sudo chmod -R 777 /home/ubuntu/api npm install nohup npm run start:dev >/home/ubuntu/log/logs 2>&1 Date: Tue, 24 Oct 2023 20:41:16 +0900 Subject: [PATCH 20/21] add script for continuous deploy --- cd/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cd/start.sh b/cd/start.sh index 0d6b4ce..37b5593 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -4,6 +4,6 @@ cd /home/ubuntu/api sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` sudo chmod -R 777 /home/ubuntu/api npm install -nohup npm run start:dev >/home/ubuntu/log/logs 2>&1 /home/ubuntu/log/logs 2>&1 Date: Tue, 24 Oct 2023 20:43:31 +0900 Subject: [PATCH 21/21] add script for continuous deploy --- cd/start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cd/start.sh b/cd/start.sh index 37b5593..c199bac 100644 --- a/cd/start.sh +++ b/cd/start.sh @@ -4,6 +4,6 @@ cd /home/ubuntu/api sudo kill -9 `ps -ef | grep 'node' | awk '{print $2}'` sudo chmod -R 777 /home/ubuntu/api npm install -nohup cross-env NODE_ENV=dev nest start >/home/ubuntu/log/logs 2>&1 /home/ubuntu/log/logs 2>&1