Created
March 12, 2023 03:46
-
-
Save ikhanhmai/ae404013a320ce9fe38c6361742bf96f to your computer and use it in GitHub Desktop.
Sample github actions yml file to integrate with Elastic AWS Beanstalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Stage - Deploy Odidi FT BE to AWS Elastic Beanstalk | |
env: | |
APP_NAME: OdidiFT | |
ENV_NAME: Odidiftstage | |
S3_BUCKET: odidi-ft | |
AWS_REGION: ap-southeast-1 | |
AWS_PLATFORM: Docker | |
PIPELINE_ID: ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER} | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
create_eb_version: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- run: | | |
AWS_VERSION_LABEL=${{env.APP_NAME}}-${{env.PIPELINE_ID}} | |
echo "Creating Source Bundle" | |
zip -r ${{env.APP_NAME}}.zip ./src Dockerfile dockerignore package.json yarn.lock tsconfig.json | |
S3_KEY="$AWS_VERSION_LABEL.zip" | |
echo "Uploading Source Bundle to S3" | |
aws s3 cp ${{env.APP_NAME}}.zip s3://${{env.S3_BUCKET}}/${S3_KEY} --region ${{env.AWS_REGION}} | |
echo "Creating Elastic Beanstalk version" | |
aws elasticbeanstalk create-application-version --application-name ${{env.APP_NAME}} --version-label $AWS_VERSION_LABEL --region ${{env.AWS_REGION}} --source-bundle S3Bucket=${{env.S3_BUCKET}},S3Key=${S3_KEY} --auto-create-application | |
deploy_aws: | |
needs: [create_eb_version] | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: Waiting for approval | |
uses: trstringer/manual-approval@v1.9.0 | |
with: | |
secret: ${{ github.TOKEN }} | |
approvers: ace53thntu, ikhanhmai, tindl88, phuocvuive09 | |
minimum-approvals: 1 | |
issue-title: "Deploying Odidi FT BE to stage environment" | |
issue-body: "Please approve or deny the deployment" | |
exclude-workflow-initiator-as-approver: false | |
additional-approved-words: 'approved ✅' | |
additional-denied-words: 'rejected 💬' | |
- uses: actions/checkout@v2 | |
- name: Set up Python 3.10.10 (needed for eb cli) | |
uses: actions/setup-python@v1 | |
with: | |
python-version: "3.10.10" | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-id: ${{ secrets.AWS_ID }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- run: | | |
AWS_VERSION_LABEL=${{env.APP_NAME}}-${{env.PIPELINE_ID}} | |
echo "Installing Elastic Beanstalk Cli" | |
python -m pip install --upgrade pip | |
pip install awsebcli --upgrade | |
eb --version | |
echo "eb init" | |
eb init ${{env.APP_NAME}} -p ${{env.AWS_PLATFORM}} --region ${{env.AWS_REGION}} | |
echo "eb deploy" | |
eb deploy ${{env.ENV_NAME}} --version $AWS_VERSION_LABEL --timeout 20 | |
echo "Deploy finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment