-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (64 loc) · 2.66 KB
/
deploy.yml
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
#Location: .github/workflows/custom_config.yml
name: CI-CD pipeline to AWS
env:
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
EB_S3_BUCKET_NAME: "elasticbeanstalk-us-east-2-486795723792"
EB_APPLICATION_NAME: "huzaifazahoor-app"
EB_ENVIRONMENT_NAME: "Huzaifazahoor-app-env"
DEPLOY_PACKAGE_NAME: "django-app-${{ github.sha }}.zip"
VERSION_NAME: ${{ github.sha }}
AWS_REGION_NAME: "us-east-2"
on:
push:
branches:
- main #Use your own branch here (Might be staging or testing)
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Git clone on our repo
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect static files
run: python manage.py collectstatic --noinput
- name: Create zip deployment package
run: zip -r ${{ env.DEPLOY_PACKAGE_NAME }} ./ -x *.git*
- 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_NAME }}
- name: Copying file to S3
run: aws s3 cp ${{ env.DEPLOY_PACKAGE_NAME }} s3://${{ env.EB_S3_BUCKET_NAME }}/
- name: Print nice message on success finish
run: echo "CI part finished successfuly"
deploy:
runs-on: ubuntu-latest
needs: [build]
steps:
- 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_NAME }}
- name: Create new EBL app ver
run: |
aws elasticbeanstalk create-application-version \
--application-name ${{ env.EB_APPLICATION_NAME }} \
--source-bundle S3Bucket="${{ env.EB_S3_BUCKET_NAME }}",S3Key="${{ env.DEPLOY_PACKAGE_NAME }}" \
--version-label "${{ env.VERSION_NAME }}"
- name: Deploy new app
run: |
aws elasticbeanstalk update-environment --environment-name ${{ env.EB_ENVIRONMENT_NAME }} --version-label "${{ env.VERSION_NAME }}" \
--option-settings Namespace=aws:elasticbeanstalk:application:environment,OptionName=DJANGO_SECRET_KEY,Value="${{ env.DJANGO_SECRET_KEY }}"
- name: Print nice message on success finish
run: echo "CD part finished successfuly"