gpt4 book ai didi

amazon-web-services - 是否有可能在 AppSpec 文件的节文件中使用 CodeDeploy 环境变量

转载 作者:行者123 更新时间:2023-12-03 01:44:38 25 4
gpt4 key购买 nike

我有网站,存储在 AWS EC2 服务器上。

我们有 2 台服务器,一台用于生产环境,另一台用于开发和登台环境。

开发和暂存环境位于不同的文件夹中。例如,开发环境存储在 /var/www/development 中,而 staging 存储在 /var/www/staging 中。

我想使用 AWS CodeDeploy 直接从 bitbucket 上传文件。我放置了 AppSpec 文件,它将源代码复制到 /var/www/html 文件夹并安装所有依赖项和配置。但我希望我的 AppSpec 文件将源代码复制到 /var/www/development/var/www/staging ,具体取决于所选的开发组。

有什么办法可以做到这一点,或者,也许,在我的情况下有更好的方法?

最佳答案

appspec.yml 有点不灵活,因此请使用以下代码将代码部署到同一实例上的不同文件夹中。

version: 0.0
os: linux
files:
- source: /
destination: /var/www/my-temp-dir
permissions:
- object: /var/www/my-temp-dir
owner: ec2-user
group: ec2-user
hooks:
BeforeInstall:
- location: ci/integrations-deploy-pre.sh
runas: root
AfterInstall:
- location: ci/integrations-deploy-post.sh
runas: root

在我的 integrations-deploy-post.sh 文件中,我使用 CodeDeploy 环境变量将文件移动到我需要的位置;

#!/bin/bash

if [ "$DEPLOYMENT_GROUP_NAME" == "Staging" ]
then
cp -R /var/www/my-temp-dir /var/www/my-staging-dir
chown -R ec2-user:ec2-user /var/www/my-staging-dir

# Insert other commands that need to run...
fi

if [ "$DEPLOYMENT_GROUP_NAME" == "UAT" ]
then
cp -R /var/www/my-temp-dir /var/www/my-uat-dir
chown -R ec2-user:ec2-user /var/www/my-uat-dir

# Insert other commands that need to run...
fi

注意:在我的 integrations-deploy-post.sh 中,您还需要要在生产环境中运行的命令。为简单起见已删除。

关于amazon-web-services - 是否有可能在 AppSpec 文件的节文件中使用 CodeDeploy 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45535821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com