This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Recipes | ||
class Deploy < Base | ||
|
||
def initialize(pathfinder, type: 'none') | ||
if !%w(cloud66 docker none).include?(type) | ||
fail 'none, docker or cloud66 are the only allowed options for deploy recipe' | ||
end | ||
super(pathfinder) | ||
@type = type | ||
end | ||
|
||
def init_file | ||
case @type | ||
when 'docker' then docker_config_files | ||
when 'cloud66' then cloud66_config_files | ||
end | ||
end | ||
|
||
private | ||
|
||
def cloud66_config_files | ||
@template.add_file '.cloud66/bower.sh', | ||
relative_file_content('deploy/cloud66/bower.sh') | ||
@template.add_file '.cloud66/cache_permissions.sh', | ||
relative_file_content('deploy/cloud66/cache_permissions.sh') | ||
@template.add_file '.cloud66/deploy_hooks.yml', | ||
relative_file_content('deploy/cloud66/deploy_hooks.yml') | ||
end | ||
|
||
def docker_config_files | ||
@template.add_file 'docker/rails-env.conf', | ||
relative_file_content('deploy/docker/rails-env.conf') | ||
@template.add_file '.dockerignore', | ||
relative_file_content('deploy/docker/.dockerignore') | ||
@template.append_file 'README.md', | ||
relative_file_content('deploy/docker/README.md') | ||
add_file_and_replace_app_name('docker/fix_permissions.sh', | ||
'deploy/docker/fix_permissions.sh') | ||
add_file_and_replace_app_name('Dockerfile', 'deploy/docker/Dockerfile') | ||
add_file_and_replace_app_name('docker/nginx.conf', 'deploy/docker/nginx.conf') | ||
end | ||
|
||
def add_file_and_replace_app_name(target_file, source_file) | ||
@template.add_file target_file, relative_file_content(source_file) | ||
@template.run "sed -i '' 's/app-name/#{@pathfinder.app_name}/g' #{target_file}" | ||
end | ||
|
||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sudo npm install -g bower |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
chown nginx:app_writers $STACK_BASE/shared/cache && chmod 775 $STACK_BASE/shared/cache && sudo chmod g+s $STACK_BASE/shared/cache |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
production: | ||
first_thing: | ||
- snippet: cloud66/node | ||
target: rails | ||
execute: true | ||
- snippet: cloud66/newrelic | ||
target: any | ||
execute: true | ||
- source: /.cloud66/bower.sh | ||
destination: /tmp/bower.sh | ||
target: rails | ||
execute: true | ||
after_rails: | ||
- source: /.cloud66/cache_permissions.sh | ||
destination: /tmp/cache_permissions.sh | ||
target: rails | ||
run_on: all_servers | ||
execute: true | ||
sudo: true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public/uploads | ||
vendor/bundle |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
FROM phusion/passenger-ruby24 | ||
MAINTAINER MarsBased "hola@marsbased.com" | ||
|
||
ENV HOME /home/app/app-name | ||
|
||
# Install software dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y imagemagick | ||
|
||
# Use baseimage-docker's init system. | ||
CMD ["/sbin/my_init"] | ||
|
||
# Expose Nginx HTTP service | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
# Start Nginx / Passenger | ||
RUN rm -f /etc/service/nginx/down | ||
|
||
# Remove the default site | ||
RUN rm /etc/nginx/sites-enabled/default | ||
|
||
# Create app home dir | ||
RUN mkdir -p $HOME | ||
WORKDIR $HOME | ||
|
||
# Install bundle of gems | ||
ADD Gemfile Gemfile | ||
ADD Gemfile.lock Gemfile.lock | ||
RUN bundle install --without development test | ||
|
||
# Add the nginx site and config | ||
ADD docker/nginx.conf /etc/nginx/sites-enabled/app-name.conf | ||
ADD docker/rails-env.conf /etc/nginx/main.d/rails-env.conf | ||
|
||
# Add the Rails app | ||
ADD . /home/app/app-name | ||
|
||
RUN RAILS_ENV=production SECRET_KEY_BASE=NOT-IMPORTANT bin/rake assets:precompile | ||
|
||
# Add a tmp folder for pids | ||
RUN mkdir -p tmp/pids | ||
|
||
# Define volumes | ||
|
||
VOLUME $HOME/public/uploads | ||
VOLUME $HOME/log | ||
|
||
# Configure init scripts | ||
RUN mkdir -p /etc/my_init.d | ||
ADD docker/fix_permissions.sh /etc/my_init.d/fix_permissions.sh | ||
RUN chmod +x /etc/my_init.d/fix_permissions.sh | ||
|
||
RUN chown -R app:app $HOME | ||
|
||
# Clean up APT and bundler when done. | ||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
## Docker | ||
|
||
Production deploys are managed with Docker. The Dockerfile makes use of some config files that can be found in the `docker` folder. | ||
|
||
- **fix_permissions.sh**: Makes the mountable volumes writable for the | ||
application user. | ||
- **rails-env.conf**: Makes env variables visible to Nginx. As the | ||
application is running on Passenger through Nginx, every ENV variable | ||
that needs to reach the application must be defined here. | ||
- **nginx.conf**: Base nginx configuration. The file contains | ||
instructions to tune the application performance. | ||
|
||
It's recommended to use Dockerhub (or a private docker repository) to store the application images and then use docker-compose to orchestrate the deployment. | ||
|
||
The docker-compose file is not included in the project and needs to be | ||
configured on a project basis. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
chown -R app:app /home/app/app-name/public/uploads | ||
chown -R app:app /home/app/app-name/log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
server { | ||
listen 80 default_server; | ||
root /home/app/app-name/public; | ||
passenger_enabled on; | ||
passenger_user app; | ||
passenger_ruby /usr/bin/ruby2.4; | ||
|
||
## Configure this with the same value of the passenger_max_pool_size | ||
# passenger_min_instances 10; | ||
|
||
location ~ ^/assets/ { | ||
expires 1y; | ||
add_header Cache-Control public; | ||
add_header ETag ""; | ||
break; | ||
} | ||
|
||
location ~ ^/uploads/ { | ||
expires 24h; | ||
add_header Cache-Control public; | ||
add_header ETag ""; | ||
break; | ||
} | ||
} | ||
|
||
## The number for max_pool_size should be (TOTAL_RAM * 0.75) / RAM_PER_PROCESS | ||
# passenger_max_pool_size 10; | ||
|
||
## Configure this option with the app host url to preload app after deploy | ||
# passenger_pre_start https://app-name.com; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# List here all the ENV variables that need to be available in the application | ||
# Only ENV variable names are expected, not their values. | ||
# env APP_HOST; |
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