I have a mono repo project and a separate directory that contains the serverless yaml file. Is there a way to set the directory to execute from in the github action.
- name: Navigate to serverless
run: cd serverless
- name: Serverless Deploy
uses: serverless/github-action@master
with:
args: deploy
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
but without any luck.
I am experiencing the same issue. I tried using the working directory setting and it still did not work.
This is my main.yml:
name: Deploy master branch
push:
branches:
- master
jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
defaults:
working-directory: ./app
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy
# SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
# or if using AWS credentials directly
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
This gave me the same error.
couldn't find anyway to make it run either. I think it's because of this:
-v "/home/runner/work/berry/berry":"/github/workspace"
By default the serverless docker maps the parent folder. Would be nice if there's an option to change that.
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn workspace @berry/shared build
- run: node ./node_modules/serverless/bin/serverless.js config credentials --provider aws --key ${{ secrets.AWS_ACCESS_KEY_ID }} --secret ${{ secrets.AWS_SECRET_ACCESS_KEY }} --profile papaya --overwrite
- run: node ../../node_modules/serverless/bin/serverless.js deploy --aws-s3-accelerate --stage dev --verbose
working-directory: ./services/id
env:
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SLS_DEBUG: 1
akfreas, mikkel-arturo, Blackglade, StephenGrable1, diegohsitec, and bazetovich reacted with thumbs up emoji
StephenGrable1, diegohsitec, and PatrickFelber reacted with heart emoji
All reactions
You need to set the config variable on the serverless deploy command to the path of the serverless.yml file:
name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy -s stage -c path/to/file/serverless.yml
You need to set the config variable on the serverless deploy command to the path of the serverless.yml file:
name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy -s stage -c path/to/file/serverless.yml
This does not work if you are loading other files in your serverless.yml
.
Serverless Warning --------------------------------------
A valid file to satisfy the declaration 'file(dev-config.yaml):environment' could not be found.
You need to set the config variable on the serverless deploy command to the path of the serverless.yml file:
name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy -s stage -c path/to/file/serverless.yml
This still doesn't work due to the fact that my repo is a monorepo and so all my serverless functions are inside a serverless folder inside my repo.
Repo Structure looks something like this
/package.json
/<ReactJS Project Files>
/serverless
/serverless/serverless.yml
/serverless/index.js <- contains function info
/serverless/package.json
Here was the deploy command I was using but couldn't get it to work:
name: Deploy to AWS Lambda
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Build w/ Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm ci
working-directory: ./serverless
- name: Serverless Deploy
uses: serverless/github-action@master
with:
args: -c "serverless plugin install --name serverless-domain-manager && serverless deploy -c serverless/serverless.yml -v"
entrypoint: /bin/sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Honestly have sort of given up on this. It's clear Serverless has no intention of providing support for github actions.
You need to set the config variable on the serverless deploy command to the path of the serverless.yml file:
name: serverless deploy
uses: serverless/github-action@master
with:
args: deploy -s stage -c path/to/file/serverless.yml
This still doesn't work due to the fact that my repo is a monorepo and so all my serverless functions are inside a serverless folder inside my repo.
Repo Structure looks something like this
/package.json
/<ReactJS Project Files>
/serverless
/serverless/serverless.yml
/serverless/index.js <- contains function info
/serverless/package.json
Here was the deploy command I was using but couldn't get it to work:
name: Deploy to AWS Lambda
push:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Build w/ Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
- run: npm ci
working-directory: ./serverless
- name: Serverless Deploy
uses: serverless/github-action@master
with:
args: -c "serverless plugin install --name serverless-domain-manager && serverless deploy -c serverless/serverless.yml -v"
entrypoint: /bin/sh
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Honestly have sort of given up on this. It's clear Serverless has no intention of providing support for github actions.
Seems like the solution i provided previously only works for single lambdas.
I apologise that this does not represent most cases that people encounter in real life scenarios.
I have had luck calling serverless directly via npx, see here as an example. CLI commands/flags should work as indentended - but I havn't tried with a monorepo setup or using other yml files in the serverless.yml file (hopefully is not the same result as before).
I am keen to see the result of such running serverless with the above method - hopefully we can help progress this GHA.
Anyone encountering this thread who's following best practices and splitting their serverless app into separate directories, follow @deathemperor solution above (or my slightly simplified one below) to roll your own deployment step for each of your services.
Any semi-mature application will eventually need to split their code. I recommend you do not consolidate your separate services into the root folder just so this github action will work -- you will end up having to backtrack once your app grows.
It would be great if we could add support for this eventually, but in the meantime, I'm dropping this github action and using this manual deployment setup:
name: GitHub Actions Deploy Prod
push:
branches:
- master
jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build
- run: node ./node_modules/serverless/bin/serverless.js config credentials --provider aws --key ${{ secrets.AWS_ACCESS_KEY_ID }} --secret ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- run: node ../../node_modules/serverless/bin/serverless.js deploy --stage prod --verbose
working-directory: ./serverless/backend-api
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SLS_DEBUG: 1
thanks again for the suggestion @deathemperor
to deal with a Serverless Error `This command can only be run in a Serverless service directory.`
see: serverless/github-action#53
to deal with a Serverless Error `This command can only be run in a Serverless service directory.`
see: serverless/github-action#53
Update... if you add org and app properties to serverless.yaml then the serverless client requires a SERVERLESS_ACCESS_KEY
configured in serverless.com UX console.
My subdirectory is called server
, note the use of working-directory
at top level rather than for each step.
name: Deploy main branch serverless
push:
branches:
- main
jobs:
deploy:
name: deployserver
runs-on: ubuntu-latest
defaults:
working-directory: ./server
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: node ./node_modules/serverless/bin/serverless.js deploy --stage prod --verbose
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}
SLS_DEBUG: 1
@pgrzesik Thanks for the note. Sure... here are logs of attempting to run without SERVERLESS_ACCESS_KEY
. Literally the only change required to get my deploy to work is to add a valid SERVERLESS_ACCESS_KEY
to the env
section of the yaml file.
Run node ./node_modules/serverless/bin/serverless.js config credentials --provider aws --key *** --secret ***
node ./node_modules/serverless/bin/serverless.js config credentials --provider aws --key *** --secret ***
shell: /usr/bin/bash -e {0}
Serverless: Setting up AWS...
Run node ./node_modules/serverless/bin/serverless.js deploy --stage prod --verbose
node ./node_modules/serverless/bin/serverless.js deploy --stage prod --verbose
shell: /usr/bin/bash -e {0}
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
Serverless Error ----------------------------------------
You are not currently logged in. Follow instructions in http://slss.io/run-in-cicd to setup env vars for authentication.
Hey @hutch120 - thanks for responding. Based on the error message it seems like you're using Serverless Dashboard integration in your service - do you have org
and app
properties defined in your serverless.yml
? If that's the case, then yes, SERVERLESS_ACCESS_KEY is required, because otherwise it would be impossible to use the Dashboard integration. If you are not using Dashboard, you can remove the org
and app
setttings and key will be no longer needed.
Hey @hutch120 - happy I could help clear up some misunderstanding 👍 As for these guides, I'm looking at them and I see that the second one about CI setup might definitely be misleading, as it suggests that if you're using CI, then you need to use Dashboard which is definitely not the case. I'll bring it up internally so we can clear that confusion in documentation as well 👍
I handled this issue by overriding the ENTRYPOINT
and changing to the directory that contains my serverless.yml
this way
jobs:
deploy:
name: deployserver
steps:
- name: serverless deploy
uses: serverless/github-action@v3
with:
args: -c "cd ./<your-dir> && serverless deploy"
entrypoint: /bin/sh
Change <your-dir>
to your target directory.
The struggle with the serverless config living
outside the root of the folder are detailed [here](serverless/github-action#53)
The github action _should_ respect sub folders, though this should force
it run from the correct folder
The struggle with the serverless config living
outside the root of the folder are detailed [here](serverless/github-action#53)
The github action _should_ respect sub folders, though this should force
it run from the correct folder
I handled this issue by overriding the ENTRYPOINT
and changing to the directory that contains my serverless.yml
this way
jobs:
deploy:
name: deployserver
steps:
- name: serverless deploy
uses: serverless/github-action@v3
with:
args: -c "cd ./<your-dir> && serverless deploy"
entrypoint: /bin/sh
Change <your-dir>
to your target directory.
So I am doing this now, but get /bin/sh: 1: serverless: not found
error. Am I doing something wrong? What should the content of the package.json
look like? As in does it need any specific dependencies for npm ci
?