4 | ExampleApp
5 |
11 |
12 |
13 |
14 | <%= yield %>
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | # The priority is based upon order of creation: first created -> highest priority.
3 | # See how all your routes lay out with "rake routes".
4 |
5 | # Simple "Hello, World" page
6 | root 'application#index'
7 |
8 | # This URL is used for health checks
9 | get 'health' => 'application#health'
10 | end
11 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7 | fixtures :all
8 |
9 | # Add more helper methods to be used by all tests here...
10 | end
11 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/ecs-params.yml.template:
--------------------------------------------------------------------------------
1 | version: 1
2 | task_definition:
3 | task_execution_role: $ecsTaskExecutionRole
4 | ecs_network_mode: awsvpc
5 | task_size:
6 | mem_limit: 0.5GB
7 | cpu_limit: 256
8 | run_params:
9 | network_configuration:
10 | awsvpc_configuration:
11 | subnets:
12 | - "$subnet_1"
13 | - "$subnet_2"
14 | - "$subnet_3"
15 | security_groups:
16 | - "$security_group"
17 | assign_public_ip: DISABLED
18 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | ecsdemo-frontend:
4 | environment:
5 | - CRYSTAL_URL=http://ecsdemo-crystal.service:3000/crystal
6 | - NODEJS_URL=http://ecsdemo-nodejs.service:3000
7 | image: brentley/ecsdemo-frontend
8 | ports:
9 | - "3000:3000"
10 | logging:
11 | driver: awslogs
12 | options:
13 | awslogs-group: ecsdemo-frontend
14 | awslogs-region: ${AWS_REGION}
15 | awslogs-stream-prefix: ecsdemo-frontend
16 |
--------------------------------------------------------------------------------
/ecs-params.yml:
--------------------------------------------------------------------------------
1 | version: 1
2 | task_definition:
3 | task_execution_role: ecsTaskExecutionRole
4 | ecs_network_mode: awsvpc
5 | task_size:
6 | mem_limit: 0.5GB
7 | cpu_limit: 256
8 | run_params:
9 | network_configuration:
10 | awsvpc_configuration:
11 | subnets:
12 | - "subnet-07105dbab6f04ae7f"
13 | - "subnet-086d522cc6c273ac1"
14 | - "subnet-0519235cdff9e7013"
15 | security_groups:
16 | - "sg-0e5cd18b6fbb61668"
17 | assign_public_ip: DISABLED
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | # Rails.application.config.assets.precompile += %w( search.js )
12 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
11 | Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) }
12 | gem 'spring', match[1]
13 | require 'spring/binstub'
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require turbolinks
16 | //= require_tree .
17 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 |
4 | # path to your application root.
5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6 |
7 | Dir.chdir APP_ROOT do
8 | # This script is a starting point to setup your application.
9 | # Add necessary setup steps to this file:
10 |
11 | puts "== Installing dependencies =="
12 | system "gem install bundler --conservative"
13 | system "bundle check || bundle install"
14 |
15 | # puts "\n== Copying sample files =="
16 | # unless File.exist?("config/database.yml")
17 | # system "cp config/database.yml.sample config/database.yml"
18 | # end
19 |
20 | puts "\n== Preparing database =="
21 | system "bin/rake db:setup"
22 |
23 | puts "\n== Removing old logs and tempfiles =="
24 | system "rm -f log/*"
25 | system "rm -rf tmp/cache"
26 |
27 | puts "\n== Restarting application server =="
28 | system "touch tmp/restart.txt"
29 | end
30 |
--------------------------------------------------------------------------------
/Dockerfile.cdk:
--------------------------------------------------------------------------------
1 | FROM ruby:2.5-slim
2 |
3 | COPY Gemfile Gemfile.lock /usr/src/app/
4 | WORKDIR /usr/src/app
5 |
6 | RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev python3 python3-pip && \
7 | bundle install && \
8 | pip3 install awscli && \
9 | apt-get autoremove -y --purge && \
10 | apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \
11 | apt-get clean && \
12 | rm -rvf /root/* /root/.gem* /var/cache/*
13 |
14 | COPY . /usr/src/app
15 | RUN chmod +x /usr/src/app/startup-cdk.sh
16 |
17 | # helpful when trying to update gems -> bundle update, remove the Gemfile.lock, start ruby
18 | # RUN bundle update
19 | # RUN rm -vf /usr/src/app/Gemfile.lock
20 |
21 | HEALTHCHECK --interval=10s --timeout=3s \
22 | CMD curl -f -s http://localhost:3000/health/ || exit 1
23 | EXPOSE 3000
24 | ENTRYPOINT ["bash","/usr/src/app/startup-cdk.sh"]
25 |
--------------------------------------------------------------------------------
/kubernetes/deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: ecsdemo-frontend
5 | labels:
6 | app: ecsdemo-frontend
7 | namespace: default
8 | spec:
9 | replicas: 1
10 | selector:
11 | matchLabels:
12 | app: ecsdemo-frontend
13 | strategy:
14 | rollingUpdate:
15 | maxSurge: 25%
16 | maxUnavailable: 25%
17 | type: RollingUpdate
18 | template:
19 | metadata:
20 | labels:
21 | app: ecsdemo-frontend
22 | spec:
23 | containers:
24 | - image: brentley/ecsdemo-frontend:latest
25 | imagePullPolicy: Always
26 | name: ecsdemo-frontend
27 | ports:
28 | - containerPort: 3000
29 | protocol: TCP
30 | env:
31 | - name: CRYSTAL_URL
32 | value: "http://ecsdemo-crystal.default.svc.cluster.local/crystal"
33 | - name: NODEJS_URL
34 | value: "http://ecsdemo-nodejs.default.svc.cluster.local/"
35 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # FROM ruby:2.5-slim
2 | FROM public.ecr.aws/bitnami/ruby:2.5
3 |
4 | COPY Gemfile Gemfile.lock /usr/src/app/
5 | WORKDIR /usr/src/app
6 |
7 | RUN apt-get update && apt-get -y install iproute2 curl jq libgmp3-dev ruby-dev build-essential sqlite libsqlite3-dev python3 python3-pip && \
8 | gem install bundler:1.17.3 && \
9 | bundle install && \
10 | pip3 install awscli netaddr && \
11 | apt-get autoremove -y --purge && \
12 | apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \
13 | apt-get clean && \
14 | rm -rvf /root/* /root/.gem* /var/cache/*
15 |
16 | COPY . /usr/src/app
17 | RUN chmod +x /usr/src/app/startup-cdk.sh
18 |
19 | # helpful when trying to update gems -> bundle update, remove the Gemfile.lock, start ruby
20 | # RUN bundle update
21 | # RUN rm -vf /usr/src/app/Gemfile.lock
22 |
23 | HEALTHCHECK --interval=10s --timeout=3s \
24 | CMD curl -f -s http://localhost:3000/health/ || exit 1
25 | EXPOSE 3000
26 | ENTRYPOINT ["bash","/usr/src/app/startup-cdk.sh"]
27 |
--------------------------------------------------------------------------------
/copilot/ecsdemo-frontend/addons/task-role.yaml:
--------------------------------------------------------------------------------
1 | # You can use any of these parameters to create conditions or mappings in your template.
2 | Parameters:
3 | App:
4 | Type: String
5 | Description: Your application's name.
6 | Env:
7 | Type: String
8 | Description: The environment name your service, job, or workflow is being deployed to.
9 | Name:
10 | Type: String
11 | Description: The name of the service, job, or workflow being deployed.
12 |
13 | Resources:
14 | SubnetsAccessPolicy:
15 | Type: AWS::IAM::ManagedPolicy
16 | Properties:
17 | PolicyDocument:
18 | Version: 2012-10-17
19 | Statement:
20 | - Sid: EC2Actions
21 | Effect: Allow
22 | Action:
23 | - ec2:DescribeSubnets
24 | Resource: "*"
25 |
26 | Outputs:
27 | # You also need to output the IAM ManagedPolicy so that Copilot can inject it to your ECS task role.
28 | SubnetsAccessPolicyArn:
29 | Description: "The ARN of the Policy to attach to the task role."
30 | Value: !Ref SubnetsAccessPolicy
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Brent Langston
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key is used for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 |
6 | # Make sure the secret is at least 30 characters and all random,
7 | # no regular words or you'll be exposed to dictionary attacks.
8 | # You can use `rake secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | development:
14 | secret_key_base: 3007e861284142573607c2c60bc23c02bc5e2df5aa8f3966091ca4a61cf8f6c4f0819911271e83c1086ce3135056caa92b73a055f5edb721d66447addba365d1
15 |
16 | test:
17 | secret_key_base: e0159534f4f0beaf5b838aa81ad072c8e8798ebb6cdc2e1ba610060102ff6fefae02733c9c575f0fe03a2a2528467e59162677f904061be86fdad7e0510ebb73
18 |
19 | # TODO: This value should not be checked into the repo! It's only here to keep this example simple!
20 | production:
21 | secret_key_base: 3007e861284142573607c2c60bc23c02bc5e2df5aa8f3966091ca4a61cf8f6c4f0819911271e83c1086ce3135056caa92b73a055f5edb721d66447addba365d1
22 | # Secrets should be read from the environment!
23 | # secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
24 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | require 'rails/all'
4 |
5 | # Require the gems listed in Gemfile, including any gems
6 | # you've limited to :test, :development, or :production.
7 | Bundler.require(*Rails.groups)
8 |
9 | module ExampleApp
10 | class Application < Rails::Application
11 | # Settings in config/environments/* take precedence over those specified here.
12 | # Application configuration should go into files in config/initializers
13 | # -- all .rb files in that directory are automatically loaded.
14 |
15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
17 | # config.time_zone = 'Central Time (US & Canada)'
18 |
19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
21 | # config.i18n.default_locale = :de
22 |
23 | # Do not swallow errors in after_commit/after_rollback callbacks.
24 | config.active_record.raise_in_transactional_callbacks = true
25 |
26 | # Since we run in a Docker container, always log to stdout
27 | config.logger = Logger.new(STDOUT)
28 | config.logger.level = Logger::ERROR
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 |
4 | gem 'thin'
5 |
6 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
7 | gem 'rails', '4.2.10'
8 | # Use sqlite3 as the database for Active Record
9 | gem 'sqlite3'
10 | # Use SCSS for stylesheets
11 | gem 'sass-rails', '~> 5.0'
12 | # Use Uglifier as compressor for JavaScript assets
13 | gem 'uglifier', '>= 1.3.0'
14 | # Use CoffeeScript for .coffee assets and views
15 | gem 'coffee-rails', '~> 4.1.0'
16 | # See https://github.com/rails/execjs#readme for more supported runtimes
17 | gem 'therubyracer', platforms: :ruby
18 |
19 | gem 'activesupport'
20 |
21 | # Use jquery as the JavaScript library
22 | gem 'jquery-rails'
23 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
24 | gem 'turbolinks'
25 | # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
26 | gem 'jbuilder', '~> 2.0'
27 | # bundle exec rake doc:rails generates the API under doc/api.
28 | gem 'sdoc', '~> 0.4.0', group: :doc
29 |
30 | # Use ActiveModel has_secure_password
31 | # gem 'bcrypt', '~> 3.1.7'
32 |
33 | # Use Unicorn as the app server
34 | # gem 'unicorn'
35 |
36 | # Use Capistrano for deployment
37 | # gem 'capistrano-rails', group: :development
38 |
39 | group :development, :test do
40 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
41 | gem 'byebug'
42 | end
43 |
44 | group :development do
45 | # Access an IRB console on exception pages or by using <%= console %> in views
46 | gem 'web-console', '~> 2.0'
47 |
48 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
49 | gem 'spring'
50 | end
51 |
52 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.