stack_car 0.8.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.gitlab-ci.yml +17 -12
  3. data/README.md +122 -1
  4. data/lib/stack_car/cli.rb +253 -41
  5. data/lib/stack_car/dot_rc.rb +25 -0
  6. data/lib/stack_car/version.rb +1 -1
  7. data/lib/stack_car.rb +1 -0
  8. data/stack_car.gemspec +2 -0
  9. data/templates/.dockerignore.erb +2 -2
  10. data/templates/.env.development.erb +2 -0
  11. data/templates/.env.erb +29 -16
  12. data/templates/.gitlab/issue_templates/Bug.md +46 -0
  13. data/templates/.gitlab/issue_templates/Feature.md +41 -0
  14. data/templates/.gitlab/issue_templates/Question.md +18 -0
  15. data/templates/.gitlab/merge_request_templates/Bug.md +36 -0
  16. data/templates/.gitlab/merge_request_templates/Feature.md +36 -0
  17. data/templates/.gitlab-ci.yml.erb +98 -65
  18. data/templates/.sops.yaml.erb +3 -0
  19. data/templates/Dockerfile.erb +26 -7
  20. data/templates/README.md +81 -7
  21. data/templates/chart/.gitignore +3 -0
  22. data/templates/chart/.helmignore +23 -0
  23. data/templates/chart/Chart.yaml.tt +30 -0
  24. data/templates/chart/README.md +223 -0
  25. data/templates/chart/bin/check_sidekiq.rb +0 -0
  26. data/templates/chart/bin/decrypt +17 -0
  27. data/templates/chart/bin/deploy +14 -0
  28. data/templates/chart/bin/encrypt +15 -0
  29. data/templates/chart/bin/remove +15 -0
  30. data/templates/chart/sample-values.yaml.tt +153 -0
  31. data/templates/chart/templates/_helpers.tpl.tt +85 -0
  32. data/templates/chart/templates/rails-env-cm.yaml.tt +47 -0
  33. data/templates/chart/templates/rails-env-secret.yaml +10 -0
  34. data/templates/chart/templates/rails-pvc-shared.yml +20 -0
  35. data/templates/chart/templates/setup-job.yaml +73 -0
  36. data/templates/chart/templates/web-deploy.yaml +67 -0
  37. data/templates/chart/templates/web-ing-wildcard.yaml +20 -0
  38. data/templates/chart/templates/web-ing.yaml +20 -0
  39. data/templates/chart/templates/web-svc.yaml +20 -0
  40. data/templates/chart-fcrepo/fcrepo-deploy.yaml +63 -0
  41. data/templates/chart-fcrepo/fcrepo-env-cm.yaml +8 -0
  42. data/templates/chart-fcrepo/fcrepo-env-secret.yaml.tt +10 -0
  43. data/templates/chart-fcrepo/fcrepo-pvc.yaml +20 -0
  44. data/templates/chart-fcrepo/fcrepo-svc.yaml +19 -0
  45. data/templates/chart-sidekiq/sidekiq-deploy.yaml +80 -0
  46. data/templates/database.yml.erb +10 -11
  47. data/templates/decrypt-secrets +22 -0
  48. data/templates/development.rb.erb +90 -0
  49. data/templates/docker-compose.yml.erb +52 -18
  50. data/templates/encrypt-secrets +19 -0
  51. data/templates/env.conf.erb +11 -11
  52. data/templates/nginx.sh.erb +17 -0
  53. data/templates/production.rb.erb +117 -0
  54. metadata +71 -12
  55. data/templates/Dockerfile.base.erb +0 -48
  56. data/templates/Dockerfile.builder.erb +0 -13
  57. data/templates/docker-compose.ci.yml.erb +0 -87
  58. data/templates/docker-compose.production.yml.erb +0 -26
@@ -0,0 +1,20 @@
1
+ ---
2
+ apiVersion: apps/v1
3
+ kind: Ingress
4
+ metadata:
5
+ name: {{ template "app.web.name" . }}-in-wildcard
6
+ annotations:
7
+ # kubernetes.io/ingress.allow-http: "false"
8
+ # for GKE
9
+ # kubernetes.io/ingress.global-static-ip-name: rails-k8s-app
10
+ spec:
11
+ # tls:
12
+ # - hosts:
13
+ # - {{ .Values.ingress.host }}
14
+ rules:
15
+ - host: "*.{{ .Values.ingress.host }}"
16
+ http:
17
+ paths:
18
+ - backend:
19
+ serviceName: {{ template "app.web.name" . }}
20
+ servicePort: 80
@@ -0,0 +1,20 @@
1
+ ---
2
+ apiVersion: apps/v1
3
+ kind: Ingress
4
+ metadata:
5
+ name: {{ template "app.web.name" . }}-in
6
+ annotations:
7
+ {{- range $key, $value := .Values.ingress.annotations }}
8
+ {{ $key }}: {{ $value | quote }}
9
+ {{- end }}
10
+ spec:
11
+ # tls:
12
+ # - hosts:
13
+ # - {{ .Values.ingress.host }}
14
+ rules:
15
+ - host: "{{ .Values.ingress.host }}"
16
+ http:
17
+ paths:
18
+ - backend:
19
+ serviceName: {{ template "app.web.name" . }}
20
+ servicePort: 80
@@ -0,0 +1,20 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Service
4
+ metadata:
5
+ name: {{ template "app.web.name" . }}
6
+ labels:
7
+ app: {{ template "app.name" . }}
8
+ chart: {{ template "app.chart" . }}
9
+ release: {{ .Release.Name }}
10
+ heritage: {{ .Release.Service }}
11
+ component: web
12
+ spec:
13
+ ports:
14
+ - protocol: TCP
15
+ port: 80
16
+ targetPort: 80
17
+ selector:
18
+ app: {{ template "app.name" . }}
19
+ release: {{ .Release.Name }}
20
+ component: web
@@ -0,0 +1,63 @@
1
+ ---
2
+ apiVersion: apps/v1
3
+ kind: Deployment
4
+ metadata:
5
+ name: {{ template "app.fcrepo.name" . }}
6
+ labels:
7
+ app: {{ template "app.name" . }}
8
+ chart: {{ template "app.chart" . }}
9
+ release: {{ .Release.Name }}
10
+ heritage: {{ .Release.Service }}
11
+ component: fcrepo
12
+ spec:
13
+ replicas: 1
14
+ selector:
15
+ matchLabels:
16
+ app: {{ template "app.name" . }}
17
+ release: {{ .Release.Name }}
18
+ component: fcrepo
19
+ strategy:
20
+ type: Recreate
21
+ template:
22
+ metadata:
23
+ labels:
24
+ app: {{ template "app.name" . }}
25
+ release: {{ .Release.Name }}
26
+ component: fcrepo
27
+ spec:
28
+ restartPolicy: Always
29
+ {{- if .Values.fcrepo.imagePullSecrets }}
30
+ imagePullSecrets:
31
+ {{ toYaml .Values.fcrepo.imagePullSecrets }}
32
+ {{- end }}
33
+ volumes:
34
+ - name: data
35
+ persistentVolumeClaim:
36
+ claimName: {{ template "app.fcrepo.name" . }}
37
+ initContainers:
38
+ - name: "remove-lost-found"
39
+ image: "busybox:1.25.0"
40
+ command:
41
+ - rm
42
+ - -fr
43
+ - /data/lost+found
44
+ volumeMounts:
45
+ - name: data
46
+ mountPath: /data
47
+ containers:
48
+ - name: fcrepo
49
+ image: {{ .Values.fcrepo.image.repository }}:{{ .Values.fcrepo.image.tag }}
50
+ livenessProbe:
51
+ tcpSocket:
52
+ port: 8080
53
+ readinessProbe:
54
+ tcpSocket:
55
+ port: 8080
56
+ volumeMounts:
57
+ - name: data
58
+ mountPath: /data
59
+ envFrom:
60
+ - configMapRef:
61
+ name: {{ template "app.fcrepo-env.name" . }}
62
+ - secretRef:
63
+ name: {{ template "app.fcrepo-env.name" . }}
@@ -0,0 +1,8 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: ConfigMap
4
+ metadata:
5
+ name: {{ template "app.fcrepo-env.name" . }}
6
+ data:
7
+ DATABASE_USER: {{ .Values.env.configmap.DATABASE_USER }}
8
+ DATABASE_NAME: {{ .Values.env.configmap.FC_DATABASE_NAME }}
@@ -0,0 +1,10 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Secret
4
+ metadata:
5
+ name: {{ template "app.fcrepo-env.name" . }}
6
+ data:
7
+ DATABASE_PASSWORD: {{ .Values.env.secret.DATABASE_PASSWORD | b64enc }}
8
+ <% if options[:postgres] %>
9
+ JAVA_OPTS: {{ printf "-Dfcrepo.modeshape.configuration=\"classpath:/config/jdbc-postgresql/repository.json\" -Dfcrepo.postgresql.host=\"%s\" -Dfcrepo.postgresql.username=\"%s\" -Dfcrepo.postgresql.password=\"%s\" -Dfcrepo.object.directory=\"/data/objects\" -Dfcrepo.binary.directory=\"/data/binaries\"" ( include "app.postgres.name" . ) .Values.env.configmap.DATABASE_USER .Values.env.secret.DATABASE_PASSWORD | b64enc }}
10
+ <% end %>
@@ -0,0 +1,20 @@
1
+ ---
2
+ kind: PersistentVolumeClaim
3
+ apiVersion: v1
4
+ metadata:
5
+ name: {{ template "app.fcrepo.name" . }}
6
+ labels:
7
+ app: {{ template "app.name" . }}
8
+ chart: {{ template "app.chart" . }}
9
+ release: {{ .Release.Name }}
10
+ heritage: {{ .Release.Service }}
11
+ component: fcrepo
12
+ spec:
13
+ accessModes:
14
+ - ReadWriteOnce
15
+ resources:
16
+ requests:
17
+ storage: {{ .Values.fcrepo.storage.size }}
18
+ {{- if .Values.fcrepo.storage.className }}
19
+ storageClassName: "{{ .Values.fcrepo.storage.ClassName }}"
20
+ {{- end }}
@@ -0,0 +1,19 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Service
4
+ metadata:
5
+ name: {{ template "app.fcrepo.name" . }}
6
+ labels:
7
+ app: {{ template "app.name" . }}
8
+ chart: {{ template "app.chart" . }}
9
+ release: {{ .Release.Name }}
10
+ heritage: {{ .Release.Service }}
11
+ component: fcrepo
12
+ spec:
13
+ ports:
14
+ - protocol: TCP
15
+ port: 8080
16
+ selector:
17
+ app: {{ template "app.name" . }}
18
+ release: {{ .Release.Name }}
19
+ component: fcrepo
@@ -0,0 +1,80 @@
1
+ ---
2
+ apiVersion: apps/v1
3
+ kind: Deployment
4
+ metadata:
5
+ name: {{ template "app.sidekiq.name" . }}
6
+ labels:
7
+ app: {{ template "app.name" . }}
8
+ chart: {{ template "app.chart" . }}
9
+ release: {{ .Release.Name }}
10
+ heritage: {{ .Release.Service }}
11
+ component: sidekiq
12
+ spec:
13
+ replicas: {{ .Values.sidekiq.replicas }}
14
+ selector:
15
+ matchLabels:
16
+ app: {{ template "app.name" . }}
17
+ release: {{ .Release.Name }}
18
+ component: sidekiq
19
+ template:
20
+ metadata:
21
+ labels:
22
+ app: {{ template "app.name" . }}
23
+ release: {{ .Release.Name }}
24
+ component: sidekiq
25
+ annotations:
26
+ checksum/rails-env-cm: {{ include (print $.Template.BasePath "/rails-env-cm.yaml") . | sha256sum }}
27
+ checksum/rails-env-secret: {{ include (print $.Template.BasePath "/rails-env-secret.yaml") . | sha256sum }}
28
+ spec:
29
+ restartPolicy: Always
30
+ terminationGracePeriodSeconds: {{ .Values.sidekiq.timeout | add 5 }}
31
+ {{- if .Values.rails.imagePullSecrets }}
32
+ imagePullSecrets:
33
+ {{ toYaml .Values.rails.imagePullSecrets }}
34
+ {{- end }}
35
+ volumes:
36
+ - name: shared
37
+ persistentVolumeClaim:
38
+ claimName: {{ template "app.rails-env.name" . }}-shared
39
+ containers:
40
+ - name: sidekiq
41
+ image: {{ .Values.rails.image.repository }}:{{ .Values.rails.image.tag }}
42
+ imagePullPolicy: Always
43
+ command: ["/bin/bash"]
44
+ args:
45
+ - "-l"
46
+ - "-c"
47
+ - "bundle exec sidekiq"
48
+ # livenessProbe:
49
+ # exec:
50
+ # command:
51
+ # - ./bin/rails runner ./chart/bin/check_sidekiq.rb
52
+ # initialDelaySeconds: 30
53
+ # Use sub-path for individual folders
54
+ volumeMounts:
55
+ - mountPath: /home/app/webapp/tmp/imports
56
+ name: shared
57
+ subPath: import_path
58
+ - mountPath: /home/app/webapp/tmp/exports
59
+ name: shared
60
+ subPath: export_path
61
+ - mountPath: /home/app/webapp/tmp/derivatives_path
62
+ name: shared
63
+ subPath: derivatives_path
64
+ - mountPath: /home/app/webapp/tmp/uploads
65
+ name: shared
66
+ subPath: upload_path
67
+ - mountPath: /home/app/webapp/public/uploads
68
+ name: shared
69
+ subPath: uploads
70
+ - mountPath: /home/app/webapp/public/assets
71
+ name: shared
72
+ subPath: assets
73
+ - mountPath: /home/app/webapp/public/branding
74
+ name: shared
75
+ subPath: branding
76
+ envFrom:
77
+ - configMapRef:
78
+ name: {{ template "app.rails-env.name" . }}
79
+ - secretRef:
80
+ name: {{ template "app.rails-env.name" . }}
@@ -2,22 +2,21 @@
2
2
 
3
3
  <% if options[:mysql] -%>
4
4
  login: &login
5
- adapter: mysql2
6
- adapter: <%%= ENV['DB_ADAPTER'] %>
7
- host: <%%= ENV['MYSQL_HOST'] %>
8
- username: <%%= ENV['MYSQL_USER'] %>
9
- password: <%%= ENV['MYSQL_PASSWORD'] %>
10
- database: <%%= ENV['MYSQL_DATABASE'] %>
5
+ adapter: <%%= ENV['DATABASE_ADAPTER'] %>
6
+ host: <%%= ENV['DATABASE_HOST'] %>
7
+ username: <%%= ENV['DATABASE_USER'] %>
8
+ password: <%%= ENV['DATABASE_PASSWORD'] %>
9
+ database: <%%= ENV['DATABASE_NAME'] %>
11
10
  pool: 5
12
11
  timeout: 5000
13
12
  <% end -%>
14
13
  <% if options[:postgres] -%>
15
14
  login: &login
16
- adapter: <%%= ENV['DB_ADAPTER'] %>
17
- host: <%%= ENV['POSTGRES_HOST'] %>
18
- username: <%%= ENV['POSTGRES_USER'] %>
19
- password: <%%= ENV['POSTGRES_PASSWORD'] %>
20
- database: <%%= ENV['POSTGRES_DB'] %>
15
+ adapter: <%%= ENV['DATABASE_ADAPTER'] %>
16
+ host: <%%= ENV['DATABASE_HOST'] %>
17
+ username: <%%= ENV['DATABASE_USER'] %>
18
+ password: <%%= ENV['DATABASE_PASSWORD'] %>
19
+ database: <%%= ENV['DATABASE_NAME'] %>
21
20
  pool: 5
