wellcar 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +38 -0
  6. data/README.markdown +17 -0
  7. data/README.rdoc +6 -0
  8. data/Rakefile +44 -0
  9. data/bin/wellcar +442 -0
  10. data/command_history_example.txt +39 -0
  11. data/lib/wellcar.rb +18 -0
  12. data/lib/wellcar/templates/base.rb +61 -0
  13. data/lib/wellcar/templates/build-production-image.yml.erb +34 -0
  14. data/lib/wellcar/templates/build_production_image.rb +18 -0
  15. data/lib/wellcar/templates/database.yml.erb +20 -0
  16. data/lib/wellcar/templates/database_yaml.rb +20 -0
  17. data/lib/wellcar/templates/docker-compose-init.yml.erb +34 -0
  18. data/lib/wellcar/templates/docker-compose.yml.erb +70 -0
  19. data/lib/wellcar/templates/docker-entrypoint.sh.erb +20 -0
  20. data/lib/wellcar/templates/docker-stack.yml.erb +35 -0
  21. data/lib/wellcar/templates/docker_compose.rb +22 -0
  22. data/lib/wellcar/templates/docker_entrypoint.rb +13 -0
  23. data/lib/wellcar/templates/docker_stack.rb +23 -0
  24. data/lib/wellcar/templates/dockerfile.erb +48 -0
  25. data/lib/wellcar/templates/dockerfile.rb +13 -0
  26. data/lib/wellcar/templates/dockerfile_init.erb +38 -0
  27. data/lib/wellcar/templates/dockerfile_init.rb +18 -0
  28. data/lib/wellcar/templates/dockerignore.erb +10 -0
  29. data/lib/wellcar/templates/dockerignore.rb +12 -0
  30. data/lib/wellcar/templates/env_development_database.erb +3 -0
  31. data/lib/wellcar/templates/env_development_database.rb +13 -0
  32. data/lib/wellcar/templates/env_development_web.erb +1 -0
  33. data/lib/wellcar/templates/env_development_web.rb +14 -0
  34. data/lib/wellcar/templates/env_production_database.erb +3 -0
  35. data/lib/wellcar/templates/env_production_database.rb +14 -0
  36. data/lib/wellcar/templates/env_production_web.erb +5 -0
  37. data/lib/wellcar/templates/env_production_web.rb +14 -0
  38. data/lib/wellcar/templates/reverse_proxy.conf.erb +12 -0
  39. data/lib/wellcar/templates/reverse_proxy_conf.rb +14 -0
  40. data/lib/wellcar/version.rb +3 -0
  41. data/spec/.keep +0 -0
  42. data/spec/spec_helper.rb +101 -0
  43. data/spec/wellcar/templates/build_production_image_spec.rb +55 -0
  44. data/spec/wellcar/templates/database_yaml_spec.rb +27 -0
  45. data/spec/wellcar/templates/docker_compose_spec.rb +34 -0
  46. data/spec/wellcar/templates/docker_entrypoint_spec.rb +32 -0
  47. data/spec/wellcar/templates/docker_stack_spec.rb +37 -0
  48. data/spec/wellcar/templates/dockerfile_init_spec.rb +28 -0
  49. data/spec/wellcar/templates/dockerfile_spec.rb +44 -0
  50. data/spec/wellcar/templates/dockerignore_spec.rb +28 -0
  51. data/spec/wellcar/templates/env_development_database_spec.rb +25 -0
  52. data/spec/wellcar/templates/env_development_web_spec.rb +13 -0
  53. data/spec/wellcar/templates/env_production_database_spec.rb +25 -0
  54. data/spec/wellcar/templates/env_production_web_spec.rb +29 -0
  55. data/spec/wellcar/templates/reverse_proxy_conf_spec.rb +17 -0
  56. data/wellcar.gemspec +22 -0
  57. data/wellcar.rdoc +5 -0
  58. metadata +163 -0
@@ -0,0 +1,39 @@
1
+ 841 docker-machine ls
2
+ 842 docker-machine ssh chxta-vm-1
3
+ 846 git diff docker-stack.yml
4
+ 847 git add docker-stack.yml
5
+ 848 git commit -m 'Corrects docker files for prod'
6
+ 851 eval $(docker-machine env -u)
7
+ 853 docker build -f Dockerfile.prod -t houches/chamonix-takeaway:prod .
8
+ 855 history |grep docker
9
+ 856 docker push houches/chamonix-takeaway:prod
10
+ 857 eval (docker-machine env chxta-vm-1)
11
+ 858 eval $(docker-machine env chxta-vm-1)
12
+ 860 docker stack deploy -c docker-stack.yml chamonix-takeaway
13
+ 861 docker stack ps
14
+ 862 docker stack services chamonix-takeaway
15
+ 865 docker stack --help
16
+ 870 history |grep docker
17
+ 871 docker build -f Dockerfile.prod -t houches/chamonix-takeaway:prod .
18
+ 873 eval $(docker-machine env -u)
19
+ 874 docker build -f Dockerfile.prod -t houches/chamonix-takeaway:prod .
20
+ 875 docker push houches/chamonix-takeaway:prod
21
+ 877 eval $(docker-machine env chxta-vm-1)
22
+ 878 docker stack deploy -c docker-stack.yml chamonix-takeaway
23
+ 879 docker stack ps
24
+ 880 docker stack services chamonix-takeaway
25
+ 881 docker service ls
26
+ 885 eval $(docker-machine env -u)
27
+ 886 docker build -f Dockerfile.prod -t houches/chamonix-takeaway:prod .
28
+ 887 docker build -f Dockerfile.prod -t houches/chamonix-takeaway:prod .
29
+ 888 docker push houches/chamonix-takeaway:prod
30
+ 890 eval $(docker-machine env chxta-vm-1)
31
+ 891 docker stack deploy -c docker-stack.yml chamonix-takeaway
32
+ 902 docker-compose exec web bin/rails db:seed
33
+ 904 eval $(docker-machine env -u)
34
+ 905 docker-compose exec web bin/rails db:seed
35
+ 906 docker-compose exec web bin/rails db:seed
36
+ 907 docker-compose exec web yarn install --check-files
37
+ 908 docker-compose exec webpack-dev-server yarn install --check-files
38
+ 909 docker-compose exec webpack-dev-server yarn install --check-files
39
+ 910 docker-compose exec web bin/rails db:seed
@@ -0,0 +1,18 @@
1
+ require 'wellcar/version.rb'
2
+ require 'wellcar/templates/base.rb'
3
+ require 'wellcar/templates/dockerfile.rb'
4
+ require 'wellcar/templates/dockerfile_init.rb'
5
+ require 'wellcar/templates/dockerignore.rb'
6
+ require 'wellcar/templates/docker_compose.rb'
7
+ require 'wellcar/templates/docker_stack.rb'
8
+ require 'wellcar/templates/database_yaml.rb'
9
+ require 'wellcar/templates/docker_entrypoint.rb'
10
+ require 'wellcar/templates/env_development_database.rb'
11
+ require 'wellcar/templates/env_development_web.rb'
12
+ require 'wellcar/templates/env_production_database.rb'
13
+ require 'wellcar/templates/env_production_web.rb'
14
+ require "wellcar/templates/build_production_image"
15
+ require "wellcar/templates/reverse_proxy_conf"
16
+
17
+ # Add requires for other files you add to your project here, so
18
+ # you just need to require this one file in your bin file
@@ -0,0 +1,61 @@
1
+ module Wellcar
2
+ module Templates
3
+ class Base
4
+ include ERB::Util
5
+
6
+ def initialize(file_path)
7
+ @file_path = file_path
8
+ @before_write = []
9
+ end
10
+
11
+ def write
12
+ @before_write.each {|procedure| procedure.call }
13
+
14
+ File.open(file_path, 'w') {|file| file.write render }
15
+ end
16
+
17
+ def exist?
18
+ File.exist? file_path
19
+ end
20
+
21
+ def render
22
+ ERB.new(template).result(binding)
23
+ end
24
+
25
+ private
26
+
27
+ def file_path
28
+ raise NotImplementedError, "You have not assigned a value to @file_path" if @file_path.nil?
29
+ @file_path
30
+ end
31
+
32
+ def template
33
+ raise NotImplementedError, "You have not set the template filename. Use with_template in your concrete implementation." if @template_filename.empty?
34
+
35
+ @template ||= File.read(File.join(File.dirname(__FILE__), @template_filename))
36
+ end
37
+
38
+ def with_template(filename)
39
+ @template_filename = filename
40
+ end
41
+
42
+ def with_attributes(attributes)
43
+ attributes.each do |pair|
44
+ name = pair.first
45
+ value = pair.last
46
+ self.define_singleton_method(name.to_sym) { return value }
47
+ end
48
+ end
49
+
50
+ def within(path)
51
+ @before_write << Proc.new do
52
+ @file_path = File.join path, @file_path
53
+
54
+ next if Dir.exist? path
55
+
56
+ FileUtils.mkdir_p path
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,34 @@
1
+ name: Publish production image
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ push_to_registry:
7
+ name: Push Docker image to GitHub Packages
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Check out the repo
11
+ uses: actions/checkout@v2
12
+ - name: Build reverse proxy
13
+ uses: docker/build-push-action@v1
14
+ with:
15
+ username: ${{ github.actor }}
16
+ password: ${{ secrets.GITHUB_TOKEN }}
17
+ registry: docker.pkg.github.com
18
+ repository: <%= repository_base_path %>/nginx
19
+ target: reverse_proxy
20
+ tag_with_ref: true
21
+ tags: latest
22
+ - name: Push to GitHub Packages
23
+ uses: docker/build-push-action@v1
24
+ with:
25
+ username: ${{ github.actor }}
26
+ password: ${{ secrets.GITHUB_TOKEN }}
27
+ registry: docker.pkg.github.com
28
+ repository: <%= repository_base_path %>/web
29
+ target: production
30
+ tag_with_ref: true
31
+ tags: latest
32
+ env:
33
+ RAILS_MASTER_KEY: ${{ secrets.PROD_MASTER_KEY }}
34
+ RAILS_ENV: production
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ module Wellcar
4
+ module Templates
5
+ class BuildProductionImage < Base
6
+ def initialize(app_name, repo_account)
7
+ super "build-production-image.yml"
8
+ with_attributes app_name: app_name, repo_account: repo_account
9
+ with_template "build-production-image.yml.erb"
10
+ within ".github/workflows"
11
+ end
12
+
13
+ def repository_base_path
14
+ [repo_account, app_name].join "/"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ host: '<%%= ENV.fetch("DATABASE_HOST") %>'
5
+ username: '<%%= ENV.fetch("POSTGRES_USER") %>'
6
+ password: '<%%= ENV.fetch("POSTGRES_PASSWORD") %>'
7
+ database: '<%%= ENV.fetch("POSTGRES_DB") %>'
8
+ pool: 5
9
+ variables:
10
+ statement_timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+
15
+ test:
16
+ <<: *default
17
+ database: <%= app_name %>
18
+
19
+ production:
20
+ <<: *default
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ module Wellcar
4
+ module Templates
5
+ class DatabaseYaml < Base
6
+ def initialize(app_name)
7
+ super "config/database.yml"
8
+ with_attributes app_name: app_name
9
+ with_template "database.yml.erb"
10
+ end
11
+
12
+ def update
13
+ # back up existing file
14
+ FileUtils.mv file_path, "config/database.pre_docker.yml"
15
+ self.write
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,34 @@
1
+ version: '3.4'
2
+
3
+ services:
4
+ new_rails:
5
+ build:
6
+ context: .
7
+ target: new_rails
8
+ dockerfile: Dockerfile.init
9
+ volumes:
10
+ - .:/app/<%= app_name %>
11
+ - gem_cache:/gems
12
+
13
+ bundle:
14
+ build:
15
+ context: .
16
+ target: bundle_for_lockfile
17
+ dockerfile: Dockerfile.init
18
+ volumes:
19
+ - .:/app/<%= app_name %>
20
+ - gem_cache:/gems
21
+
22
+ install_webpacker:
23
+ build:
24
+ context: .
25
+ target: install_webpacker
26
+ dockerfile: Dockerfile.init
27
+ volumes:
28
+ - .:/app/<%= app_name %>
29
+ - gem_cache:/gems
30
+ - node_modules:/app/<%= app_name %>/node_modules
31
+
32
+ volumes:
33
+ gem_cache:
34
+ node_modules:
@@ -0,0 +1,70 @@
1
+ version: '3.4'
2
+
3
+ services:
4
+ reverseproxy:
5
+ build:
6
+ context: .
7
+ target: reverse_proxy
8
+ restart: always
9
+ ports:
10
+ - "127.0.0.1:3001:3001"
11
+ web:
12
+ build:
13
+ context: .
14
+ target: dev_environment
15
+ restart: always
16
+ ports:
17
+ - "3000:3000"
18
+ volumes:
19
+ - .:/app/<%= app_name %>
20
+ - gem_cache:/gems
21
+ - node_modules:/app/<%= app_name %>/node_modules
22
+ env_file:
23
+ - .env/development/web
24
+ - .env/development/database
25
+ environment:
26
+ - WEBPACKER_DEV_SERVER_HOST=webpack-dev-server
27
+
28
+ database:
29
+ image: postgres
30
+ volumes:
31
+ - db_data:/var/lib/postgresql/data
32
+ env_file:
33
+ - .env/development/database
34
+
35
+ webpack-dev-server:
36
+ build:
37
+ context: .
38
+ target: dev_environment
39
+ command: ./bin/webpack-dev-server
40
+ ports:
41
+ - "3035:3035"
42
+ volumes:
43
+ - .:/app/<%= app_name %>
44
+ - gem_cache:/gems
45
+ - node_modules:/app/<%= app_name %>/node_modules
46
+ env_file:
47
+ - .env/development/web
48
+ - .env/development/database
49
+ environment:
50
+ - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
51
+
52
+ production:
53
+ build:
54
+ context: .
55
+ target: production
56
+ image: <%= image_path %>
57
+ ports:
58
+ - "3000:3000"
59
+ volumes:
60
+ - .:/app/<%= app_name %>
61
+ - gem_cache:/gems
62
+ - node_modules:/app/<%= app_name %>/node_modules
63
+ env_file:
64
+ - .env/production/web
65
+ - .env/production/database
66
+
67
+ volumes:
68
+ gem_cache:
69
+ node_modules:
70
+ db_data:
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ #
3
+ # The start up script for the web service defined for Compose.
4
+ #
5
+ # It attempts to tidy up any orphaned PID files created by the app before
6
+ # calling the CMD as defined in the Dockerfile that uses this script as
7
+ # an ENTRYPOINT.
8
+
9
+ if [ -f tmp/pids/server.pid ]; then
10
+ echo "Removing server.pid file"
11
+ rm tmp/pids/server.pid
12
+ fi
13
+
14
+ # Dependencies are managed as part of the development workflow on mounted volumes. As such, they
15
+ # are installed on container start-up. If the mounted volumes already include the dependencies, then
16
+ # this step should not take a lot of time.
17
+ bundle install
18
+ yarn install --check-files
19
+
20
+ exec "$@"
@@ -0,0 +1,35 @@
1
+ version: '3.4'
2
+
3
+ services:
4
+ reverseproxy:
5
+ image: <%= proxy_image_path %>
6
+ restart: always
7
+ ports:
8
+ - "127.0.0.1:3001:3001"
9
+ web:
10
+ image: <%= image_path %>
11
+ ports:
12
+ - "3000:3000"
13
+ env_file:
14
+ - .env/production/web
15
+ - .env/production/database
16
+
17
+ database:
18
+ image: postgres
19
+ volumes:
20
+ - db_data:/var/lib/postgresql/data
21
+ env_file:
22
+ - .env/production/database
23
+
24
+ db-migrator:
25
+ image: <%= image_path %>
26
+ command: ["./bin/wait-for", "--timeout=300", "database:5432", "--", "bin/rails", "db:migrate"]
27
+ env_file:
28
+ - .env/production/database
29
+ - .env/production/web
30
+ deploy:
31
+ restart_policy:
32
+ condition: none
33
+
34
+ volumes:
35
+ db_data:
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ module Wellcar
4
+ module Templates
5
+ class DockerCompose < Base
6
+ INIT_TEMPLATE = "docker-compose-init.yml.erb"
7
+
8
+ def initialize(app_name, repo_account, template_name="docker-compose.yml.erb")
9
+ super "docker-compose.yml"
10
+ with_attributes app_name: app_name,
11
+ template_name: template_name,
12
+ repo_account: repo_account,
13
+ registry_url: "docker.pkg.github.com"
14
+ with_template template_name
15
+ end
16
+
17
+ def image_path
18
+ [registry_url, repo_account, app_name, "web"].join "/"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ module Wellcar
4
+ module Templates
5
+ class DockerEntrypoint < Base
6
+ def initialize
7
+ super "bin/docker-entrypoint.sh"
8
+ with_template "docker-entrypoint.sh.erb"
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), "base")
2
+
3
+ module Wellcar
4
+ module Templates
5
+ class DockerStack < Base
6
+ def initialize(app_name, repo_account)
7
+ super "docker-stack.yml"
8
+ with_attributes app_name: app_name,
9
+ repo_account: repo_account,
10
+ registry_url: "docker.pkg.github.com"
11
+ with_template "docker-stack.yml.erb"
12
+ end
13
+
14
+ def image_path
15
+ [registry_url, repo_account, app_name, "web"].join "/"
16
+ end
17
+
18
+ def proxy_image_path
19
+ [registry_url, repo_account, app_name, "nginx"].join "/"
20
+ end
21
+ end
22
+ end
23
+ end