簡體   English   中英

AWS Codedeploy 沒有這樣的文件或目錄

[英]AWS Codedeploy No such file or directory

我在通過 AWS CodeDeploy 部署時遇到兩個問題。 我正在嘗試將 CodeCommit 的代碼部署到 EC2 ubuntu 實例。

在 appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu
hooks:
  ApplicationStart:
    - location: scripts/ApplicationStart.sh
      timeout: 300
      runas: ubuntu

在啟動 pm2 之前,我需要將幾個配置文件放在應用程序中的正確位置。 我還假設因為我在 appspec.yml 中將 runas 設置為 ubuntu,所以 bash 腳本將位於 /home/ubuntu。

我的 /home/ubuntu 有

config/ backend/ frontend/ 

看起來 Code deploy 不會覆蓋以前的部署,所以如果我在目錄中有 backend/ 和 frontend/ 文件夾,它會在安裝階段失敗。

在 ApplicationStart.sh 中

#!bin/bash

sudo cp config/config1.json backend/config/config1.json
sudo cp config/config2.json backend/config/environments/development/config2.json
sudo cp config/config3.json frontend/config3.json
sudo pm2 kill

cd backend
sudo npm install
sudo pm2 start "strapi start" --name backend


cd ../frontend
sudo npm install
sudo pm2 start "npm start" --name frontend

在 ApplicationStart 階段,它給了我以下錯誤。

LifecycleEvent - ApplicationStart
Script - scripts/ApplicationStart.sh
[stderr]bash: /opt/codedeploy-agent/path/to/deployment/scripts/ApplicationStart.sh: bin/bash: 
bad interpreter: No such file or directory

我在 /home/ubuntu 運行相同的 bash 文件。 它工作正常。

問題 1. - 如何在沒有錯誤的情況下運行 BeforeInstall.sh? 是否存在路徑問題或我嘗試做但我不應該做的其他事情?

問題 2. - 當目錄 (/home/ubuntu) 中已經存在應用程序文件夾時,如何讓代碼部署覆蓋之前的部署? - 我是否在 BeforeInstall 階段手動刪除目錄?

您在#!bin/bash bin/bash之前缺少斜線。

它應該是#!/bin/bash

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM