47
loading...
This website collects cookies to deliver better user experience
.github
. And one more folder inside it called workflows. GitHub Actions config should be placed inside and formatted with YAML syntax. See my example below:#Location: .github/workflows/custom_config.yml
name: CI-CD pipeline to AWS
env:
EB_S3_BUCKET_NAME: "YOUR BUCKET NAME FROM Step 2"
EB_APPLICATION_NAME: "YOUR APP NAME FROM Step 1"
EB_ENVIRONMENT_NAME: "YOUR ENVIRONMENT NAME FROM Step 1"
DEPLOY_PACKAGE_NAME: "django-app-${{ github.sha }}.zip"
AWS_REGION_NAME: "YOUR AWS REGION ("us-east-1"/"eu-central-1" etc.)"
on:
push:
branches:
- master #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: 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 "${{ github.sha }}"
- name: Deploy new app
run: aws elasticbeanstalk update-environment --environment-name ${{ env.EB_ENVIRONMENT_NAME }} --version-label "${{ github.sha }}"
- name: Print nice message on success finish
run: echo "CD part finished successfuly"
secrets.aws_access_key_id
or secrets.aws_secret_access_key
yet. 🧊 Let's fix that!aws_secret_access_key and
it's value. That's it!# main_django_app settings.py
import os
ALLOWED_HOSTS = ['YOUR_ENVIRONMENT_HOST']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
# rest of the settings
.ebextensions
and place there a file 01_packages.config
:packages:
yum:
amazon-linux-extras: []
commands:
01_postgres_activate:
command: sudo amazon-linux-extras enable postgresql10
02_postgres_install:
command: sudo yum install -y postgresql-devel
.ebextensions
folder called django.config
:option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: main_django_app.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: main_django_app.settings
"PYTHONPATH": "/var/app/current:$PYTHONPATH"
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
aws:elasticbeanstalk:environment:proxy:staticfiles0:
tells which folder to serve through the reverse proxy and which relative URL to use.pip freeze > requirements.txt
(it will be the primary source for Beanstalk to configure EC2 environment)..platform
with the following structure:.platform/
└───hooks/
└───postdeploy/
-01_django.sh
#!/bin/bash
source /var/app/venv/*/bin/activate && {
# collecting static files
python manage.py collectstatic --noinput;
# log which migrations have already been applied
python manage.py showmigrations;
# migrate the rest
python manage.py migrate --noinput;
# another command to create a superuser (write your own)
}
ALLOWED_HOSTS = ['*']
at your own risk).pip install psycopg2-binary
and freeze the requirements.txt.