如何使用github动作来部署一个有多个package.json的无服务器单体repo?

问题描述 投票:0回答:1

我正在尝试部署作为单体回购一部分的微服务,为此我使用了github动作,但我遇到了一个与package.json文件中的插件有关的问题。这是我项目的结构。

--repo
---package.json
---resources
----package.json
---services
----Service A
-----package.json
----Service B
-----package.json

首先,我试图部署资源文件夹,基本上是创建S3桶,cognito用户池等... 我添加了名为 "serverless-cognito-add-custom-attributes "的插件作为这个项目的一部分,这个插件只存在于 "资源 "文件夹内的package.json中。

当我试图从github actions部署时,我得到了这个错误。

Serverless插件 "serverless-cognito-add-custom-attributes "未找到。确保它已经安装,并列在你的serverless配置文件的 "plugins "部分。

这是我在github actions上使用的.yml文件。

name: Deploy Resources to Dev

on:
  push:
    branches:
      - dev
    tags:
      - RC-*
    paths: 
      - './resources'

jobs:
  InstallActions:
    name: deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Download Node
      uses: actions/setup-node@v1
      with:
        node-version: "12.x"
    - name: Install NPM Global Packages
      run: |
        npm install --global
        npm install "./resources" --global
    - name: Serverless Deploy       
      uses: serverless/github-action@master
      with:
        args: deploy --stage dev --config "./resources/serverless.yml"
      env:
        AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_DEV}}
        AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}

当上面的.yml文件运行时,我可以在控制台看到这个。

+ [email protected]
added 1 package in 2.935s
+ [email protected]
added 3 packages from 3 contributors in 0.654s
amazon-web-services github package.json serverless-framework github-actions
1个回答
1
投票

出于某种原因,似乎

uses: serverless/github-action@master

当从子文件夹安装时,无法找到包,但手动安装似乎可以正常工作。

name: Deploy Resources to Dev

on:
  push:
    branches:
      - dev
    tags:
      - RC-*
    paths: 
      - './resources'

jobs:
  Deploy:
    name: deploy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Download Node
      uses: actions/setup-node@v1
      with:
        node-version: "12.x"
    - name: Install Serverless Framework
      run: npm install -g serverless
    - name: Serverless Authentication
      run: sls config credentials --provider aws --key ${{secrets.AWS_ACCESS_KEY_DEV}} --secret ${{secrets.AWS_SECRET_ACCESS_KEY_DEV}}
    - name: Install NPM dependencies
      run: |
        npm install
        npm install "./resources"
    - name: Deploy to AWS
      run: serverless deploy -v -s dev
      working-directory: "./resources"

我遇到了这个问题,大约17个小时,然后决定全部手动,而不是使用包serverlessgithub-action@master。

© www.soinside.com 2019 - 2024. All rights reserved.