Roberto Guajardo
Roberto Guajardo

Reputation: 490

How to use github action to deploy a serverless mono repo with multiple packages.json?

I'm trying to deploy micro services that are part of a mono repo, for this I'm using github actions but I'm having an issue related to the plugins in the package.json files. This is the structure of my project:

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

First I'm trying to deploy the resources folder that basically creates S3 buckets, cognito user pool, etc... and I have added the plugin called "serverless-cognito-add-custom-attributes" as part of this project, this plugin only exists on the package.json that is inside the "resources" folder.

I'm getting this error when trying to deploy from github actions :

Serverless plugin "serverless-cognito-add-custom-attributes" not found. Make sure it's installed and listed in the "plugins" section of your serverless config file.

this is the .yml file I'm using on github actions:

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}}

When the above .yml file run I can see this on the console:

+ [email protected]
added 1 package in 2.935s
+ [email protected]
added 3 packages from 3 contributors in 0.654s

Upvotes: 1

Views: 1493

Answers (1)

Roberto Guajardo
Roberto Guajardo

Reputation: 490

for some reason it seems that

uses: serverless/github-action@master

is unable to find the packages when installed from a sub folder, but doing all manually seems to work fine:

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"

I had this problem for around 17 hours and then decided to go all manual instead of using the package serverless/github-action@master

Upvotes: 4

Related Questions