22
21
  timeout: 5000
23
22
  <% end -%>
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require 'byebug'
4
+
5
+ parent_dir = File.dirname(__dir__)
6
+ Dir.chdir(File.join(parent_dir))
7
+ [
8
+ ".env.*",
9
+ "chart/*-values.yaml",
10
+ "ops/kube_config.yml",
11
+ "ops/.backend",
12
+ "ops/k8s/*-values.yaml"
13
+ ].each do |files|
14
+ Dir.glob(files).each do |file|
15
+ if file.match(/enc/)
16
+ next unless File.exists?(file)
17
+ cmd = "sops --decrypt #{file} > #{file.gsub(/.enc$/, '')}"
18
+ puts cmd
19
+ `#{cmd}`
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,90 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ <% if options[:sidekiq] %>
5
+ # In the development environment your application's code is reloaded on
6
+ # every request. This slows down response time but is perfect for development
7
+ # since you don't have to restart the web server when you make code changes.
8
+ config.cache_classes = !!Sidekiq.server?
9
+ <% end -%>
10
+
11
+ # Do not eager load code on boot.
12
+ config.eager_load = false
13
+
14
+ # Show full error reports.
15
+ config.consider_all_requests_local = true
16
+
17
+ # Enable/disable caching. By default caching is disabled.
18
+ if Rails.root.join('tmp/caching-dev.txt').exist?
19
+ config.action_controller.perform_caching = true
20
+
21
+ config.cache_store = :memory_store
22
+ config.public_file_server.headers = {
23
+ 'Cache-Control' => 'public, max-age=172800'
24
+ }
25
+ else
26
+ config.action_controller.perform_caching = false
27
+
28
+ config.cache_store = :null_store
29
+ end
30
+
31
+ # SMTP Mailer configuration
32
+ # Add SMTP settings to your environment and uncomment the following section to enable mailer
33
+ # if ENV['SMTP_ENABLED'].present? && ENV['SMTP_ENABLED'].to_s == 'true'
34
+ # config.action_mailer.smtp_settings = {
35
+ # user_name: ENV['SMTP_USER_NAME'],
36
+ # password: ENV['SMTP_PASSWORD'],
37
+ # address: ENV['SMTP_ADDRESS'],
38
+ # domain: ENV['SMTP_DOMAIN'],
39
+ # port: ENV['SMTP_PORT'],
40
+ # enable_starttls_auto: true,
41
+ # authentication: ENV['SMTP_TYPE']
42
+ # }
43
+ # # ActionMailer Config
44
+ # config.action_mailer.delivery_method = :smtp
45
+ # config.action_mailer.perform_deliveries = true
46
+ # config.action_mailer.raise_delivery_errors = false
47
+ <% if options[:hyku] %>
48
+ # config.action_mailer.asset_host = ENV['SETTINGS__MULTITENANCY__ADMIN_HOST']
49
+ <% end %>
50
+ # else
51
+ # config.action_mailer.delivery_method = :test
52
+ # end
53
+
54
+ # Don't care if the mailer can't send.
55
+ config.action_mailer.raise_delivery_errors = false
56
+
57
+ config.action_mailer.perform_caching = false
58
+
59
+ # Print deprecation notices to the Rails logger.
60
+ config.active_support.deprecation = :log
61
+
62
+ # Raise an error on page load if there are pending migrations.
63
+ config.active_record.migration_error = :page_load
64
+
65
+ # Debug mode disables concatenation and preprocessing of assets.
66
+ # This option may cause significant delays in view rendering with a large
67
+ # number of complex assets.
68
+ config.assets.debug = true
69
+
70
+ # Suppress logger output for asset requests.
71
+ config.assets.quiet = true
72
+
73
+ # Raises error for missing translations
74
+ # config.action_view.raise_on_missing_translations = true
75
+
76
+ config.action_mailer.default_url_options = { host: "localhost:3001" }
77
+
78
+ config.web_console.whitelisted_ips = ['172.18.0.0/16', '172.27.0.0/16', '0.0.0.0/0']
79
+
80
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
81
+ logger = ActiveSupport::Logger.new(STDOUT)
82
+ logger.formatter = config.log_formatter
83
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
84
+ end
85
+
86
+ config.active_job.queue_adapter = Settings.active_job.queue_adapter
87
+ # Use an evented file watcher to asynchronously detect changes in source code,
88
+ # routes, locales, etc. This feature depends on the listen gem.
89
+ # config.file_watcher = ActiveSupport::EventedFileUpdateChecker
90
+ end
@@ -2,10 +2,11 @@ version: '2.1'
2
2
  services:
3
3
  <% if options[:postgres] -%>
4
4
  postgres:
5
- image: postgres
6
- env_file:
7
- - .env
8
- - .env.development
5
+ image: postgres:11.1
6
+ environment:
7
+ - POSTGRES_USER=postgres
8
+ - POSTGRES_PASSWORD=DatabaseFTW
9
+ - POSTGRES_DB=<%= @project_name %>
9
10
  ports:
10
11
  - "5432"
11
12
  volumes:
@@ -13,10 +14,12 @@ services:
13
14
  <% end -%>
14
15
  <% if options[:mysql] -%>
15
16
  mysql:
16
- image: mysql
17
- env_file:
18
- - .env
19
- - .env.development
17
+ image: mysql:5.7
18
+ environment:
19
+ - MYSQL_DATABASE=<%= @project_name %>
20
+ - MYSQL_USER=<%= @project_name %>
21
+ - MYSQL_PASSWORD=DatabaseFTW
22
+ - MYSQL_ROOT_PASSWORD=DatabaseFTW
20
23
  ports:
21
24
  - '3306'
22
25
  volumes:
@@ -94,29 +97,58 @@ services:
94
97
  - "8080"
95
98
  <% end -%>
96
99
 
97
- base:
98
- image: "${REGISTRY_HOST}${REGISTRY_URI}/base:latest"
100
+ app:
99
101
  build:
100
- context: .
101
- dockerfile: Dockerfile.base
102
-
103
- web:
104
- build: .
105
- image: "${REGISTRY_HOST}${REGISTRY_URI}:${TAG:-master}"
102
+ <% if @sc_dir -%>
103
+ context: ..
104
+ dockerfile: stack_car/Dockerfile
105
+ <% else -%>
106
+ context: .
107
+ dockerfile: Dockerfile
108
+ <% end -%>
109
+ args:
110
+ DEPLOY_KEY: "${DEPLOY_KEY}"
111
+ REPO_URL: "${REPO_URL}"
112
+ BRANCH: "${BRANCH}"
113
+ image: "${REGISTRY_HOST}${REGISTRY_URI}:${TAG:-main}"
106
114
  env_file:
107
115
  - .env
108
116
  - .env.development
109
117
  volumes:
110
- - .:/home/app/webapp
118
+ - .:/home/app/webapp:cached
119
+ - node_modules:/home/app/webapp/node_modules
120
+ - tmp_cache:/home/app/webapp/tmp/cache
111
121
  # Keep the stdin open, so we can attach to our app container's process
112
122
  # and do things such as byebug, etc:
113
123
  stdin_open: true
114
124
  # Enable sending signals (CTRL+C, CTRL+P + CTRL+Q) into the container:
115
125
  tty: true
126
+
127
+ web:
128
+ extends: app
116
129
  ports:
117
- - "${DOCKER_PORT}"
130
+ - "${WEB_PORT}"
131
+ environment:
132
+ - VIRTUAL_HOST=<%= @project_name %>.docker
133
+ - VIRTUAL_PORT=80
134
+ depends_on:
135
+ <%= compose_depends %>
136
+
137
+ <% if options[:delayed_job] %>
138
+ worker:
139
+ extends: app
140
+ command: ./bin/delayed_job run
141
+ depends_on:
142
+ <%= compose_depends %>
143
+ <% end %>
144
+
145
+ <% if options[:sidekiq] %>
146
+ worker:
147
+ extends: app
148
+ command: bundle exec sidekiq
118
149
  depends_on:
119
150
  <%= compose_depends %>
151
+ <% end %>
120
152
 
121
153
  volumes:
122
154
  <% if options[:postgres] -%>
@@ -140,3 +172,5 @@ volumes:
140
172
  <% if options[:fcrepo] -%>
141
173
  fcrepo:
142
174
  <% end -%>
175
+ tmp_cache:
176
+ node_modules: