-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (67 loc) · 2.49 KB
/
cd-aws-eb.yml
File metadata and controls
77 lines (67 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Deploy to AWS Elastic Beanstalk
on:
workflow_call:
# inputs:
# config-path:
# required: true
# type: string
secrets:
GITHUB_CONTAINER_REGISTRY_TOKEN:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_REGION:
required: true
AWS_S3_BUCKET:
required: true
EB_APPLICATION_NAME:
required: true
EB_ENVIRONMENT_NAME:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
# environment: production
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
- name: Set up AWS CLI
uses: aws-actions/configure-aws-credentials@v4.2.1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set deployment variables
id: vars
run: |
echo "DEPLOY_PACKAGE=${{ github.event.repository.name }}-${{ github.sha }}.zip" >> $GITHUB_ENV
- name: Zip project for deployment
run: |
zip -r $DEPLOY_PACKAGE . -x "node_modules/*" ".next/*" "Dockerfile*" "docker-compose*" "*.zip" ".git/*"
- name: Upload deployment package to S3
run: |
aws s3 cp $DEPLOY_PACKAGE s3://${{ secrets.AWS_S3_BUCKET }}/$DEPLOY_PACKAGE
- name: Create new Elastic Beanstalk Application Version
run: |
aws elasticbeanstalk create-application-version \
--application-name ${{ secrets.EB_APPLICATION_NAME }} \
--source-bundle S3Bucket="${{ secrets.AWS_S3_BUCKET }}",S3Key="$DEPLOY_PACKAGE" \
--version-label "ver-${{ github.sha }}" \
--description "commit-sha-${{ github.sha }}"
- name: Deploy new Application Version
run: |
aws elasticbeanstalk update-environment \
--environment-name ${{ secrets.EB_ENVIRONMENT_NAME }} \
--version-label "ver-${{ github.sha }}"
- name: Wait for deployment to complete
run: |
aws elasticbeanstalk wait environment-updated \
--environment-name ${{ secrets.EB_ENVIRONMENT_NAME }}
- name: Get deployment status
run: |
aws elasticbeanstalk describe-environments \
--environment-names ${{ secrets.EB_ENVIRONMENT_NAME }} \
--query 'Environments[0].{Status:Status,Health:Health,URL:CNAME}' \
--output table