Deployment (for Mac & Linux)

Heroku

Create a new IAM User for aws

Go on create new IAM user to create a new IAM User for your S3 Bucket.

At first enter a User name` and activate Programmatic access and than on Next: Permission button.

_images/iam-create-01.png

On the next page Set permissions for YourNewIamUser just click on Next: Review without to add any group or policies.

_images/iam-create-02.png

On Review ignore the warning This user has no permissions and click on Create User.

_images/iam-create-03.png

On the last page write down your new Access key ID & Secret access key to use it later on the deployment. And in the end click on Close

_images/iam-create-04.png

Now get the User ARN, for that click on your new created user.

_images/iam-create-05.png

In the Summary page you will see the user ARN, also write it down for using to setup your S3 Bucket.

_images/iam-create-06.png

Setup a S3 Bucket

To create a S3 Bucket for the media & static files go on create new S3 Bucket and click on + Create bucket.

_images/s3-create-01.png

In the following wizard enter your Bucket name and select your Region than click on Next.

_images/s3-create-02.png

On the next page ‘Set properties’ just click on Next.

_images/s3-create-03.png

And again on ‘Set permission’ just click on Next.

_images/s3-create-04.png

For the last time ‘Review’ just click on Create Bucket.

_images/s3-create-05.png

So after the Bucket is created click on your new Bucket in the list and on the right side click on Permissions.

_images/s3-create-06.png

At next click on Bucket Policy and write down the following policy.

Importent change BUCKET-NAME with your Bucket name and USER-ARN with your just befor created user.

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKET-NAME/*"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "USER-ARN"
            },
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::BUCKET-NAME",
                "arn:aws:s3:::BUCKET-NAME/*"
            ]
        }
    ]
}

Cors Setup

<CORSConfiguration>
  <CORSRule>
      <AllowedOrigin>*</AllowedOrigin>
      <AllowedMethod>GET</AllowedMethod>
      <MaxAgeSeconds>3000</MaxAgeSeconds>
      <AllowedHeader>Authorization</AllowedHeader>
  </CORSRule>
</CORSConfiguration>

Policy & Cors by Wagtail.io: Wagtail.io Blog - Amazon S3

_images/s3-create-06.png

Heroku Deployment

Official Tutorial from Heroku: https://devcenter.heroku.com/articles/deploying-python

Create a Heroku App

$ heroku login
Enter your Heroku credentials.
...
$ heroku create --region eu
Creating intense-falls-9163... done, stack is cedar
http://intense-falls-9163.herokuapp.com/ | git@heroku.com:intense-falls-9163.git
Git remote heroku added
$ git push heroku master
...
-----> Python app detected
...
-----> Launching... done, v7
       https://intense-falls-9163.herokuapp.com/ deployed to Heroku

Setup Enviroment

Run the setup_heroku.sh bash script to setup the environment for the heroku instance.

$ ./setup_heroku.sh

Fill the Database & Upload the Static files

$ heroku run python manage.py collectstatic --noinput
$ heroku run python manage.py createsuperuser
$ heroku run python manage.py oscar_populate_countries

Show if anything work’s fine

$ heroku info

Continuous Deployment

To enable Continuous Deployment on Bitbucket.com enable Piples in your Bitbucket project & set the enviarables `HEROKU_APP_NAME` & `HEROKU_API_KEY`

More details: https://bitbucket.org/spittet/heroku-deploy

Push Updates (CLI)

This is only if you want to push updates via the CLI

$ git add -A
$ git commit -m "your update"
$ git commit -m "your update"
$ heroku run python manage.py collectstatic --noinput
$ heroku run python manage.py migrate
$ heroku run python manage.py createsuperuser