deploy to EBS from github

GitHub Actions provide an easier way to implement CI/CD for the projects. With a single YAML file and a little bit of configuration, one could achieve a CD pipeline.

For Elastic BeanStalk, we need to run the jobs in a Linux container. ubuntu works in most of the cases. If you wish to use Alpine, you can test it out.

Following workflow runs on push event (git push ...) to the repository's main branch. You can modify it with other events such as pull_request etc. (Full List of Events)

The env variables secrets.AWS_ACCESS_KEY_ID and secrets.AWS_SECRET_ACCESS_KEY must be set in the repository. Visit https://github.com/USER/REPO/settings/secrets/actions to set those variables.

Finally, create a file .github/workflows/deploy.yml and paste the following content.

name: Deploy to Beanstalk

on:
  push:
    branches:
    - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:

    - name: get source code
      uses: actions/checkout@v2

    - name: zip deployment code
      run: zip -r deploy.zip . -x '*.git*'

    - name: deploy to beanstalk
      uses: einaregilsson/beanstalk-deploy@v20
      with:
        aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        application_name:  <EBS_APPLICATION_NAME>
        environment_name: <EBS_APPLICATION_ENV>
        region: <AWS_REGION>
        version_label: ${{ github.run_number }} # or a custom version number
        deployment_package: deploy.zip
        existing_bucket_name: <AWS_S3_BUCKET_NAME> # stores deploy.zip