-
-
Save tuantranf/29964c8942b9ba816bad06b539f1765f to your computer and use it in GitHub Desktop.
Installing node and npm on a Django AWS ElasticBeanstalk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This specifies the deployment process on AWS ElasticBeanstalk for a Django app using npm and Postgres. | |
# | |
# The target environment should have access to a Postgres Database through environment variables. | |
# The environment can be setup using `eb create --database.engine=postgres` | |
# The necessary environment variables to access the database will be automatically defined on the | |
# instances of that environment. | |
# | |
# In addition, the target environment should define environment variables (django secret key ...). | |
# They can be manually defined using the AWS ElasticBeanstalk interface on the web. | |
# They can also be specified when creating the environment from command line, for example: | |
# ``` | |
# eb create --database.engine=postgres --envvars ENVVAR1=value,ENVVAR2=value | |
# ``` | |
# | |
packages: | |
yum: | |
git: [] | |
postgresql93-devel: [] | |
commands: | |
01_node_install: | |
cwd: /tmp | |
test: '[ ! -f /usr/bin/node ] && echo "node not installed"' | |
command: 'yum install -y nodejs --enablerepo=epel' | |
02_npm_install: | |
cwd: /tmp | |
test: '[ ! -f /usr/bin/npm ] && echo "npm not installed"' | |
command: 'curl -L http://npmjs.org/install.sh | sh' | |
03_node_update: | |
cwd: /tmp | |
test: '[ ! -f /usr/bin/n ] && echo "node not updated"' | |
command: 'npm install -g n && n stable' | |
option_settings: | |
"aws:elasticbeanstalk:application:environment": | |
# your settings module here | |
DJANGO_SETTINGS_MODULE: "server.settings_prod" | |
# add the path to the root of your django app | |
# note that this is the path on the target machine | |
# EB will deploy your application in /opt/python/current on the target machines | |
PYTHONPATH: "/opt/python/current/app/server:$PYTHONPATH" | |
"aws:elasticbeanstalk:container:python": | |
# path to your wsgi.py file from the root folder of your application | |
WSGIPath: server/server/wsgi.py | |
NumProcesses: 3 | |
NumThreads: 20 | |
"aws:elasticbeanstalk:container:python:staticfiles": | |
"/static/": "www/static/" | |
# These commands will be run just before the application is started | |
container_commands: | |
01_migrate: | |
command: 'python server/manage.py migrate --noinput' | |
leader_only: true | |
# You can create a "createadmin" command to create a super user automatically | |
# You can use environment variables to define the credentials of the super user | |
# If you don't use a createadmin command, delete this command. | |
02_createadmin: | |
command: 'python server/manage.py createadmin' | |
leader_only: true | |
# You can define a build script in packages.json (using gulp, grunt...) to build your client side files | |
03_npm_build: | |
command: 'npm install && npm run build' | |
04_collectstatic: | |
command: 'python server/manage.py collectstatic --noinput' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment