使用Pulumi部署AWS栈时出错:未找到名为'dev'的栈
我正在尝试在我的AWS账户中使用pulumi来部署一个堆栈。我的deploy.yml文件看起来是这样的:
name: Pushes Glue Scripts to S3
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy jobs
uses: pulumi/actions@v5
id: pulumi
env:
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
with:
command: up
cloud-url: s3://my-bucket/pulumi/
stack-name: dev
在我的代码库里,有一个名为Pulumi.dev.yaml的堆栈文件。这个文件里只有一个加密盐的代码。值得一提的是,我通过命令pulumi login s3://my-bucket/pulumi
把pulumi的后端配置到了我的S3桶里。
但是,当我运行我的部署代码时,出现了以下错误:
StackNotFoundError: code: -2
stdout:
stderr: Command failed with exit code 255: pulumi stack select --stack dev --non-interactive
error: no stack named 'dev' found
err?: Error: Command failed with exit code 255: pulumi stack select --stack dev --non-interactive
error: no stack named 'dev' found
我觉得运行pulumi up代码的容器没有找到我的堆栈。那么,我该如何解决这个问题呢?在使用Pulumi运行我的Github Actions时,有没有什么步骤需要检查的?
1 个回答
0
经过几天的努力,我终于找到了解决办法,虽然我觉得这可能不是最好的或最合适的方案。我不得不重新整理我的部署脚本,以达到我想要的效果。下面是我的脚本和一些解释:
name: Pushes Glue Scripts to S3
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
PULUMI_STACK: dev
PULUMI_CONFIG_PASSPHRASE:
GLUE_SCRIPT_LOCATION: ${{ vars.GLUE_SCRIPT_LOCATION }}
jobs:
deploy-glue-jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./glue_jobs
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Pulumi
uses: pulumi/action-install-pulumi-cli@v1.0.1
- name: Install Poetry
run: pip install poetry
- name: Installing Project Dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.GLUE_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.GLUE_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Start Pulumi
run: |
poetry run pulumi login s3://my-bucket/pulumi
poetry run pulumi stack select dev
poetry run pulumi stack init dev
continue-on-error: true
- name: Deploy Pulumi
run: poetry run pulumi up --yes
我尝试过的 pulumi/actions@v5
对我来说没用。所以我不得不把使用 pulumi 部署服务的整个过程拆分开来。
首先,我需要安装 pulumi 并配置 AWS 的凭证。因为我使用 poetry 来管理我的依赖,所以我添加了一个步骤来安装、配置和管理它。然后,我确保通过 poetry 的命令在我的环境中运行 pulumi。
好吧,正如我所说,这个方法是有效的。但是有没有改进的空间呢?我相信是有的。所以,如果你有更合适的答案,请随时补充。目前,我就先这样做了。