-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deploy failing: This command can only be run in a Serverless service directory. #53
Comments
I am experiencing the same issue. I tried using the working directory setting and it still did not work. This is my main.yml:
This gave me the same error. |
couldn't find anyway to make it run either. I think it's because of this:
By default the serverless docker maps the parent folder. Would be nice if there's an option to change that. |
Ended up writing my own commands. name: GitHub Actions Deploy ID Dev
on:
push:
branches:
- main
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: 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 |
* initial setup * add serverless deploy (see issue: serverless/github-action#53) * specify a single node version
You need to set the config variable on the serverless deploy command to the path of the serverless.yml file:
|
This does not work if you are loading other files in your
|
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
Here was the deploy command I was using but couldn't get it to work:
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 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
on:
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 My subdirectory is called
|
@hutch120 Could you elaborate more what is the problem here? Serverless never requires the use of SERVERLESS_ACCESS_KEY, what makes you think that is the case? |
@pgrzesik Thanks for the note. Sure... here are logs of attempting to run without
|
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 |
@pgrzesik Thanks for the info. I stand corrected. I've updated my initial comment. FYI I guess the reason I got to this conclusion was by following along with this general guide and this CI guide |
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 👍 |
https://ryan-schachte.com/posts/serverless-deployments-with-github-actions-on-aws I wrote a post setting this deployment up on Github actions. Might help some people out there. |
I handled this issue by overriding the
Change |
The struggle with the serverless config living outside the root of the folder are detailed [here](https://github.com/serverless/github-action/issues/53\#issuecomment-1059839383) 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](https://github.com/serverless/github-action/issues/53\#issuecomment-1059839383) The github action _should_ respect sub folders, though this should force it run from the correct folder
Thanks, I added this info in the readme. |
So I am doing this now, but get |
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.
I tried doing something like this:
but without any luck.
The text was updated successfully, but these errors were encountered: