Trying to set up a Meteor on an AWS/EBS (Amazon Web Services, Elastic Beanstalk) environment.
A Meteor dev-run can be passed a command line flag: --settings s
NEW SOLUTION
This is thet easier way I'm able to come with. I've made a bash script that automatically generates a compressed build of your project and integrates the settings file so you don't really have to do anything.
BEFORE TO RUN THIS SCRIPT
In your meteor project create ./lib/beanstalk-settings-fix.js
/*==============================================================================
* Globals
*============================================================================*/
/*global process*/
/*global Meteor*/
/*global Npm*/
if (Meteor.isProduction){
var meteorFile = process.env.METEOR_SETTINGS_FILE;
if(meteorFile == undefined) throw new Error(
'METEOR_SETTINGS_FILE env variable must be defined in production.')
var fs = Npm.require('fs');
var pjsonBuf = fs.readFileSync( meteorFile );
Meteor.settings = JSON.parse( pjsonBuf.toString().trim());
}
HOW TO USE IT
You'll end with something like project-name.zip ready to upload it to your beanstalk environment. I hope you find it useful!
This solution is based on AWS forums. If you want to check the old solutions, please check the edit history.
#!/bin/bash
#===============================================================================
# DESCRIPTION:
#===============================================================================
# This script creates a build of the project ready to be uploaded to beanstalk.
# Requires pyton 2.7.x
#===============================================================================
# COMMON ISSUES:
#===============================================================================
# -If you upload the output to a sample application, it will fail.
# -Version format must be 0.0.0
#===============================================================================
# CONSTANTS
#===============================================================================
CURRENT_VERSION="1.0.0"
OUTPUT_NAME="file-name-without-extension"
PRODUCTION_SETTINGS_JSON="./your-project-directory/settings-prod.json"
PROJECT_DIRECTORY="./your-project-directory"
OUTPUT_DIRECTORY="./the-output-directory"
ROOT_URL="http://www.SOMEENVIRONMENT-env.us-west-2.elasticbeanstalk.com"
MONGO_URL="none"
#===============================================================================
# SAY HELLO
#===============================================================================
initial_directory=$(pwd) # This file's local path
clear
echo "COOKING OUTPUT"
echo "========================================================="
#===============================================================================
# RAW PROJECT BUILD
#===============================================================================
echo "> BUILDING RAW PROJECT"
cd $initial_directory
cd $PROJECT_DIRECTORY
rm -f -R "../build/bundle"
meteor build --directory ../build/
#===============================================================================
# SET PRODUCTION ENVIRONMENT VARIABLES
#===============================================================================
cd $initial_directory
json=`cat $PRODUCTION_SETTINGS_JSON`
cd $OUTPUT_DIRECTORY/bundle
mkdir -p .ebextensions
echo "option_settings:" >> .ebextensions/environment.config
echo " - option_name: MONGO_URL" >> .ebextensions/environment.config
echo " value: $MONGO_URL" >> .ebextensions/environment.config
echo "option_settings:" >> .ebextensions/environment.config
echo " - option_name: ROOT_URL" >> .ebextensions/environment.config
echo " value: "$ROOT_URL"" >> .ebextensions/environment.config
echo "files:" >> .ebextensions/environment.config
echo " '/tmp/settings.json':" >> .ebextensions/environment.config
echo " content : |" >> .ebextensions/environment.config
echo " "$json >> .ebextensions/environment.config
echo "option_settings:" >> .ebextensions/environment.config
echo " - namespace: aws:elasticbeanstalk:application:environment" >> .ebextensions/environment.config
echo " option_name: METEOR_SETTINGS_FILE" >> .ebextensions/environment.config
echo " value: '/tmp/settings.json'" >> .ebextensions/environment.config
chmod 444 .ebextensions/environment.config
echo "> ADDING 'settings.json' AS ENV VAR"
#===============================================================================
# CREATE PACKAGE.JSON
#===============================================================================
cd $initial_directory
cd $OUTPUT_DIRECTORY/bundle
# Write base package.json
echo '{
"name": "'$OUTPUT_NAME'",
"version": "'$CURRENT_VERSION'",
"scripts": {
"start": "node main.js"
},
"dependencies": {
}
}' > ./package.json
# Add dependencies from meteor in packages.json
# Then add extra dependencies defined by us.
EXTRA_DEPENDENCIES='{"forever": "*"}'
meteor_packages=$(cat ./programs/server/package.json)
packages=$(cat ./package.json)
packages_updated=`python < ./package.json
chmod 444 ./package.json
echo "> ADDING 'package.json'"
#===============================================================================
# ZIP OUTPUT
#===============================================================================
cd $initial_directory
cd $OUTPUT_DIRECTORY/bundle
zip -FSrq "../$OUTPUT_NAME-$CURRENT_VERSION.zip" .
echo "> ZIP THE OUTPUT"
#===============================================================================
# CLEAN THE HOUSE
#===============================================================================
cd $initial_directory
cd $OUTPUT_DIRECTORY
rm -R -f ./bundle
echo "> CLEAN THE HOUSE"
#===============================================================================
# SAY GOODBYE
#===============================================================================
echo "========================================================="
echo "YOU CAN UPLOAD THE PROJECT TO A BEANSTALK ENVIRONMENT NOW"
Some extra help: In case you want to check that everything went fine, you can find your final settings in your zipped output, under /.ebextensions/environment.config and your packages file under /package.json