├── .gitignore
├── .meteor
├── .finished-upgraders
├── .gitignore
├── .id
├── packages
├── platforms
├── release
└── versions
├── Makefile
├── README.md
├── client
├── main.css
├── main.html
└── main.js
├── coldbrew.conf
├── deploy
├── Dockerfile
└── script
│ ├── lib
│ ├── build_app.sh
│ ├── cleanup.sh
│ ├── install_base.sh
│ ├── install_meteor.sh
│ ├── install_node.sh
│ └── install_phantomjs.sh
│ └── run_app.sh
├── package.json
└── server
└── main.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/.meteor/.finished-upgraders:
--------------------------------------------------------------------------------
1 | # This file contains information which helps Meteor properly upgrade your
2 | # app when you run 'meteor update'. You should check it into version control
3 | # with your project.
4 |
5 | notices-for-0.9.0
6 | notices-for-0.9.1
7 | 0.9.4-platform-file
8 | notices-for-facebook-graph-api-2
9 | 1.2.0-standard-minifiers-package
10 | 1.2.0-meteor-platform-split
11 | 1.2.0-cordova-changes
12 | 1.2.0-breaking-changes
13 | 1.3.0-split-minifiers-package
14 | 1.4.0-remove-old-dev-bundle-link
15 | 1.4.1-add-shell-server-package
16 |
--------------------------------------------------------------------------------
/.meteor/.gitignore:
--------------------------------------------------------------------------------
1 | local
2 |
--------------------------------------------------------------------------------
/.meteor/.id:
--------------------------------------------------------------------------------
1 | # This file contains a token that is unique to your project.
2 | # Check it into your repository along with the rest of this directory.
3 | # It can be used for purposes such as:
4 | # - ensuring you don't accidentally deploy one app on top of another
5 | # - providing package authors with aggregated statistics
6 |
7 | 1yt916p1020zel13kncmf
8 |
--------------------------------------------------------------------------------
/.meteor/packages:
--------------------------------------------------------------------------------
1 | # Meteor packages used by this project, one per line.
2 | # Check this file (and the other files in this directory) into your repository.
3 | #
4 | # 'meteor add' and 'meteor remove' will edit this file for you,
5 | # but you can also edit it by hand.
6 |
7 | meteor-base@1.0.4 # Packages every Meteor app needs to have
8 | mobile-experience@1.0.4 # Packages for a great mobile UX
9 | mongo@1.1.14 # The database Meteor supports right now
10 | blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
11 | reactive-var@1.0.11 # Reactive variable for tracker
12 | jquery@1.11.10 # Helpful client-side library
13 | tracker@1.1.1 # Meteor's client-side reactive programming library
14 |
15 | standard-minifier-css@1.3.2 # CSS minifier run for production mode
16 | standard-minifier-js@1.2.1 # JS minifier run for production mode
17 | es5-shim@4.6.15 # ECMAScript 5 compatibility for older browsers.
18 | ecmascript@0.5.9 # Enable ECMAScript2015+ syntax in app code
19 | shell-server@0.2.1 # Server-side component of the `meteor shell` command
20 |
21 | autopublish@1.0.7 # Publish all data to the clients (for prototyping)
22 | insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
23 |
--------------------------------------------------------------------------------
/.meteor/platforms:
--------------------------------------------------------------------------------
1 | server
2 | browser
3 |
--------------------------------------------------------------------------------
/.meteor/release:
--------------------------------------------------------------------------------
1 | METEOR@1.4.2
2 |
--------------------------------------------------------------------------------
/.meteor/versions:
--------------------------------------------------------------------------------
1 | allow-deny@1.0.5
2 | autopublish@1.0.7
3 | autoupdate@1.2.11
4 | babel-compiler@6.13.0
5 | babel-runtime@0.1.13
6 | base64@1.0.10
7 | binary-heap@1.0.10
8 | blaze@2.1.9
9 | blaze-html-templates@1.0.5
10 | blaze-tools@1.0.10
11 | boilerplate-generator@1.0.11
12 | caching-compiler@1.1.8
13 | caching-html-compiler@1.0.7
14 | callback-hook@1.0.10
15 | check@1.2.4
16 | ddp@1.2.5
17 | ddp-client@1.2.9
18 | ddp-common@1.2.7
19 | ddp-server@1.2.10
20 | deps@1.0.12
21 | diff-sequence@1.0.7
22 | ecmascript@0.5.9
23 | ecmascript-runtime@0.3.15
24 | ejson@1.0.13
25 | es5-shim@4.6.15
26 | fastclick@1.0.13
27 | geojson-utils@1.0.10
28 | hot-code-push@1.0.4
29 | html-tools@1.0.11
30 | htmljs@1.0.11
31 | http@1.1.8
32 | id-map@1.0.9
33 | insecure@1.0.7
34 | jquery@1.11.10
35 | launch-screen@1.0.12
36 | livedata@1.0.18
37 | logging@1.1.16
38 | meteor@1.6.0
39 | meteor-base@1.0.4
40 | minifier-css@1.2.15
41 | minifier-js@1.2.15
42 | minimongo@1.0.18
43 | mobile-experience@1.0.4
44 | mobile-status-bar@1.0.13
45 | modules@0.7.7
46 | modules-runtime@0.7.7
47 | mongo@1.1.14
48 | mongo-id@1.0.6
49 | npm-mongo@2.2.11_2
50 | observe-sequence@1.0.14
51 | ordered-dict@1.0.9
52 | promise@0.8.8
53 | random@1.0.10
54 | reactive-var@1.0.11
55 | reload@1.1.11
56 | retry@1.0.9
57 | routepolicy@1.0.12
58 | shell-server@0.2.1
59 | spacebars@1.0.13
60 | spacebars-compiler@1.0.13
61 | standard-minifier-css@1.3.2
62 | standard-minifier-js@1.2.1
63 | templating@1.2.15
64 | templating-compiler@1.2.15
65 | templating-runtime@1.2.15
66 | templating-tools@1.0.5
67 | tracker@1.1.1
68 | ui@1.0.12
69 | underscore@1.0.10
70 | url@1.0.11
71 | webapp@1.3.12
72 | webapp-hashing@1.0.9
73 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | BUILD_DIR := /tmp/tutorial-meteor
2 |
3 | bundle:
4 | mkdir -p $(BUILD_DIR)
5 | rm -rf $(BUILD_DIR)/bundle
6 | meteor build --directory $(BUILD_DIR)/ --architecture os.linux.x86_64 --server http://localhost:3000 --server-only
7 |
8 | deploy: bundle
9 | cp -rf deploy/* $(BUILD_DIR)/
10 | cp -rf coldbrew.conf $(BUILD_DIR)/
11 | coldbrew deploy --app-dir $(BUILD_DIR) --dockerfile $(BUILD_DIR)/Dockerfile
12 |
13 | .PHONY: deploy bundle
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Tutorial: Running a Meteor app on AWS using coldbrew-cli
2 |
3 | This is a sample project to demonstrate how to run a [Meteor](https://www.meteor.com/) application on AWS using [coldbrew-cli](https://github.com/coldbrewcloud/coldbrew-cli).
4 |
5 | ## Getting Started
6 |
7 | ### Install Docker
8 |
9 | [coldbrew-cli](https://github.com/coldbrewcloud/coldbrew-cli) deploys your application in [Docker containers](https://www.docker.com/what-docker). So the first step is to [install Docker](https://docs.docker.com/engine/installation/) in your system if you don't have it yet.
10 |
11 | ### Install coldbrew-cli
12 |
13 | Download the package for your system [here](https://github.com/coldbrewcloud/coldbrew-cli/wiki/Downloads). It makes things easier if you copy the downloaded binary `coldbrew` (or `coldbrew.exe` on Windows) in your `$PATH`, so you can run `coldbrew` from anywhere. _But it's also okay to keep `coldbrew` executable in your application directory if you want._
14 |
15 | ### AWS Account
16 |
17 | As you will be deploying your application on AWS, you will need an AWS account for sure. [Sign up](https://aws.amazon.com/) if you haven't yet, and get your [AWS access keys](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html). You can pass AWS access keys to **coldbrew-cli** either in [environment variables](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Environment-Variables) or using [CLI flags](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Global-Flags), but we will assume that you set the follow environment variables throughout the tutorial:
18 |
19 | - `$AWS_ACCESS_KEY_ID`: AWS Access Key ID
20 | - `$AWS_SECRET_ACCESS_KEY`: AWS Secret Access Key
21 | - `$AWS_REGION`: AWS region name
22 | - `$AWS_VPC`: AWS VPC ID _(this is completely optional. If you don't specify or don't know your VPC ID, **coldbrew-cli** will automatically use the [default VPC](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/default-vpc.html) of your AWS account.)_
23 |
24 | ### Meteor
25 |
26 | Pretty obvious, but, you will need to [install Meteor](https://www.meteor.com/install) to follow this tutorial.
27 |
28 | ### Clone This Repo
29 |
30 | This tutorial project contains the bare minimum _(but fully functional)_ sample resources so you can get started right away.
31 |
32 | - A sample Meteor application: created by running `meteor create tutorial-meteor`
33 | - [deploy](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/deploy) directory: all deploy related resources including deploy configuration, Dockerfile, and bunch of scripts.
34 | - [coldbrew.conf](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/Makefile): deploy configuration file
35 | - [Makefile](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/Makefile): for Meteor app bundling (`make bundle`) and deployment (`make deploy`)
36 |
37 | _Basically, everything should be the regular Meteor app directory structure except for the `deploy` directory, `coldbrew.conf`, and, `Makefile`._
38 |
39 | Clone this repo:
40 |
41 | ```bash
42 | git clone https://github.com/coldbrewcloud/tutorial-meteor.git
43 | cd tutorial-meteor
44 | ```
45 |
46 | ## Creating Your First Cluster
47 |
48 | **coldbrew-cli** has _very_ simple [concepts](https://github.com/coldbrewcloud/coldbrew-cli/wiki/Concepts): clusters and applications (apps). An app is the minimum deployment unit and _typically_ corresponds to a project (like this tutorial project). And a cluster is simply a collection of apps who will share some AWS resources. _Most importantly they share the Docker hosts (which is ECS Container Instances in the AWS context)._
49 |
50 | Let's create your first cluster `tutorial` using [cluster-create](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-cluster-create) command:
51 |
52 | ```bash
53 | coldbrew cluster-create tutorial --disable-keypair
54 | ```
55 |
56 |
57 |
58 | _*In this tutorial, we used `--disable-keypair` flag to skip assigning EC2 key pairs to the container instances. If you will need direct access to the instances (e.g. via SSH), you can use the `--key` flag to specify your key pair name._
59 |
60 | If you want to check the current running status of your first cluster, you can use [cluster-status](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-cluster-status) command:
61 |
62 | ```bash
63 | coldbrew cluster-status tutorial
64 | ```
65 |
66 | It can take several minutes until the initial ECS Container Instances (EC2 Instances) become fully available, but, you can continue on to start deploying your application.
67 |
68 |
69 |
70 | ## Deploying Your Application
71 |
72 | Now it's time to deploy your app for the first time. All you need is an application [configuration file](https://github.com/coldbrewcloud/coldbrew-cli/wiki/Configuration-File) to define your app's deployment settings. You can easily create it on your own, or you can use [init](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-init) command to generate a proper default configuration for your app. In this tutorial, we provide a sample [coldbrew.conf](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/coldbrew.conf) file so we can start quickly.
73 |
74 | In this tutorial, we will use `make deploy` command to script the typical Meteor app deployment process:
75 |
76 | - Create a temporary build directory (`/tmp/tutorial-meteor`)
77 | - Run `meteor build` to compile, build, and, bundle everything in the temporary build directory (`/tmp/tutorial-meteor/bundle`)
78 | - Copy deployment files to the temporary build directory
79 | - Run `coldbrew deploy` to initiate the deployment process
80 |
81 | See [Makefile](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/Makefile) if you want more details, and feel free to customize the scripts if you want.
82 |
83 | Now let's run it:
84 |
85 | ```bash
86 | make deploy
87 | ```
88 |
89 |
90 |
91 | If you're curious, this is what happens when **coldbrew-cli** initiates the deployment process:
92 |
93 | - **coldbrew-cli** builds local Docker image using [Dockerfile](https://github.com/coldbrewcloud/tutorial-meteor/blob/master/deploy/Dockerfile). _(You can skip this if you provide the local image name using `--docker-image` flag directly.)_
94 | - It pushes the Docker image to the ECR Repository that's created for your application.
95 | - It creates, updates, or configures ECS Task Definition and ECS Service to apply your configurations.
96 | - It also creates or configures an ELB Application Load Balanacer if your application needs a load balancer. _(This tutorial enables the load balancer.)_
97 |
98 | Now let's check the application status using [status](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-status) command:
99 |
100 | ```bash
101 | coldbrew status
102 | ```
103 |
104 |
105 |
106 | It gives you much more details about your application and its related AWS resources.
107 |
108 | _*Again, it will take several minutes until all AWS resources get fully provisioned and become active (especially if you enabled load balancer). But, the next deploys will be much faster, typically within a minute._
109 |
110 | #### Deploying Again
111 |
112 | After the first deploy, whenever you have changes in your code or configurations, you can re-deploy them again using the same [deploy](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-deploy) command. In this example, I made a simple change in `.units` attributes in the configuration file: from `1` tom `2`.
113 |
114 | ```bash
115 | make deploy
116 | ```
117 |
118 |
119 |
120 | This time, you will notice that **coldbrew-cli** did not create a new AWS resources this time because they were already created during the first deploy run. **coldbrew-cli** always tries to minimize the actual AWS changes by analyzing and comparing the current status and the desired status.
121 |
122 | _*Note that not all configuration changes will be applied immediately. See [this](https://github.com/coldbrewcloud/coldbrew-cli/wiki/Configuration-Changes-and-Their-Effects) for more details._
123 |
124 | Let's run [status](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-status) command again:
125 |
126 | ```bash
127 | coldbrew status
128 | ```
129 |
130 |
131 |
132 | ## Testing the Application
133 |
134 | To know if your application is up and running, check [status](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-status) command output:
135 | - Make sure ELB Load Balancer's Status becomes `active`.
136 | - Make sure you have more than 1 ECS Task has running status (`RUNNING/RUNNING`).
137 |
138 | Assuming it's all good, let's test if your Meteor application really works. Again check [status](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-status) command output to find the Load Balancer endpoint _(`http://tutorial-meteor-elb-352619032.us-west-2.elb.amazonaws.com:80` in my example run)_. You should be able to test your app by opening the load balancer endpoint URL in your web browser.
139 |
140 | ## Cleaning Up
141 |
142 | When you no longer need to run your application in AWS, you can use the [delete](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-delete) command to clean up all AWS resources that were used to run your application.
143 |
144 | ```bash
145 | coldbrew delete
146 | ```
147 |
148 |
149 |
150 | _*Note that cleanining up can take several minutes to finish to make sure all AWS resources are properly deleted or updated._
151 |
152 | And, if you need to delete the cluster too, you can [cluster-delete](https://github.com/coldbrewcloud/coldbrew-cli/wiki/CLI-Command:-cluster-delete) command.
153 |
154 | ```bash
155 | coldbrew cluster-delete tutorial
156 | ```
157 |
158 |
159 |
160 | _*For the same reason, cluster delete can take long to finish._
161 |
162 | ## Notes
163 |
164 | - In this tutorial, we didn't use `$MONGO_URL`, but, in production you should set up your own MongoDB cluster (one easy way to do is to use [compose.io](https://compose.io)) and specify its connection URI in `$MONGO_URL`. You can use `env` attribute in the configuration file.
165 |
166 | ---
167 |
168 | That's it for the tutorial. Now you know how to run your Meteor applications on AWS using [coldbrew-cli](https://github.com/coldbrewcloud/coldbrew-cli). Although this tutorial used a sample Meteor application, the deployment workflow of **coldbrew-cli** for other tech stacks is almost the same, as long as you have your Dockerfile in place.
169 |
170 | See [Documentations](https://github.com/coldbrewcloud/coldbrew-cli/wiki) for more details.
171 |
--------------------------------------------------------------------------------
/client/main.css:
--------------------------------------------------------------------------------
1 | /* CSS declarations go here */
2 |
--------------------------------------------------------------------------------
/client/main.html:
--------------------------------------------------------------------------------
1 |
You've pressed the button {{counter}} times.
15 | 16 | 17 | 18 |