The "Deploy to Elastic Beanstalk" GitHub Action automates the deployment of applications to AWS Elastic Beanstalk directly from your GitHub repository, ensuring a seamless CI/CD pipeline for your cloud-based applications.
This action is triggered on pushes to the develop and main branches or can be manually triggered using workflow_dispatch.
It consists of two main jobs: gathering job information and deploying to AWS Elastic Beanstalk.
The deployment process includes building a deployment package (e.g., a JAR file for a Spring Java application) and deploying it to the specified Elastic Beanstalk environment.
-
push:- Triggers the workflow on pushes to the develop and main branches.
-
workflow_dispatch:- Allows the workflow to be manually triggered.
-
Gather info for jobs (
info):- Gathers essential information for subsequent jobs, like the environment name.
- Uses the job-info action to determine the target environment based on the branch or tag that triggered the workflow.
-
Deploy to Elastic Beanstalk (
deploy):- Depends on the
infojob. - Performs several steps to deploy the application to AWS Elastic Beanstalk:
- Checkout code: Checks out the code for the application.
- Set up JDK: Sets up the Java Development Kit (JDK) environment. Uses Corretto 17, matching the Elastic Beanstalk configuration.
- Build deployment package: Builds the application's deployment package (e.g., a JAR file). The environment variables for the database are set using secrets.
- Artifact Deploy Package: (Optional) Saves the deployment package as a GitHub artifact, aiding in debugging and rollback if necessary.
- Deploy to Elastic Beanstalk: Deploys the built package to AWS Elastic Beanstalk using the
beanstalk-deployaction.
- Depends on the
terraform-version: (Optional) Specifies the version of Terraform to use. Defaults to "latest".paths: (Optional) Specifies newline-separated list of paths to validate. Defaults to the current directory.
SPRING_DATASOURCE_PASSWORD: The password for the database.SPRING_DATASOURCE_USERNAME: The username for the database.SPRING_DATASOURCE_URL: The JDBC URL for the database.SPRING_LIQUIBASE_URL: The Liquibase URL for the database.DEPLOY_ENV: The target environment for deployment.S3_BUCKET: The name of the S3 bucket for deployment.
ACCESS_KEY_ID: AWS access key ID.SECRET_ACCESS_KEY: AWS secret access key.
To use this workflow:
-
Ensure that the required secrets (
ACCESS_KEY_IDandSECRET_ACCESS_KEY) are set in your repository's secrets. -
Configure the workflow to match your application's needs, especially the environment variables and the build script.
-
Push code to the
developormainbranches, or manually trigger the workflow.
- The workflow is optimized for Java applications but can be adapted for other types of applications.
- Ensure that the AWS credentials provided have the necessary permissions for Elastic Beanstalk operations.
- The deployment package is optionally saved as an artifact on GitHub, providing a backup for rollback if necessary.
Remember to replace your-repo/deploy-to-elastic-beanstalk@v1 with the actual path to your action if you host it in a specific repository.
This README provides a comprehensive guide on how to integrate and leverage the "Deploy to Elastic Beanstalk" action in your GitHub workflows.