git - 使用 CodeDeploy 和 Bitbucket 管道在 EC2 上自动部署
问题描述
我有一个用Django(Python 框架)编写的项目和Bitbucket中的存储库
我必须使用以下操作设置 bitbucket 管道:
- 在暂存服务器中部署并提交到暂存分支
- 当发布只是来自主分支的草稿时,部署到生产服务器。
我不确定像 Github 这样的 Bitbucket 可以在哪里草稿。
我有以下bitbucket-pipelines.yml文件
image: python:3.7
pipelines:
branches:
staging:
- step:
deployment: staging
script:
- apt-get update
- apt-get install -y zip # required for packaging up the application
- pip install boto3==1.3.0 # required for codedeploy_deploy.py
- zip -r /tmp/artifact.zip * # package up the application for deployment
- python codedeploy_deploy.py # run the deployment script
现在,在 Django 应用程序中,我使用.env
它来提供凭据和设置。对于不同的环境,比如开发、登台和生产,我对每个环境都有不同的环境文件
development.env
staging.env
production.env
我需要.env
根据部署类型重命名/复制相应的文件。
如何在 bitbucket 管道中设置它以执行此步骤?
appspec.yml内容为:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html/project/
permissions:
- object: /var/www/html
pattern: "**"
owner: ubuntu
group: ubuntu
hooks:
BeforeInstall:
- location: scripts/clean_instance.sh
timeout: 6000
runas: root
AfterInstall:
- location: scripts/install_os_dependencies.sh
timeout: 6000
runas: root
- location: scripts/install_python_dependencies.sh
timeout: 6000
runas: ubuntu
- location: scripts/setup_environment.sh
timeout: 6000
runas: ubuntu
- location: scripts/migrate.sh
timeout: 6000
runas: ubuntu
- location: scripts/ngnix.sh
timeout: 6000
runas: ubuntu
ApplicationStart:
- location: scripts/start_application.sh
timeout: 6000
runas: ubuntu
ApplicationStop:
- location: scripts/stop_application.sh
timeout: 6000
runas: ubuntu
根据部署类型,我可以有多个 appspec.yml 文件吗?
解决方案
在应用程序版本名称下拥有多个目录可能是一个很好的解决方案。
1.0.0->
appspec.yml
files/
scripts/
推荐阅读
- javascript - ajax 不工作我必须刷新才能使其工作
- python - SyntaxError:无效的语法,python3
- vue.js - 无法在 vue native 中导入 js 文件
- sql - 带有 IF、ELSE 的函数“如果总价格的 AVG 高于游戏价格,则返回 0,否则返回 1”
- ubuntu - 如何在 mosquitto broker 的 bridg.conf 文件中提及 will 消息设置
- forms - 访问表单/文本框默认值问题
- json - JSON 提取多列 PostgreSQL
- pandas - 使用自定义功能按多列分组
- xamarin - AppCenter 不构建 Android App Bundle (aab)
- bash - 如何编写多个条件并选择文件夹名称的最小值?