stack_car 0.9.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +64 -1
  3. data/lib/stack_car.rb +1 -0
  4. data/lib/stack_car/cli.rb +112 -36
  5. data/lib/stack_car/dot_rc.rb +25 -0
  6. data/lib/stack_car/version.rb +1 -1
  7. data/stack_car.gemspec +1 -0
  8. data/templates/.dockerignore.erb +2 -2
  9. data/templates/.env.development.erb +2 -0
  10. data/templates/.env.erb +15 -16
  11. data/templates/.gitlab-ci.yml.erb +94 -62
  12. data/templates/Dockerfile.base.erb +28 -19
  13. data/templates/Dockerfile.erb +26 -7
  14. data/templates/chart-fcrepo/fcrepo-deploy.yaml +63 -0
  15. data/templates/chart-fcrepo/fcrepo-env-cm.yaml +8 -0
  16. data/templates/chart-fcrepo/fcrepo-env-secret.yaml.tt +10 -0
  17. data/templates/chart-fcrepo/fcrepo-pvc.yaml +20 -0
  18. data/templates/chart-fcrepo/fcrepo-svc.yaml +19 -0
  19. data/templates/chart-sidekiq/sidekiq-deploy.yaml +80 -0
  20. data/templates/chart/.gitignore +3 -0
  21. data/templates/chart/.helmignore +23 -0
  22. data/templates/chart/Chart.yaml.tt +29 -0
  23. data/templates/chart/README.md +223 -0
  24. data/templates/chart/bin/check_sidekiq.rb +0 -0
  25. data/templates/chart/bin/decrypt +17 -0
  26. data/templates/chart/bin/deploy +14 -0
  27. data/templates/chart/bin/encrypt +15 -0
  28. data/templates/chart/bin/remove +15 -0
  29. data/templates/chart/sample-values.yaml.tt +138 -0
  30. data/templates/chart/templates/_helpers.tpl.tt +85 -0
  31. data/templates/chart/templates/rails-env-cm.yaml.tt +47 -0
  32. data/templates/chart/templates/rails-env-secret.yaml +10 -0
  33. data/templates/chart/templates/rails-pvc-shared.yml +20 -0
  34. data/templates/chart/templates/setup-job.yaml +73 -0
  35. data/templates/chart/templates/web-deploy.yaml +67 -0
  36. data/templates/chart/templates/web-ing-wildcard.yaml +20 -0
  37. data/templates/chart/templates/web-ing.yaml +20 -0
  38. data/templates/chart/templates/web-svc.yaml +20 -0
  39. data/templates/database.yml.erb +10 -10
  40. data/templates/docker-compose.yml.erb +53 -12
  41. data/templates/env.conf.erb +11 -11
  42. data/templates/nginx.sh.erb +17 -0
  43. metadata +47 -10
  44. data/templates/docker-compose.ci.yml.erb +0 -87
  45. data/templates/docker-compose.production.yml.erb +0 -26
@@ -1 +1,3 @@
1
1
  # Items in this file override those in .env and are good for developer system specific preferences
2
+ # if not using dory uncomment the next line
3
+ WEB_PORT=3000:80
data/templates/.env.erb CHANGED
@@ -1,18 +1,23 @@
1
+ APP_NAME=<%= @project_name %>
2
+ PASSENGER_APP_ENV=development
3
+ REGISTRY_HOST=registry.gitlab.com
4
+ REGISTRY_URI=/CHANGEME/<%= @project_name %>
5
+ TAG=dev
1
6
  <% if options[:postgres] -%>
2
- POSTGRES_DB=<%= @project_name %>
3
- POSTGRES_USER=postgres
4
- POSTGRES_PASSWORD=DatabaseFTW
5
- POSTGRES_HOST=postgres
6
- DB_ADAPTER=postgresql
7
+ DATABASE_NAME=<%= @project_name %>
8
+ DATABASE_USER=postgres
9
+ DATABASE_PASSWORD=DatabaseFTW
10
+ DATABASE_HOST=postgres
11
+ DATABASE_ADAPTER=postgresql
7
12
  TEST_DB=<%= @project_name %>_test
8
13
  <% end -%>
9
14
  <% if options[:mysql] -%>
10
- MYSQL_DATABASE=<%= @project_name %>
11
- MYSQL_USER=root
12
- MYSQL_PASSWORD=DatabaseFTW
15
+ DATABASE_NAME=<%= @project_name %>
16
+ DATABASE_USER=<%= @project_name %>
17
+ DATABASE_PASSWORD=DatabaseFTW
13
18
  MYSQL_ROOT_PASSWORD=DatabaseFTW
14
- MYSQL_HOST=mysql
15
- DB_ADAPTER=mysql2
19
+ DATABASE_HOST=mysql
20
+ DATABASE_ADAPTER=mysql2
16
21
  TEST_DB=<%= @project_name %>_test
17
22
  <% end -%>
18
23
  <% if options[:elasticsearch] -%>
@@ -22,9 +27,3 @@ ES_URL=http://elasticsearch:9200
22
27
  SITE_URI=https://CHANGEME.com
23
28
  DEPLOY_HOOK=CHANGEME
24
29
  <% end -%>
25
- REGISTRY_HOST=registry.gitlab.com
26
- REGISTRY_URI=/CHANGEME/<%= @project_name %>
27
- TAG=dev
28
- VIRTUAL_PORT=80
29
- PASSENGER_APP_ENV=development
30
- DOCKER_PORT=3000:80
@@ -1,71 +1,96 @@
1
- image: $CI_REGISTRY_IMAGE/builder:latest
2
- services:
3
- - docker:dind
4
- <% if options[:postgres] -%>
5
- - postgres:latest
6
- <% end -%>
7
- <% if options[:mysql] -%>
8
- - mysql:latest
9
- <% end -%>
10
- <% if options[:solr] -%>
11
- - solr:latest
12
- <% end -%>
13
- <% if options[:elasticsearch] -%>
14
- - elasticsearch:latest
15
- <% end -%>
16
- <% if options[:redis] -%>
17
- - redis:latest
18
- <% end -%>
19
-
20
1
  stages:
21
- - build
22
- - test
23
- - review
24
- - staging
25
- - production
26
-
27
- variables:
28
- <% if options[:postgres] -%>
29
- POSTGRES_DB: <%= @project_name %>
30
- POSTGRES_USER: postgres
31
- POSTGRES_PASSWORD: password
32
- POSTGRES_HOST: postgres
33
- <% end -%>
34
- <% if options[:mysql] -%>
35
- MYSQL_DATABASE: <%= @project_name %>
36
- MYSQL_ROOT_PASSWORD: password
37
- MYSQL_USER: <%= @project_name %>_test
38
- MYSQL_PASSWORD: password
39
- MYSQL_HOST: mysql
40
- <% end -%>
41
- TEST_DB: <%= @project_name %>
42
- DOCKER_DRIVER: overlay
43
- REGISTRY_HOST: registry.gitlab.com
44
- REGISTRY_URI: TODO/<%= @project_name %>
45
- SITE_URI_BASE: TODO
46
-
2
+ - build
3
+ - test
4
+ - deploy
47
5
 
48
6
  before_script:
49
- - export REGISTRY_FULL=registry.gitlab.com/notch8/ror-site/$CI_COMMIT_REF_SLUG:${CI_COMMIT_SHA:0:8}
50
- - export TAG=$CI_COMMIT_REF_SLUG
51
- - eval $(ssh-agent -s)
52
- - bash
53
- - ssh-add <(echo "$SSH_PRIVATE_KEY")
54
- - mkdir -p ~/.ssh
55
- - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
7
+ - export TAG=${CI_COMMIT_SHORT_SHA}
8
+ - export BRANCH=${CI_COMMIT_REF_NAME}
9
+ - export REGISTRY_HOST=${CI_REGISTRY}
10
+ - export REGISTRY_URI="/${CI_PROJECT_PATH}"
11
+
12
+ base:
13
+ stage: build
14
+ script:
15
+ - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
16
+ - sc build -s base
17
+ - sc push -s base
18
+ when: manual
19
+ tags:
20
+ - local
56
21
 
57
22
  build:
58
23
  stage: build
59
24
  script:
60
- - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY
25
+ - docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
61
26
  - sc build
62
27
  - sc push
28
+ - docker tag $CI_REGISTRY_IMAGE:$TAG $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
29
+ - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
30
+ tags:
31
+ - local
32
+
33
+ lint:
34
+ stage: go
35
+ image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
36
+ variables:
37
+ PRONTO_GITLAB_API_ENDPOINT: "https://gitlab.com/api/v4"
38
+ before_script:
39
+ - export PRONTO_GITLAB_API_PRIVATE_TOKEN=$GITLAB_API_TOKEN
40
+ script:
41
+ - cd /home/app/webapp && bundle exec pronto run -f gitlab
63
42
  tags:
64
43
  - docker
65
44
 
66
45
  test:
67
46
  stage: test
68
- image: $CI_REGISTRY_IMAGE:$CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
47
+ image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
48
+ services:
49
+ <% if options[:postgres] -%>
50
+ - name: postgres:11.1
51
+ <% end -%>
52
+ <% if options[:mysql] -%>
53
+ - mysql:5.7
54
+ <% end -%>
55
+ <% if options[:solr] -%>
56
+ - name: solr:latest
57
+ entrypoint: ["docker-entrypoint.sh", "solr-precreate", "test"]
58
+ <% end -%>
59
+ <% if options[:elasticsearch] -%>
60
+ - elasticsearch:latest
61
+ <% end -%>
62
+ <% if options[:redis] -%>
63
+ - redis:latest
64
+ <% end -%>
65
+ <% if options[:fcrepo] -%>
66
+ - name: botimer/fcrepo:4.5.1
67
+ <% end %>
68
+ variables:
69
+ <% if options[:postgres] -%>
70
+ POSTGRES_DB: <%= @project_name %>
71
+ POSTGRES_USER: postgres
72
+ POSTGRES_PASSWORD: password
73
+ POSTGRES_HOST: postgres
74
+ DATABASE_ADAPTER: postgresql
75
+ DATABASE_HOST: postgres
76
+ DATABASE_NAME: <%= @project_name %>
77
+ DATABASE_PASSWORD: password
78
+ DATABASE_USER: postgres
79
+ <% end -%>
80
+ <% if options[:mysql] -%>
81
+ MYSQL_DATABASE: <%= @project_name %>
82
+ MYSQL_ROOT_PASSWORD: password
83
+ MYSQL_USER: <%= @project_name %>_test
84
+ MYSQL_PASSWORD: password
85
+ MYSQL_HOST: mysql
86
+ DATABASE_ADAPTER: mysql2
87
+ DATABASE_HOST: mysql
88
+ DATABASE_NAME: <%= @project_name %>
89
+ DATABASE_PASSWORD: password
90
+ DATABASE_USER: <%= @project_name %>_test
91
+ <% end -%>
92
+ TEST_DB: <%= @project_name %>
93
+ SITE_URI_BASE: TODO
69
94
  script:
70
95
  - cd /home/app/webapp && bundle exec rake db:create db:schema:load spec
71
96
  tags:
@@ -77,7 +102,7 @@ review:
77
102
  stage: review
78
103
  type: deploy
79
104
  environment:
80
- name: $CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG
105
+ name: $CI_COMMIT_REF_SLUG
81
106
  url: http://web.$CI_PROJECT_NAME-$CI_COMMIT_REF_SLUG.staging.$SITE_URI_BASE
82
107
  on_stop: stop_review
83
108
  only:
@@ -88,12 +113,13 @@ review:
88
113
  <% if options[:rancher] -%>
89
114
  - export RANCHER_ENVIRONMENT=staging
90
115
  - sc provision ci
91
- <% else %>
116
+ <% elsif options[:helm] -%>
117
+ - ./chart/bin/deploy review $CI_COMMIT_REF_SLUG
118
+ <% else -%>
92
119
  - CHANGME
93
- <% end %>
120
+ <% end -%>
94
121
  tags:
95
- - docker
96
- - mysql
122
+ - local
97
123
 
98
124
  stop_review:
99
125
  stage: review
@@ -101,6 +127,8 @@ stop_review:
101
127
  <% if options[:rancher] -%>
102
128
  - export RANCHER_ENVIRONMENT=staging
103
129
  - rancher rm $CI_PROJECT_NAME-$CI_BUILD_REF_SLUG
130
+ <% elsif options[:helm] -%>
131
+ - ./chart/bin/remove review $CI_COMMIT_REF_SLUG
104
132
  <% end %>
105
133
  when: manual
106
134
  environment:
@@ -112,7 +140,9 @@ staging:
112
140
  type: deploy
113
141
  script:
114
142
  <% if options[:rancher] -%>
115
- - sc deploy staging
143
+ - sc deploy staging
144
+ <% elsif options[:helm] -%>
145
+ - ./chart/bin/deploy staging $CI_COMMIT_REF_SLUG
116
146
  <% end -%>
117
147
  <% if options[:heroku] -%>
118
148
  - dpl --provider=heroku --app=<%= @project_name %>-staging --api-key=$HEROKU_STAGING_API_KEY --run="bundle exec rake db:migrate"
@@ -120,7 +150,7 @@ staging:
120
150
  only:
121
151
  - master
122
152
  tags:
123
- - docker
153
+ - local
124
154
 
125
155
  production:
126
156
  stage: production
@@ -128,6 +158,8 @@ production:
128
158
  script:
129
159
  <% if options[:rancher] -%>
130
160
  - sc deploy production
161
+ <% elsif options[:helm] -%>
162
+ - ./chart/bin/deploy production $CI_COMMIT_REF_SLUG
131
163
  <% end -%>
132
164
  <% if options[:heroku] -%>
133
165
  - dpl --provider=heroku --app=<%= @project_name %> --api-key=$HEROKU_PRODUCTION_API_KEY --run="bundle exec rake db:migrate"
@@ -136,4 +168,4 @@ production:
136
168
  only:
137
169
  - master
138
170
  tags:
139
- - docker
171
+ - local
@@ -1,23 +1,32 @@
1
- FROM phusion/passenger-ruby23:0.9.28
1
+ FROM phusion/passenger-ruby26:1.0.9
2
+ ARG DEPLOY_KEY
3
+ <% if options[:git] %>
4
+ ARG REPO_URL
5
+ <% end %>
2
6
 
3
7
  RUN <%= pre_apt_string %> && \
4
- curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
8
+ curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
5
9
  apt-get update -qq && \
6
- apt-get install -y build-essential nodejs pv tzdata libsasl2-dev <%= apt_packages_string %> && \
10
+ apt-get install -y \
11
+ build-essential \
12
+ libsasl2-dev \
13
+ nodejs \
14
+ pv \
15
+ tzdata \
16
+ <%= apt_packages_string %> && \
7
17
  apt-get clean && \
8
18
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
9
19
  <%= post_apt_string %>
10
20
 
11
21
  <% if options[:fcrepo] %>
12
22
  RUN mkdir -p /opt/fits && \
13
- curl -fSL -o /opt/fits-0.8.5.zip http://projects.iq.harvard.edu/files/fits/files/fits-0.8.5.zip && \
14
- cd /opt && \
15
- unzip fits-0.8.5.zip && \
16
- chmod +x fits-0.8.5/fits.sh
17
-
23
+ curl -fSL -o /opt/fits/fits-latest.zip https://projects.iq.harvard.edu/files/fits/files/fits-1.3.0.zip && \
24
+ cd /opt/fits && unzip fits-latest.zip && chmod +X /opt/fits/fits.sh
18
25
  <% end -%>
19
26
 
20
27
  RUN rm /etc/nginx/sites-enabled/default
28
+ COPY ops/webapp.conf /etc/nginx/sites-enabled/webapp.conf
29
+ COPY ops/env.conf /etc/nginx/main.d/env.conf
21
30
 
22
31
  ENV APP_HOME /home/app/webapp
23
32
  RUN mkdir $APP_HOME
@@ -26,23 +35,23 @@ WORKDIR $APP_HOME
26
35
  ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \
27
36
  BUNDLE_JOBS=4
28
37
 
29
- ADD Gemfile* $APP_HOME/
30
- RUN bundle check || bundle install
38
+ COPY --chown=app Gemfile* $APP_HOME/
39
+ RUN /sbin/setuser app bash -l -c "gem update bundler && (bundle check || bundle install)"
31
40
 
32
- <% if options[:delayed_job] || options[:sidekiq] %>
33
- RUN touch /var/log/worker.log && chmod 666 /var/log/worker.log
34
- RUN mkdir /etc/service/worker
35
- ADD ops/worker.sh /etc/service/worker/run
36
- RUN chmod +x /etc/service/worker/run
41
+ <% if options[:git] %>
42
+ RUN chown -R app $APP_HOME && /sbin/setuser app bash -l -c "git clone --depth 2 ${REPO_URL} ${APP_HOME}""
43
+ <% else %>
44
+ COPY --chown=app . $APP_HOME
37
45
  <% end %>
38
46
 
39
- ADD . $APP_HOME
40
- RUN chown -R app $APP_HOME
47
+ <% if options[:imagemagick] %>
48
+ # reenables pdfs in imagemagick see https://ubuntuforums.org/showthread.php?t=2403266
49
+ RUN sed -i '/PDF/s/none/read|write/' /etc/ImageMagick-6/policy.xml
50
+ <% end %>
41
51
 
42
52
  # this is so that these items are cached and only have to be updated
43
- RUN /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && DB_ADAPTER=nulldb bundle exec rake assets:precompile'
53
+ RUN /sbin/setuser app /bin/bash -l -c 'cd /home/app/webapp && DATABASE_ADAPTER=nulldb bundle exec rake assets:precompile'
44
54
  # Asset complie and migrate if prod, otherwise just start nginx
45
55
  ADD ops/nginx.sh /etc/service/nginx/run
46
56
  RUN chmod +x /etc/service/nginx/run
47
57
  RUN rm -f /etc/service/nginx/down
48
-
@@ -1,14 +1,33 @@
1
1
  FROM CHANGEME/base:latest
2
+ <% if options[:git] %>
3
+ ARG BRANCH=master
4
+ ARG REPO_URL
5
+ <% end %>
2
6
 
3
- ADD http://time.jsontest.com build-time
7
+ ADD http://timejson.herokuapp.com build-time
4
8
  ADD ops/webapp.conf /etc/nginx/sites-enabled/webapp.conf
5
9
  ADD ops/env.conf /etc/nginx/main.d/env.conf
6
- ADD . $APP_HOME
7
10
 
8
- RUN cd /home/app/webapp && \
9
- (/sbin/setuser app bundle check || /sbin/setuser app bundle install) && \
10
- /sbin/setuser app bundle exec rake assets:precompile DB_ADAPTER=nulldb && \
11
- chown -R app $APP_HOME && \
12
- rm -f /etc/service/nginx/down
11
+ <% if options[:git] %>
12
+ RUN /sbin/setuser app bash -l -c "set -x && \
13
+ git fetch -ap && \
14
+ git reset --hard && \
15
+ git checkout $BRANCH && \
16
+ git pull && \
17
+ (bundle check || bundle install) && \
18
+ bundle exec rake assets:clobber assets:precompile DATABASE_ADAPTER=nulldb && \
19
+ mv /home/app/webapp/public/assets /home/app/webapp/public/assets-new && \
20
+ mv /home/app/webapp/public/packs /home/app/webapp/public/packs-new"
21
+ <% else %>
22
+ COPY --chown=app . $APP_HOME
23
+ RUN /sbin/setuser app bash -l -c "set -x && \
24
+ (bundle check || bundle install) && \
25
+ bundle exec rake assets:clobber assets:precompile DATABASE_ADAPTER=nulldb && \
26
+ mv /home/app/webapp/public/assets /home/app/webapp/public/assets-new && \
27
+ mv /home/app/webapp/public/packs /home/app/webapp/public/packs-new"
28
+ <% end %>
29
+
30
+ RUN bash -l -c "set -x && \
31
+ rm -f /etc/service/nginx/down"
13
32
 
14
33
  CMD ["/sbin/my_init"]
@@ -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" . }}