serverless / github-action

:zap::octocat: A Github Action for deploying with the Serverless Framework
Apache License 2.0
662 stars 174 forks source link

Add examples for using Serverless Plugins #28

Closed matthewpoer closed 3 years ago

matthewpoer commented 4 years ago

Sharing an example of using this Action with one or more SLS Serverless plugins. Would be nice to add some notes around this to the README.md. The key is to set both args and entrypoint on the step.

Similar tactic is used in #26 to capture resources.Outputs data.

name: Deploy
on:
  push:
    branches:
      - master
jobs:
  deploy:
    name: Deployment
    runs-on: ubuntu-latest
    strategy:
      matrix:
        stages:
          - stage: 'dev'
            AWS_SECRET_ACCESS_KEY: 'AWS_SECRET_ACCESS_KEY_DEV'
            AWS_ACCESS_KEY_ID: 'AWS_ACCESS_KEY_ID_DEV'
          - stage: 'prod'
            AWS_SECRET_ACCESS_KEY: 'AWS_SECRET_ACCESS_KEY_PROD'
            AWS_ACCESS_KEY_ID: 'AWS_ACCESS_KEY_ID_PROD'
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install VPC Plugin and Deploy
      uses: serverless/github-action@v1.53.0
      with:
        args: -c "serverless plugin install --name serverless-vpc-discovery && serverless deploy --stage=${{ matrix.stages.stage }} --verbose"
        entrypoint: /bin/bash
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets[matrix.stages.AWS_ACCESS_KEY_ID] }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets[matrix.stages.AWS_SECRET_ACCESS_KEY] }}
        SLS_DEBUG: 1
benjefferies commented 4 years ago

I was just about to start figuring this out but you've saved me some time. Thanks for the issue/documentation @matthewpoer

matthewpoer commented 3 years ago

Update for all those who find this the hard way: serverless plugin install ... will find and install the latest version of a plugin. You can tag specific versions, but I found this easier:

    - name: Install SLS Plugins and Deploy
      uses: serverless/github-action@v1.53.0
      with:
        args: -c "npm install --also=dev && npm list -g && npm list && serverless deploy --stage=${{ matrix.stages.stage }} --verbose"
        entrypoint: /bin/bash

The extra npm list bits are nice to check versions :D

porthunt commented 3 years ago

For anyone getting this error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown.
time="2021-08-24T14:37:43Z" level=error msg="error waiting for container: context canceled"

Change the entrypoint to /bin/sh. It affects >2.18.0 (therefore master too).

More info on #52

Ddevon commented 2 years ago

does this not relevant if the plugins were installed with npm?