What's wrong in my local_settings / how to do basic deploy to aws

59 views
Skip to first unread message

Wolfgang M

unread,
Apr 16, 2018, 12:23:29 AM4/16/18
to Mezzanine Users
Hello, I saw the recent posts about aws but didn't want to hijack a thread with my own questions. I have an app I really like that I've made with mezzanine, can someone point out what's wrong with my deployment. I'm following the standard deployment in the tutorials and am trying to get it online using aws, either ec2 or elasticbeanstalk.
Also if someone can explain how git works for a deployment that would be great. Do I push my local MyProject folder contents to a repository, then pull that to the ec2, (and separarely transfer local_settings.py to keep secret keys off of git)? Or does the fabric deployment suggest I handle it all remotely and not within an ec2 instance, and if so how does git integrate with fab?

local_settings.py
# This file is exec'd from settings.py, so it has access to and can
# modify all the variables in settings.py.

DEBUG = False

# Make these unique, and don't share it with anybody.
SECRET_KEY = "12345SecretKeyHidden54321"
NEVERCACHE_KEY = "12345NevercacheKeyHidden54321"

DATABASES = {
    "default": {
        # Ends with "postgresql_psycopg2", "mysql", "sqlite3" or "oracle".
        "ENGINE": "postgresql_psycopg2", #django.db.backends.sqlite3
        # DB name or path to database file if using sqlite3.
        "NAME": "", #dev.db
        # Not used with sqlite3.
        "USER": "",
        # Not used with sqlite3.
        "PASSWORD": "",
        # Set to empty string for localhost. Not used with sqlite3.
        "HOST": "",
        # Set to empty string for default. Not used with sqlite3.
        "PORT": "",
    }
}

###################
# DEPLOY SETTINGS #
###################

# Domains for public site
ALLOWED_HOSTS = ["myCustomRoute53domain.me"]

# These settings are used by the default fabfile.py provided.
# Check fabfile.py for defaults.

FABRIC = {
     "DEPLOY_TOOL": "git",  # Deploy with "git", "hg", or "rsync"
     "SSH_USER": "ec2-user",  # VPS SSH username
     "HOSTS": ["54.219.###.###"],  # The IP address of your VPS
     "DOMAINS": ALLOWED_HOSTS,  # Edit domains in ALLOWED_HOSTS
     "REQUIREMENTS_PATH": "requirements.txt",  # Project's pip requirements
     "LOCALE": "en_US.UTF-8",  # Should end with ".UTF-8"
     "DB_PASS": "default",  # Live database password
     "ADMIN_PASS": "default",  # Live admin user password
     "SECRET_KEY": SECRET_KEY,
     "NEVERCACHE_KEY": NEVERCACHE_KEY,
 }


Yellow are the important questions I have, red is values I'm unsure of. I know these are some simple questions, so I'm hoping to figure this out and do a tutorial on it for other beginners. Right now I have my app on my home computer, and I have an ec2 instance open on aws, which I've connected to using the aws CLI to install mezzanine and git in preparation. Thanks in advance to anyone who can help. So far whatever values I put only result in "fab all" and other fab commands hanging with no response.

Kenneth L Bolton

unread,
Apr 16, 2018, 11:57:24 AM4/16/18
to mezzani...@googlegroups.com
Hi Wolfgang,

I wrote a tutorial on doing test deployments from local to a local
Vagrant virtual-machine at
http://bscientific.org/blog/mezzanine-fabric-git-vagrant-joy/
which covers your questions about git. You can definitely use a
local git repository for deployment *if* the server/remote can
find a network route to the local repo. The tutorial is for older
versions of Mezz, but the fundamental ideas have not changed.

More answers inline below. --ken


Wolfgang M <wami...@gmail.com> writes:

> Hello, I saw the recent posts about aws but didn't want to
> hijack a thread
> with my own questions. I have an app I really like that I've
> made with
> mezzanine, can someone point out what's wrong with my
> deployment. I'm
> following the standard deployment in the tutorials and am trying
> to get it
> online using aws, either ec2 or elasticbeanstalk.

Any tutorial for running Django on EC2 should provide a lot of
insight. There is nothing particularly special about Mezzanine.

> Also if someone can explain how git works for a deployment that
> would be
> great. Do I push my local MyProject folder contents to a
> repository, then
> pull that to the ec2, (and separarely transfer local_settings.py
> to keep
> secret keys off of git)? Or does the fabric deployment suggest I
> handle it
> all remotely and not within an ec2 instance, and if so how does
> git
> integrate with fab?

The fabfile is designed to run on whatever machine(s) you are
using for development work, but that can cover a lot of different
locations. Nothing prevents you from doing development work in
prod except perhaps self-preservation.

>
> local_settings.py
>
>> # This file is exec'd from settings.py, so it has access to and
>> can
>> # modify all the variables in settings.py.
>>
>> DEBUG = False
>>
>> # Make these unique, and don't share it with anybody.
>> SECRET_KEY = "12345SecretKeyHidden54321"
>> NEVERCACHE_KEY = "12345NevercacheKeyHidden54321"
>>
>> DATABASES = {
>> "default": {
>> # Ends with "postgresql_psycopg2", "mysql", "sqlite3"
>> or "oracle".
>> "ENGINE": "postgresql_psycopg2",
>> #django.db.backends.sqlite3

This is your local database. Unless you have a postgresql database
running locally, change it to back to `sqlite3`. N.B. these need
to be fully qualified, so
`django.db.backends.postgresql_psycopg2`.

>> # DB name or path to database file if using sqlite3.
>> "NAME": "", #dev.db

Change the above value back to `dev.db` unless you are definitely
using postgresql locally, in which case the value should be the
name of the database. If you don't know, just use SQLite! If you
are using SQLite, comment out the `USER`, `PASSWORD`, `HOST`, and
`PORT` keys below.

>> # Not used with sqlite3.
>> "USER": "",
>> # Not used with sqlite3.
>> "PASSWORD": "",
>> # Set to empty string for localhost. Not used with
>> sqlite3.
>> "HOST": "",
>> # Set to empty string for default. Not used with
>> sqlite3.
>> "PORT": "",
>> }
>> }
>>
>> ###################
>> # DEPLOY SETTINGS #
>> ###################
>>
>> # Domains for public site
>> ALLOWED_HOSTS = ["myCustomRoute53domain.me"]

This should be fine. You might also add `127.0.0.1` and/or
`localhost` for debugging on "locally" on your server.

>>
>> # These settings are used by the default fabfile.py provided.
>> # Check fabfile.py for defaults.
>>
>> FABRIC = {
>> "DEPLOY_TOOL": "git", # Deploy with "git", "hg", or
>> "rsync"
>> "SSH_USER": "ec2-user", # VPS SSH username
>> "HOSTS": ["54.219.###.###"], # The IP address of your VPS
>> "DOMAINS": ALLOWED_HOSTS, # Edit domains in ALLOWED_HOSTS
>> "REQUIREMENTS_PATH": "requirements.txt", # Project's pip
>> requirements
>> "LOCALE": "en_US.UTF-8", # Should end with ".UTF-8"
>> "DB_PASS": "default", # Live database password
>> "ADMIN_PASS": "default", # Live admin user password
>> "SECRET_KEY": SECRET_KEY,
>> "NEVERCACHE_KEY": NEVERCACHE_KEY,
>> }
>>
>>
> Yellow are the important questions I have, red is values I'm
> unsure of. I

Color is a terrible way to differentiate. I'm reading and writing
in emacs, and it is all blue-on-beige for me. My browser doesn't
use Javascript, so I can't read the message through-the-web. Damn
these walled gardens!

> know these are some simple questions, so I'm hoping to figure
> this out and
> do a tutorial on it for other beginners. Right now I have my app
> on my home
> computer, and I have an ec2 instance open on aws, which I've
> connected to
> using the aws CLI to install mezzanine and git in preparation.
> Thanks in

The fabfile installs mezzanine and git as part of the build
process. Installing them yourself isn't gonna get you anywhere,
but sure is a good exercise.

> advance to anyone who can help. So far whatever values I put
> only result in
> "fab all" and other fab commands hanging with no response.

You can `ssh ec2-...@54.219.###.###` no problem?


--
Ken Bolton

Wolfgang M

unread,
Apr 18, 2018, 3:56:44 PM4/18/18
to Mezzanine Users
Yes, now I can ssh in. (Couldn't before without 'ssh -i path/to/key' so I added my .pem to my .ssh/config.)

I did a lot of troubleshooting with my environment, not sure the exact formula but something to do with fabric+future+python2.7 has allowed fabric to work.

Now I can run 'fab all', but after the first line '$ apt-get update -y -q ->' , I am prompted for my "[IP] Login password for 'ec2-user' " which is the standard instance user name. AWS by default doesn't provide a password and handles authentication through a .pem private key, this means I've never set a password for ec2-user.

I've messaged Matt Mansour to see if in his experience with AWS he has to configure anything specifically. I've tried setting a password for ec2-user within my instance and using that but it doesn't pass.

Thanks for the help above, I've sorted out my ssh and fabric issues, but now I think I'm dealing with more aws specific configuration than anything else.

Matt Mansour

unread,
Apr 18, 2018, 8:23:46 PM4/18/18
to mezzani...@googlegroups.com
This post helped me in setting up my user for the ec2 instance. 


--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Hoffmann

unread,
Apr 20, 2018, 3:34:53 AM4/20/18
to Mezzanine Users

Hello Wolfang,

for AWS you need to configure fabric to use key based login:

Try to add the SSH_KEY_PATH Variable to your local_settings.py.
FABRIC = {
"SSH_USER": "ubuntu", # SSH username
"SSH_PASS":  "", # SSH password (consider key-based authentication)
"SSH_KEY_PATH":  "/Users/myaccount/.myaws-keys/my-aws-key-frankfurt-1.pem", # Local path to SSH key file, for key-based auth
"HOSTS": ['ec2-xx-xx-xxx.eu-central-1.compute.amazonaws.com',], # List of hosts to deploy to
.....
}


Be aware of the following: Amazon Linux IS NOT Ubuntu Linux. 

All the fabric def functions() for server deployment in the default mezzanine fabfile are for UBUNTU. 
Ubuntu uses "apt-get", but Amazon Linux is using "yum" - if you need Amazon Linux, you must rewrite the fabfile.  

Perhaps better try Ubuntu 16.04 AMI for your first deployment. -- Christian

Wolfgang M

unread,
Apr 23, 2018, 3:13:34 PM4/23/18
to Mezzanine Users

You were perfectly right Christian. I needed the ssh_user:ubuntu and ssh_key_path settings in my fabric local_settings. Also Amazon Linux is RHEL based and uses yum not apt-get. 


Those changes allowed me to run fab all.


I have some more questions about content deployment since after my deploy I thought it hadn't worked as my local edits weren't deployed. I'll try and sort that out on a relevant thread.

Eduardo Rivas

unread,
Apr 23, 2018, 3:18:36 PM4/23/18
to mezzani...@googlegroups.com

Hi Wolfgang.

Production and development databases are kept separate, as well as media uploads. If you'd like to upload your database and media files from dev to prod you can add custom fabric tasks that do so.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages