dockerize-stack 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails/dockerize_rails.rb +38 -12
- data/lib/rails/templates/config/database-docker.yml.erb +4 -1
- data/lib/rails/templates/docker/Dockerfile.production.erb +89 -0
- data/lib/rails/templates/docker/kubernetes/scripts/deploy.sh +5 -0
- data/lib/rails/templates/docker/kubernetes/scripts/get-secrets.sh +1 -0
- data/lib/rails/templates/docker/kubernetes/scripts/remoteconsole.sh +2 -0
- data/lib/rails/templates/docker/kubernetes/scripts/set-config-map.sh +4 -0
- data/lib/rails/templates/docker/kubernetes/scripts/set-secrets.sh +5 -0
- data/lib/rails/templates/docker/kubernetes/scripts/set-services.sh +2 -0
- data/lib/rails/templates/docker/kubernetes/scripts/set-workloads.sh +2 -0
- data/lib/rails/templates/docker/kubernetes/services/cloudsql-proxy.yaml +12 -0
- data/lib/rails/templates/docker/kubernetes/services/rails-nginx.yaml +14 -0
- data/lib/rails/templates/docker/kubernetes/workloads/cloudsql-proxy.yaml +32 -0
- data/lib/rails/templates/docker/kubernetes/workloads/rails-nginx.yaml +26 -0
- data/lib/rails/templates/docker/production/dockerbuild.sh +41 -0
- data/lib/rails/templates/docker/production/nginx/Dockerfile +13 -0
- data/lib/rails/templates/docker/production/nginx/entrypoint.sh +3 -0
- data/lib/rails/templates/docker/production/nginx/etc/nginx/conf.d/default.conf +34 -0
- data/lib/rails/templates/docker/production/nginx/etc/nginx/nginx.conf +36 -0
- data/lib/rails/templates/docker/production/rails/entrypoint.sh +7 -0
- data/lib/rails/templates/docker-compose.yml.erb +1 -1
- data/lib/version.rb +1 -1
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b14e1b24576d14cc0369d810fef3f45c6f1b1bf
|
4
|
+
data.tar.gz: a4a2b169b1142db89fb3b966dc4c1e2527e9eb20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c0180e7f0245a6b92d75f765343126dd99de7626baa94fd725fc275b6002876e88ac5c26efc724a02bf87f61fe1363e14ba1fbe3714f92b182bef2d9a389dd6
|
7
|
+
data.tar.gz: 9bca13913d4da030c5579834cc0cec3973b23ad45ab47f847c4e37e9aeeaae866273686923b677d68dd194b62eb18c34c45fd6516d1f6451e49014fceb26a86c
|
@@ -4,6 +4,7 @@ class DockerizeRails < Thor
|
|
4
4
|
include Thor::Actions
|
5
5
|
attr_accessor :ruby_version, :database, :id_rsa
|
6
6
|
|
7
|
+
WORKDIR = ".".freeze
|
7
8
|
|
8
9
|
def self.source_root
|
9
10
|
File.dirname(__FILE__)
|
@@ -17,6 +18,9 @@ class DockerizeRails < Thor
|
|
17
18
|
id_rsa = ask('Would you need your id_rsa file to connect with GitHub? Type yes or no (default no):')
|
18
19
|
id_rsa = 'no' if id_rsa == ''
|
19
20
|
render_templates(ruby_version: ruby_version, database: database, id_rsa: id_rsa)
|
21
|
+
render_production_templates(ruby_version: ruby_version, database: database, id_rsa: id_rsa)
|
22
|
+
|
23
|
+
puts 'Update your database.yml based in database-docker.yml'
|
20
24
|
end
|
21
25
|
|
22
26
|
no_commands do
|
@@ -25,22 +29,44 @@ class DockerizeRails < Thor
|
|
25
29
|
@database = database
|
26
30
|
@id_rsa = id_rsa
|
27
31
|
|
28
|
-
template 'templates/docker/development/Dockerfile.erb',
|
29
|
-
template 'templates/docker/development/entrypoint.sh.erb',
|
30
|
-
template 'templates/docker-compose.yml.erb',
|
31
|
-
template 'templates/config/database-docker.yml.erb',
|
32
|
-
template 'templates/dockerignore.erb',
|
33
|
-
|
34
|
-
append_to_file '.gitignore', '
|
32
|
+
template 'templates/docker/development/Dockerfile.erb', "#{WORKDIR}/docker/development/Dockerfile"
|
33
|
+
template 'templates/docker/development/entrypoint.sh.erb', "#{WORKDIR}/docker/development/entrypoint.sh"
|
34
|
+
template 'templates/docker-compose.yml.erb', "#{WORKDIR}/docker-compose.yml"
|
35
|
+
template 'templates/config/database-docker.yml.erb', "#{WORKDIR}/config/database-docker.yml"
|
36
|
+
template 'templates/dockerignore.erb', "#{WORKDIR}/.dockerignore"
|
37
|
+
append_or_create "#{WORKDIR}/.gitignore", '
|
35
38
|
volumes'
|
36
39
|
if @id_rsa == 'yes'
|
37
|
-
template 'templates/id_rsa.sample',
|
38
|
-
|
39
|
-
id_rsa
|
40
|
-
|
41
|
-
|
40
|
+
template 'templates/id_rsa.sample', "#{WORKDIR}/id_rsa.sample"
|
41
|
+
append_or_create "#{WORKDIR}/.gitignore", '
|
42
|
+
id_rsa
|
43
|
+
id_rsa.sample
|
44
|
+
'
|
42
45
|
end
|
43
46
|
puts 'Update your database.yml based in database-docker.yml'
|
44
47
|
end
|
48
|
+
|
49
|
+
def render_production_templates(ruby_version: '2.5.1-slim', database: 'postgresql', id_rsa: 'no')
|
50
|
+
response = ask("You want generate docker-stack for production?")
|
51
|
+
return false unless response
|
52
|
+
@ruby_version = ruby_version
|
53
|
+
@database = database
|
54
|
+
@id_rsa = id_rsa
|
55
|
+
|
56
|
+
directory 'templates/docker/production', "#{WORKDIR}/docker/production"
|
57
|
+
directory 'templates/docker/kubernetes', "#{WORKDIR}/docker/kubernetes"
|
58
|
+
|
59
|
+
template 'templates/docker/Dockerfile.production.erb', "#{WORKDIR}/docker/production/rails/Dockerfile"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def append_or_create(file_path, file_content)
|
66
|
+
if File.exist?(file_path)
|
67
|
+
append_to_file file_path, file_content
|
68
|
+
else
|
69
|
+
create_file file_path, file_content
|
70
|
+
end
|
45
71
|
end
|
46
72
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
FROM ruby:<%= ruby_version %> as builder
|
2
|
+
|
3
|
+
ENV RAILS_ENV=production
|
4
|
+
ENV NODE_ENV=production
|
5
|
+
|
6
|
+
# install common dev libs
|
7
|
+
RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y \
|
8
|
+
build-essential \
|
9
|
+
apt-transport-https \
|
10
|
+
git \
|
11
|
+
curl
|
12
|
+
<% if database == "mysql" %>
|
13
|
+
# install mysql
|
14
|
+
RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y libmysqlclient-dev mysql-client
|
15
|
+
<% elsif database == "postgresql" %>
|
16
|
+
# install postgresql
|
17
|
+
RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y libpq-dev postgresql-client
|
18
|
+
<% end %>
|
19
|
+
# install node 8.9.1 LTS
|
20
|
+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bin/bash - \
|
21
|
+
&& apt-get update -qq && apt-get dist-upgrade -y && apt-get update && apt-get install -y nodejs
|
22
|
+
|
23
|
+
# install yarn
|
24
|
+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
|
25
|
+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
|
26
|
+
&& apt-get update && apt-get dist-upgrade -y && apt-get update && apt-get install yarn
|
27
|
+
|
28
|
+
RUN mkdir /app
|
29
|
+
WORKDIR /app
|
30
|
+
|
31
|
+
# ************Install Ruby gems***************************
|
32
|
+
# Invalidate gems cache if change Gemfile or Gemfile.lock
|
33
|
+
COPY Gemfile Gemfile.lock /app/
|
34
|
+
RUN bundle install -j 4 --without development test staging --deployment
|
35
|
+
# ******************************************************
|
36
|
+
|
37
|
+
# ********Install Node packages************************
|
38
|
+
# Invalidate node_modules cache if yarn.lock change
|
39
|
+
COPY package.json yarn.lock /app/
|
40
|
+
RUN yarn install --pure-lockfile --production
|
41
|
+
# ****************************************************
|
42
|
+
|
43
|
+
COPY . /app
|
44
|
+
RUN rails assets:precompile
|
45
|
+
|
46
|
+
# *******************************************
|
47
|
+
# **************** Multi Stage **************
|
48
|
+
# *******************************************
|
49
|
+
FROM ruby:2.5.0-slim
|
50
|
+
|
51
|
+
ENV RAILS_ENV=production
|
52
|
+
ENV NODE_ENV=production
|
53
|
+
|
54
|
+
<% if database == "mysql" %>
|
55
|
+
# install mysql
|
56
|
+
RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y mysql-client º
|
57
|
+
&& apt-get clean \
|
58
|
+
&& rm -rf /var/lib/apt/lists/*
|
59
|
+
<% elsif database == "postgresql" %>
|
60
|
+
# install postgresql
|
61
|
+
RUN apt-get update -qq && apt-get dist-upgrade -y && apt-get install -y postgresql-client \
|
62
|
+
&& apt-get clean \
|
63
|
+
&& rm -rf /var/lib/apt/lists/*
|
64
|
+
<% end %>
|
65
|
+
# install node 8.9.1 LTS
|
66
|
+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bin/bash -
|
67
|
+
RUN apt-get update && apt-get install -y nodejs \
|
68
|
+
&& apt-get clean \
|
69
|
+
&& rm -rf /var/lib/apt/lists/*
|
70
|
+
|
71
|
+
RUN mkdir /app
|
72
|
+
WORKDIR /app
|
73
|
+
|
74
|
+
# ************Copy only Rails app, prevent copy unnecessary files (.dockerignore don't work)***************************
|
75
|
+
COPY --from=builder /app/app /app/app
|
76
|
+
COPY --from=builder /app/config /app/config
|
77
|
+
COPY --from=builder /app/bin /app/bin
|
78
|
+
COPY --from=builder /app/db /app/db
|
79
|
+
COPY --from=builder /app/lib /app/lib
|
80
|
+
COPY --from=builder /app/public /app/public
|
81
|
+
COPY --from=builder /app/vendor /app/vendor
|
82
|
+
COPY --from=builder /app/config.ru app/Gemfile app/Gemfile.lock app/Rakefile /app/
|
83
|
+
# *********************************************************************************************************************
|
84
|
+
|
85
|
+
COPY --from=builder /usr/local/bundle /usr/local/bundle
|
86
|
+
|
87
|
+
COPY --from=builder /app/docker/production/rails/entrypoint.sh /app/docker/production/rails/entrypoint.sh
|
88
|
+
|
89
|
+
CMD ["/app/docker/production/rails/entrypoint.sh"]
|
@@ -0,0 +1 @@
|
|
1
|
+
kubectl get secrets rails-secrets -o yaml
|
@@ -0,0 +1,32 @@
|
|
1
|
+
kind: ReplicationController
|
2
|
+
apiVersion: v1
|
3
|
+
metadata:
|
4
|
+
labels:
|
5
|
+
app: cloudsql-proxy
|
6
|
+
name: cloudsql-proxy
|
7
|
+
spec:
|
8
|
+
replicas: 2
|
9
|
+
selector:
|
10
|
+
app: cloudsql-proxy
|
11
|
+
template:
|
12
|
+
metadata:
|
13
|
+
name: cloudsql-proxy
|
14
|
+
labels:
|
15
|
+
app: cloudsql-proxy
|
16
|
+
spec:
|
17
|
+
containers:
|
18
|
+
- image: gcr.io/cloudsql-docker/gce-proxy:1.11
|
19
|
+
name: cloudsql-proxy
|
20
|
+
command:
|
21
|
+
- /cloud_sql_proxy
|
22
|
+
- -instances=<PROJECT_ID>:<INSTANCE_CONNECTION_NAME>=tcp:0.0.0.0:5432
|
23
|
+
- -credential_file=/secrets/cloudsql/credentials.json
|
24
|
+
volumeMounts:
|
25
|
+
- mountPath: /secrets/cloudsql
|
26
|
+
name: cloudsql-instance-credentials
|
27
|
+
readOnly: true
|
28
|
+
volumes:
|
29
|
+
- name: cloudsql-instance-credentials
|
30
|
+
secret:
|
31
|
+
defaultMode: 420
|
32
|
+
secretName: cloudsql-instance-credentials
|
@@ -0,0 +1,26 @@
|
|
1
|
+
kind: Deployment
|
2
|
+
apiVersion: apps/v1
|
3
|
+
metadata:
|
4
|
+
labels:
|
5
|
+
app: rails-nginx
|
6
|
+
name: rails-nginx
|
7
|
+
spec:
|
8
|
+
replicas: 2
|
9
|
+
selector:
|
10
|
+
matchLabels:
|
11
|
+
app: rails-nginx
|
12
|
+
template:
|
13
|
+
metadata:
|
14
|
+
labels:
|
15
|
+
app: rails-nginx
|
16
|
+
spec:
|
17
|
+
containers:
|
18
|
+
- image: gcr.io/<PROJECT_ID>/nginx:latest
|
19
|
+
name: nginx
|
20
|
+
- image: gcr.io/<PROJECT_ID>/rails:latest
|
21
|
+
name: rails
|
22
|
+
envFrom:
|
23
|
+
- configMapRef:
|
24
|
+
name: rails-config
|
25
|
+
- secretRef:
|
26
|
+
name: rails-secrets
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
set -ex
|
3
|
+
PROJECT_ID=<PROJECT_ID>
|
4
|
+
BRANCH_NAME=`git rev-parse --abbrev-ref HEAD`
|
5
|
+
SHORT_SHA=`git rev-parse --short HEAD`
|
6
|
+
IMAGE_NAME=gcr.io/${PROJECT_ID}
|
7
|
+
|
8
|
+
# Build rails builder
|
9
|
+
docker build \
|
10
|
+
-t ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}-builder \
|
11
|
+
-t ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest-builder \
|
12
|
+
-t ${IMAGE_NAME}/rails:latest-builder \
|
13
|
+
--target builder \
|
14
|
+
-f docker/production/rails/Dockerfile \
|
15
|
+
.
|
16
|
+
|
17
|
+
# Build rails
|
18
|
+
docker build \
|
19
|
+
-t ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA} \
|
20
|
+
-t ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest \
|
21
|
+
-t ${IMAGE_NAME}/rails:latest \
|
22
|
+
-f docker/production/rails/Dockerfile \
|
23
|
+
.
|
24
|
+
|
25
|
+
# Build nginx
|
26
|
+
docker build \
|
27
|
+
-t ${IMAGE_NAME}/nginx:${BRANCH_NAME}-${SHORT_SHA} \
|
28
|
+
-t ${IMAGE_NAME}/nginx:${BRANCH_NAME}-latest \
|
29
|
+
-t ${IMAGE_NAME}/nginx:latest \
|
30
|
+
-f docker/production/nginx/Dockerfile \
|
31
|
+
docker/production/nginx
|
32
|
+
|
33
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}-builder
|
34
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest-builder
|
35
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:latest-builder
|
36
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-${SHORT_SHA}
|
37
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:${BRANCH_NAME}-latest
|
38
|
+
gcloud docker -- push ${IMAGE_NAME}/rails:latest
|
39
|
+
gcloud docker -- push ${IMAGE_NAME}/nginx:${BRANCH_NAME}-${SHORT_SHA}
|
40
|
+
gcloud docker -- push ${IMAGE_NAME}/nginx:${BRANCH_NAME}-latest
|
41
|
+
gcloud docker -- push ${IMAGE_NAME}/nginx:latest
|
@@ -0,0 +1,13 @@
|
|
1
|
+
FROM gcr.io/<PROJECT_ID>/rails:latest as rails
|
2
|
+
|
3
|
+
FROM nginx:1.13-alpine
|
4
|
+
|
5
|
+
RUN apk upgrade --no-cache
|
6
|
+
RUN apk add --no-cache xz
|
7
|
+
|
8
|
+
# COPY content/usr/local/sbin/* /usr/local/sbin/
|
9
|
+
COPY etc/nginx/ /etc/nginx/
|
10
|
+
|
11
|
+
WORKDIR /app
|
12
|
+
|
13
|
+
COPY --from=rails /app/public ./public
|
@@ -0,0 +1,34 @@
|
|
1
|
+
server {
|
2
|
+
|
3
|
+
listen 80;
|
4
|
+
server_name localhost;
|
5
|
+
root /app/public;
|
6
|
+
|
7
|
+
location / {
|
8
|
+
try_files $uri @proxy;
|
9
|
+
}
|
10
|
+
|
11
|
+
location = /favicon.ico {
|
12
|
+
log_not_found off;
|
13
|
+
access_log off;
|
14
|
+
}
|
15
|
+
|
16
|
+
# Block access to "hidden" files and directories whose names begin with a
|
17
|
+
# period. This includes directories used by version control systems such
|
18
|
+
# as Subversion or Git to store control files.
|
19
|
+
location ~ (^|/)\. {
|
20
|
+
return 403;
|
21
|
+
}
|
22
|
+
|
23
|
+
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
|
24
|
+
expires max;
|
25
|
+
log_not_found off;
|
26
|
+
}
|
27
|
+
|
28
|
+
location @proxy {
|
29
|
+
proxy_pass http://localhost:3000;
|
30
|
+
proxy_set_header Host $host;
|
31
|
+
proxy_set_header X-Real-IP $remote_addr;
|
32
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
user nginx;
|
2
|
+
worker_processes 1;
|
3
|
+
|
4
|
+
error_log /var/log/nginx/error.log warn;
|
5
|
+
pid /var/run/nginx.pid;
|
6
|
+
|
7
|
+
|
8
|
+
events {
|
9
|
+
worker_connections 1024;
|
10
|
+
}
|
11
|
+
|
12
|
+
|
13
|
+
http {
|
14
|
+
client_max_body_size 64M;
|
15
|
+
include /etc/nginx/mime.types;
|
16
|
+
default_type application/octet-stream;
|
17
|
+
set_real_ip_from 0.0.0.0/0;
|
18
|
+
real_ip_header X-Forwarded-For;
|
19
|
+
real_ip_recursive on;
|
20
|
+
|
21
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
22
|
+
'$status $body_bytes_sent "$http_referer" '
|
23
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
24
|
+
|
25
|
+
access_log /var/log/nginx/access.log main;
|
26
|
+
|
27
|
+
sendfile on;
|
28
|
+
#tcp_nopush on;
|
29
|
+
|
30
|
+
keepalive_timeout 65;
|
31
|
+
|
32
|
+
#gzip on;
|
33
|
+
|
34
|
+
include /etc/nginx/conf.d/*.conf;
|
35
|
+
|
36
|
+
}
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockerize-stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Savignano
|
@@ -38,8 +38,26 @@ files:
|
|
38
38
|
- lib/rails/dockerize_rails.rb
|
39
39
|
- lib/rails/templates/config/database-docker.yml.erb
|
40
40
|
- lib/rails/templates/docker-compose.yml.erb
|
41
|
+
- lib/rails/templates/docker/Dockerfile.production.erb
|
41
42
|
- lib/rails/templates/docker/development/Dockerfile.erb
|
42
43
|
- lib/rails/templates/docker/development/entrypoint.sh.erb
|
44
|
+
- lib/rails/templates/docker/kubernetes/scripts/deploy.sh
|
45
|
+
- lib/rails/templates/docker/kubernetes/scripts/get-secrets.sh
|
46
|
+
- lib/rails/templates/docker/kubernetes/scripts/remoteconsole.sh
|
47
|
+
- lib/rails/templates/docker/kubernetes/scripts/set-config-map.sh
|
48
|
+
- lib/rails/templates/docker/kubernetes/scripts/set-secrets.sh
|
49
|
+
- lib/rails/templates/docker/kubernetes/scripts/set-services.sh
|
50
|
+
- lib/rails/templates/docker/kubernetes/scripts/set-workloads.sh
|
51
|
+
- lib/rails/templates/docker/kubernetes/services/cloudsql-proxy.yaml
|
52
|
+
- lib/rails/templates/docker/kubernetes/services/rails-nginx.yaml
|
53
|
+
- lib/rails/templates/docker/kubernetes/workloads/cloudsql-proxy.yaml
|
54
|
+
- lib/rails/templates/docker/kubernetes/workloads/rails-nginx.yaml
|
55
|
+
- lib/rails/templates/docker/production/dockerbuild.sh
|
56
|
+
- lib/rails/templates/docker/production/nginx/Dockerfile
|
57
|
+
- lib/rails/templates/docker/production/nginx/entrypoint.sh
|
58
|
+
- lib/rails/templates/docker/production/nginx/etc/nginx/conf.d/default.conf
|
59
|
+
- lib/rails/templates/docker/production/nginx/etc/nginx/nginx.conf
|
60
|
+
- lib/rails/templates/docker/production/rails/entrypoint.sh
|
43
61
|
- lib/rails/templates/dockerignore.erb
|
44
62
|
- lib/rails/templates/id_rsa.sample
|
45
63
|
- lib/version.rb
|