mkbrut 0.1.6 → 0.2.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49cd2e6faac641d120b2648a5d40bb859e042494d483bda48c4637bfbe693b23
4
- data.tar.gz: d72aeb805b18f85086b3f5476b4d658c073d1223e2c7e3d1b3fc65f78649b1b4
3
+ metadata.gz: e824bb238690c5bedee83be7104bc4a8a4e82c5a46fbf4aa75253e16c83ef036
4
+ data.tar.gz: 495469a00fc5fee4adf35057cd03cb6f942551c60954d8639b780fe2896d5aff
5
5
  SHA512:
6
- metadata.gz: 43e48d2ae6524b03a1735530c90af8afb01c0635dd6e2f72c04bc3966fbddadc33379e0e7026c67d09b6ee52fccb17321a1515394d1126d9af804e7fe202e8f1
7
- data.tar.gz: 307ae6b40477978aa51bf3031f8c58d2f9d9b99c51148e9c33303d33a8e9b79f7a8a1db3f4052ff0e84eacf78ffb12843f30e0558f95c51190574bb56cb1bbcc
6
+ metadata.gz: 6518144e68422c5673413ab1539a064721d3f230a6953b785dbb23056b03e8cc6ebdeb9ae02bd7b57aa8f21a854747396aa65b45e6b7d1c0269a79c639ccd7ab
7
+ data.tar.gz: d101e05f6d7afef6115be141f3307f8360bde7f1976ef1129ed3584cbd2fe6a502d721be27042afd7d296a3fd12a15974e79c5c3ff387d484bd8827a1a65b620
data/lib/mkbrut/app.rb CHANGED
@@ -43,6 +43,18 @@ module MKBrut
43
43
  templates_dir:
44
44
  )
45
45
  end
46
+ app_options.segments.each do |segment|
47
+ case segment
48
+ when "heroku"
49
+ @segments << MKBrut::Segments::Heroku.new(
50
+ app_options:,
51
+ current_dir:,
52
+ templates_dir:
53
+ )
54
+ else
55
+ raise "Segment #{segment} is not supported"
56
+ end
57
+ end
46
58
  end
47
59
 
48
60
  def create!
@@ -1,5 +1,5 @@
1
1
  class MKBrut::AppOptions
2
- attr_reader :app_name, :app_id, :prefix, :organization, :demo, :versions
2
+ attr_reader :app_name, :app_id, :prefix, :organization, :demo, :versions, :segments
3
3
 
4
4
  def initialize(
5
5
  app_name:,
@@ -9,7 +9,7 @@ class MKBrut::AppOptions
9
9
  organization: nil,
10
10
  demo: false,
11
11
  versions: nil,
12
- **ignore
12
+ **rest
13
13
  )
14
14
  if app_name.nil?
15
15
  raise ArgumentError, "app_name is required"
@@ -22,6 +22,13 @@ class MKBrut::AppOptions
22
22
  @dry_run = !!dry_run
23
23
  @demo = !!demo
24
24
  @versions = versions
25
+ @segments = rest.map { |key,value|
26
+ if key =~ /^segment-(.+)$/ && value
27
+ $1
28
+ else
29
+ nil
30
+ end
31
+ }.compact
25
32
  end
26
33
 
27
34
  def dry_run? = @dry_run
data/lib/mkbrut/cli.rb CHANGED
@@ -28,7 +28,7 @@ module MKBrut
28
28
  1
29
29
  end
30
30
 
31
- def show_help
31
+ def show_help(versions)
32
32
  @out.puts @option_parser
33
33
  @out.puts
34
34
  @out.puts "ARGUMENTS"
@@ -39,6 +39,14 @@ module MKBrut
39
39
  @out.puts
40
40
  @out.puts " BRUT_CLI_RAISE_ON_ERROR - if set to 'true', any error will raise an exception instead of printing to stderr"
41
41
  @out.puts
42
+ @out.puts "BRUT VERSIONS"
43
+ @out.puts
44
+ @out.puts " Your app will be set up to use these versions:"
45
+ @out.puts
46
+ @out.puts " BrutRB - #{versions.brut_version_specifier}"
47
+ @out.puts " BrutJS - #{versions.brut_js_version_specifier}"
48
+ @out.puts " BrutCSS - #{versions.brut_css_version_specifier}"
49
+ @out.puts
42
50
 
43
51
  end
44
52
 
@@ -57,7 +65,18 @@ module MKBrut
57
65
  opts.accept(MKBrut::Organization) do |prefix|
58
66
  MKBrut::Organization.new(prefix)
59
67
  end
60
- opts.banner = "Usage: mkbrut [options] app-name\n\n Creates a new Brut-powered app\n\nOPTIONS\n\n"
68
+ opts.banner = [
69
+ "Usage: mkbrut [options] app-name",
70
+ "",
71
+ " Creates a new Brut-powered app",
72
+ "",
73
+ "VERSION",
74
+ "",
75
+ " #{MKBrut::VERSION}",
76
+ "",
77
+ "OPTIONS",
78
+ "",
79
+ ].join("\n")
61
80
 
62
81
  opts.on("-a", "--app-id=ID", MKBrut::AppId,
63
82
  "App identifier, which must be able to be used as a hostname or other Internet identifier. Derived from your app name, if omitted")
@@ -70,8 +89,14 @@ module MKBrut
70
89
 
71
90
  opts.on("--dry-run", "Only show what would happen, don't actually do anything")
72
91
  opts.on("--[no-]demo", "Include, or not, additional files that demonstrate Brut's features (default is true for now")
92
+ {
93
+ "sidekiq" => "Use Sidekiq for background jobs",
94
+ "heroku" => "Use Heroku for container-based deployment",
95
+ }.each do |segment,description|
96
+ opts.on("--segment-#{segment}", description)
97
+ end
73
98
  opts.on("-h", "--help", "Show this help message") do
74
- show_help
99
+ show_help(versions)
75
100
  exit
76
101
  end
77
102
  end
@@ -0,0 +1,30 @@
1
+ class MKBrut::Segments::Heroku < MKBrut::Base
2
+ def self.friendly_name = "Heroku-based Deployment"
3
+
4
+ def initialize(app_options:, current_dir:, templates_dir:)
5
+ @project_root = current_dir / app_options.app_name
6
+ @templates_dir = templates_dir / "segments" / "Heroku"
7
+ @erb_binding = MKBrut::ErbBindingDelegate.new(app_options)
8
+ end
9
+
10
+ def add!
11
+ operations = copy_files(@templates_dir, @project_root) +
12
+ other_operations
13
+
14
+ operations.each do |operation|
15
+ operation.call
16
+ end
17
+ end
18
+
19
+ def other_operations
20
+ [
21
+ MKBrut::Ops::AppendToFile.new(
22
+ file: @project_root / ".gitignore",
23
+ content: %{
24
+ # These are generated by bin/deploy
25
+ deploy/Dockerfile.*
26
+ }
27
+ )
28
+ ]
29
+ end
30
+ end
@@ -3,5 +3,6 @@ module MKBrut
3
3
  autoload :BareBones, "mkbrut/segments/bare_bones"
4
4
  autoload :Demo, "mkbrut/segments/demo"
5
5
  autoload :Sidekiq, "mkbrut/segments/demo"
6
+ autoload :Heroku, "mkbrut/segments/heroku"
6
7
  end
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module MKBrut
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.7"
3
3
  end
data/lib/mkbrut.rb CHANGED
@@ -14,4 +14,5 @@ module MKBrut
14
14
  autoload :Segments, "mkbrut/segments"
15
15
  autoload :Versions, "mkbrut/versions"
16
16
  autoload :PrefixedIO, "mkbrut/prefixed_io"
17
+ autoload :VERSION, "mkbrut/version"
17
18
  end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler"
4
+ Bundler.require
5
+ require "pathname"
6
+ require "brut/cli/apps/heroku_container_based_deploy"
7
+
8
+ exit Brut::CLI.app(
9
+ Brut::CLI::Apps::HerokuContainerBasedDeploy,
10
+ project_root: Pathname($0).dirname / ".."
11
+ )
@@ -0,0 +1,125 @@
1
+ # This is a multi-stage build, meaning one image will be built that
2
+ # has necessarily dev tools in it, and that image is used to create artifacts
3
+ # that will be copied into the second build, which will create the image
4
+ # you deploy to production.
5
+ #
6
+ # # Maintaing this file
7
+ #
8
+ # You own this file now. While there could be a way to create it from
9
+ # the Dockerfile.dx, for now, you'll need to stay on top of it:
10
+ #
11
+ # 1 - ensure the versions of Ruby match
12
+ # 2 - ensure the versions of NodeJS match
13
+ # 3 - ensure that anything you installed in Dockerfile.dx to make
14
+ # the app work or to pre-generate assets is set up here as well.
15
+ # You are advised to make that setup identical.
16
+ #
17
+ # You can test this locally but using the `--plaform` flag to `bin/deploy deploy`
18
+ # and running a container locally. You'll need all infrastructure available
19
+ # but it can be done to test things before you deploy. If you need to.
20
+
21
+ # Use Ruby 3.4 as a base.
22
+ FROM docker.io/library/ruby:3.4 AS base
23
+
24
+ # bin/deploy will inject this value so that your app's GIT SHA1
25
+ # is in the environment in production, thus allowing you to be more
26
+ # sure of what's actually running.
27
+ ARG app_git_sha1
28
+
29
+ WORKDIR /brut-app
30
+
31
+ # Install base packages
32
+ #
33
+ # - ca-certificates is needed for other installs
34
+ # - curl is needed generally for other installs and by Heroku
35
+ # - gnupg is a PGP replacement used in making sure new APT repos work
36
+ # - libjemalloc2 in theory speeds up Ruby
37
+ # - lsb-release is used to generically access information for this OS's version
38
+ # - wget allows us to copy/paste commands from vendors about how to install
39
+ # software even though it does the same thing as curl
40
+ RUN apt-get update --quiet --yes && \
41
+ apt-get install --no-install-recommends --quiet --yes \
42
+ ca-certificates \
43
+ curl \
44
+ gnupg \
45
+ libjemalloc2 \
46
+ lsb-release \
47
+ rsync \
48
+ wget && \
49
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
50
+
51
+ # Install the PostgreSQL client. The latest version is not available
52
+ # from Debian, so we set up our own. This should match what's in Dockerfile.dx
53
+ # and ideally the version of Postgres used in production.
54
+ #
55
+ # Incancation is based on: https://www.postgresql.org/download/linux/debian/
56
+ RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
57
+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
58
+ apt-get update && \
59
+ apt-get --yes --quiet install postgresql-client-16 && \
60
+ rm -rf /var/lib/apt/lists /var/cache/apt/archives
61
+
62
+ # Set basic env vars for production
63
+ ENV RACK_ENV="production" \
64
+ BUNDLE_DEPLOYMENT="1" \
65
+ BUNDLE_PATH="/usr/local/bundle" \
66
+ BUNDLE_WITHOUT="development" \
67
+ APP_GIT_SHA1="${app_git_sha1}"
68
+
69
+ # This makes a new image that we'll throw away after building
70
+ # needed artifacts.
71
+ FROM base AS build
72
+
73
+ # - build-essential is needed for almost any build tool we have to install
74
+ # - git is needed to install some things
75
+ # - libpq-dev is needed by postgres
76
+ # - pkg-config is, I guess, not considered "essential" (as in build-essential),
77
+ # but still needed to install downstream stuff
78
+ RUN apt-get update --quiet --yes && \
79
+ apt-get install --no-install-recommends --quiet --yes \
80
+ build-essential \
81
+ git \
82
+ libpq-dev \
83
+ pkg-config
84
+
85
+ # Install NodeJS, per https://nodejs.org/en/download
86
+ RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash && \
87
+ \. "$HOME/.nvm/nvm.sh" && \
88
+ nvm install 22 && \
89
+ node -v && nvm current && npm -v
90
+
91
+ # Copy the app into the file, excluding the contents of .dockerignore
92
+ COPY . .
93
+
94
+ # Install RubyGems from app's Gemfile
95
+ RUN bundle install --verbose && \
96
+ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
97
+
98
+ # Install Node Modules from package.json
99
+ RUN \. "$HOME/.nvm/nvm.sh" && \
100
+ nvm use default && \
101
+ npm clean-install --no-audit --no-fund --verbose
102
+
103
+ # Build all assets
104
+ RUN \. "$HOME/.nvm/nvm.sh" && \
105
+ nvm use default && \
106
+ bin/build-assets && \
107
+ rm -rf node_modules
108
+
109
+ # We are now switching back to building the image that will be deployed.
110
+
111
+ FROM base
112
+ # Copy built artifacts from the throwaway image: gems, application
113
+ COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
114
+ COPY --from=build /brut-app /brut-app
115
+
116
+ # For security, set directories that will be written to be owned by non-root
117
+ RUN groupadd --system --gid 1000 brut && \
118
+ useradd brut --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
119
+ chown -R brut:brut logs tmp
120
+ USER 1000:1000
121
+
122
+ # This is used to execute other commands. When the app is run in production,
123
+ # this script is used to run it.
124
+ ENTRYPOINT ["/brut-app/deploy/docker-entrypoint"]
125
+
@@ -0,0 +1,26 @@
1
+ # This contains settings for your Heroku setup.
2
+ # You own and maintain this file. It is required by
3
+ # build/deploy
4
+ class HerokuConfig
5
+
6
+ # Return a Hash oif additional images to run, beyond "web" and "release".
7
+ #
8
+ # The format of this Hash is:
9
+ #
10
+ # {
11
+ # "«image name» => {
12
+ # cmd: "«command line for Dockerfile RUN directive»",
13
+ # }
14
+ # }
15
+ #
16
+ # For example, if you have the Sidekiq segment installed, `bin/run-sidekiq`
17
+ # runs Sidekiq, so you would return this hash:
18
+ #
19
+ # {
20
+ # "sidekiq" => {
21
+ # cmd: "bin/run-sidekiq",
22
+ # }
23
+ # }
24
+ def self.additional_images = {}
25
+ end
26
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkbrut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Copeland
@@ -76,6 +76,7 @@ files:
76
76
  - lib/mkbrut/segments.rb
77
77
  - lib/mkbrut/segments/bare_bones.rb
78
78
  - lib/mkbrut/segments/demo.rb
79
+ - lib/mkbrut/segments/heroku.rb
79
80
  - lib/mkbrut/segments/sidekiq.rb
80
81
  - lib/mkbrut/version.rb
81
82
  - lib/mkbrut/versions.rb
@@ -178,6 +179,9 @@ files:
178
179
  - templates/segments/Demo/specs/front_end/pages/guestbook_page.spec.rb
179
180
  - templates/segments/Demo/specs/front_end/pages/guestbook_page/message_component.spec.rb
180
181
  - templates/segments/Demo/specs/front_end/pages/new_guestbook_message_page.spec.rb
182
+ - templates/segments/Heroku/bin/deploy
183
+ - templates/segments/Heroku/deploy/Dockerfile
184
+ - templates/segments/Heroku/deploy/heroku_config.rb
181
185
  homepage: https://brutrb.com
182
186
  licenses: []
183
187
  metadata: {}