spoor 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e753dfd8783faeab768126a5e3bc0345a1aedd4685f03e4312c51793d59e27d
4
+ data.tar.gz: 9177f98d6fae90df617a85d045b10c445088bb892669bb203e1d30dfad749790
5
+ SHA512:
6
+ metadata.gz: 473146d3972978b0cf78b5897404a22d72688d58791d2ca5133521b48abbc3c11d0f911cae4de1dd466294065e32084b139fcf3014ca0bd5de56ece2cc70dfd6
7
+ data.tar.gz: 1a103f17f9e49b4787de023e9413ade6966cd117ec863db6ab8a79351e54b7312a2557cef6a90e10314142691cca0e26f525f8a8a3c5e6423379355d2b0d88c7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-01-08
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 mohammed-bageri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # Spoor
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/spoor.svg)](https://badge.fury.io/rb/spoor)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Spoor is a **Docker-based development environment** for Ruby on Rails applications, inspired by Laravel Sail. It simplifies setting up and managing a Dockerized development environment, allowing you to focus on building your Rails application.
7
+
8
+ ---
9
+
10
+ ## Prerequisites
11
+
12
+ Before using Spoor, ensure that **Docker** is installed and running on your system. You can download Docker from [https://www.docker.com/](https://www.docker.com/).
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ Add the gem to your Rails application's `Gemfile`:
19
+
20
+ ```ruby
21
+ gem "spoor"
22
+ ```
23
+
24
+ Then run:
25
+
26
+ ```bash
27
+ bundle install
28
+ ```
29
+
30
+ After installing the gem, set up Spoor in your project:
31
+
32
+ ```bash
33
+ spoor install
34
+ ```
35
+
36
+ This will generate the necessary `docker-compose.yml` and `.env` files. If your project already has a `Dockerfile`, it will not be overwritten unless you use the `--force-dockerfile` flag:
37
+
38
+ ```bash
39
+ spoor install --force-dockerfile
40
+ ```
41
+
42
+ ---
43
+
44
+ ## Usage
45
+
46
+ ### Start the Environment
47
+
48
+ To start the Spoor environment, run:
49
+
50
+ ```bash
51
+ spoor up
52
+ ```
53
+
54
+ This will start the Docker containers in the background.
55
+
56
+ ### Stop the Environment
57
+
58
+ To stop the environment, run:
59
+
60
+ ```bash
61
+ spoor down
62
+ ```
63
+
64
+ ### Run Rails Commands
65
+
66
+ You can run Rails commands inside the Docker container using:
67
+
68
+ ```bash
69
+ spoor rails <command>
70
+ ```
71
+
72
+ For example:
73
+
74
+ ```bash
75
+ spoor rails console
76
+ spoor rails db:migrate
77
+ ```
78
+
79
+ ### Run Bundler Commands
80
+
81
+ To run Bundler commands, use:
82
+
83
+ ```bash
84
+ spoor bundle <command>
85
+ ```
86
+
87
+ For example:
88
+
89
+ ```bash
90
+ spoor bundle install
91
+ ```
92
+
93
+ ### Access the Database
94
+
95
+ To start a PostgreSQL CLI session, run:
96
+
97
+ ```bash
98
+ spoor psql
99
+ ```
100
+
101
+ ### Access Redis
102
+
103
+ To start a Redis CLI session, run:
104
+
105
+ ```bash
106
+ spoor redis
107
+ ```
108
+
109
+ ### Start a Shell in the App Container
110
+
111
+ To start a Bash shell in the app container, run:
112
+
113
+ ```bash
114
+ spoor bash
115
+ ```
116
+
117
+ ---
118
+
119
+ ## Configuration
120
+
121
+ ### Environment Variables
122
+
123
+ The `.env` file generated during installation contains the following environment variables:
124
+
125
+ ```env
126
+ APP_PORT=3000
127
+ FORWARD_DB_PORT=5432
128
+ FORWARD_REDIS_PORT=6379
129
+ WWWUSER=1000
130
+ WWWGROUP=1000
131
+ ```
132
+
133
+ You can customize these values to fit your project's needs.
134
+
135
+ ### Docker Compose
136
+
137
+ The `docker-compose.yml` file is pre-configured with the following services:
138
+
139
+ - **web**: The Rails application.
140
+ - **db**: PostgreSQL database.
141
+ - **redis**: Redis for caching or background jobs.
142
+
143
+ You can modify this file to add or remove services as needed.
144
+
145
+ ---
146
+
147
+ ## Example Workflow
148
+
149
+ 1. Install Spoor:
150
+
151
+ ```bash
152
+ spoor install
153
+ ```
154
+
155
+ 2. Start the environment:
156
+
157
+ ```bash
158
+ spoor up
159
+ ```
160
+
161
+ 3. Run database migrations:
162
+
163
+ ```bash
164
+ spoor rails db:migrate
165
+ ```
166
+
167
+ 4. Access the Rails console:
168
+
169
+ ```bash
170
+ spoor rails console
171
+ ```
172
+
173
+ 5. Stop the environment when done:
174
+
175
+ ```bash
176
+ spoor down
177
+ ```
178
+
179
+ ---
180
+
181
+ ## Contributing
182
+
183
+ Contributions are welcome! If you'd like to contribute to Spoor, please follow these steps:
184
+
185
+ 1. Fork the repository.
186
+ 2. Create a new branch for your feature or bug fix.
187
+ 3. Commit your changes.
188
+ 4. Submit a pull request.
189
+
190
+ ---
191
+
192
+ ## License
193
+
194
+ Spoor is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).
195
+
196
+ ---
197
+
198
+ ## Support
199
+
200
+ If you encounter any issues or have questions, please [open an issue](https://github.com/mohammed-bageri/spoor/issues) on GitHub.
data/exe/spoor ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "spoor"
4
+
5
+ Spoor::CLI.start(ARGV)
data/lib/spoor/cli.rb ADDED
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "dotenv"
5
+
6
+ module Spoor
7
+ # Main CLI that run the command
8
+ class CLI < Thor
9
+ include Thor::Actions
10
+
11
+ def initialize(*args)
12
+ super
13
+ Dotenv.load(".env") # Load .env file
14
+ end
15
+
16
+ desc "install", "Install Spoor in the current project"
17
+ option :force_dockerfile, type: :boolean, default: false, desc: "Overwrite the existing Dockerfile"
18
+ def install
19
+ Spoor.install(force_dockerfile: options[:force_dockerfile])
20
+ end
21
+
22
+ desc "up", "Start the Spoor environment"
23
+ def up
24
+ Spoor.check_docker
25
+ say "Starting Spoor..."
26
+ system("docker-compose up -d")
27
+ end
28
+
29
+ desc "down", "Stop the Spoor environment"
30
+ def down
31
+ Spoor.check_docker
32
+ say "Stopping Spoor..."
33
+ system("docker-compose down")
34
+ end
35
+
36
+ desc "rails COMMAND", "Run a Rails command"
37
+ def rails(*args)
38
+ Spoor.check_docker
39
+ run_in_container("web", "rails", *args)
40
+ end
41
+
42
+ desc "bundle COMMAND", "Run a Bundler command"
43
+ def bundle(*args)
44
+ Spoor.check_docker
45
+ run_in_container("web", "bundle", *args)
46
+ end
47
+
48
+ desc "rake COMMAND", "Run a Rake command"
49
+ def rake(*args)
50
+ Spoor.check_docker
51
+ run_in_container("web", "rake", *args)
52
+ end
53
+
54
+ desc "psql", "Start a PostgreSQL CLI session"
55
+ def psql
56
+ Spoor.check_docker
57
+ run_in_container("db", "psql", "-U", "rails", "-d", "rails_development")
58
+ end
59
+
60
+ desc "redis", "Start a Redis CLI session"
61
+ def redis
62
+ Spoor.check_docker
63
+ run_in_container("redis", "redis-cli")
64
+ end
65
+
66
+ desc "bash", "Start a Bash shell in the app container"
67
+ def bash
68
+ Spoor.check_docker
69
+ run_in_container("web", "bash")
70
+ end
71
+
72
+ private
73
+
74
+ def run_in_container(service, *command)
75
+ system("docker-compose exec #{service} #{command.join(" ")}")
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,21 @@
1
+ # Use the Ruby version detected from the Rails app
2
+ FROM ruby:<%= ruby_version %>
3
+
4
+ # Install dependencies
5
+ RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
6
+
7
+ # Set the working directory
8
+ WORKDIR /myapp
9
+
10
+ # Install gems
11
+ COPY Gemfile Gemfile.lock ./
12
+ RUN bundle install
13
+
14
+ # Copy the application code
15
+ COPY . .
16
+
17
+ # Expose port 3000
18
+ EXPOSE 3000
19
+
20
+ # Start the Rails server
21
+ CMD ["rails", "server", "-b", "0.0.0.0"]
@@ -0,0 +1,55 @@
1
+ version: "3.8"
2
+
3
+ services:
4
+ web:
5
+ build:
6
+ context: .
7
+ dockerfile: Dockerfile
8
+ image: rails-app
9
+ environment:
10
+ RAILS_ENV: development
11
+ DATABASE_HOST: db
12
+ REDIS_HOST: redis
13
+ WWWUSER: "${WWWUSER:-1000}"
14
+ WWWGROUP: "${WWWGROUP:-1000}"
15
+ ports:
16
+ - "${APP_PORT:-3000}:3000"
17
+ volumes:
18
+ - ".:/myapp"
19
+ networks:
20
+ - spoor-network
21
+ depends_on:
22
+ - db
23
+ - redis
24
+
25
+ db:
26
+ image: postgres:latest
27
+ environment:
28
+ POSTGRES_USER: rails
29
+ POSTGRES_PASSWORD: password
30
+ POSTGRES_DB: rails_development
31
+ ports:
32
+ - "${FORWARD_DB_PORT:-5432}:5432"
33
+ volumes:
34
+ - postgres_data:/var/lib/postgresql/data
35
+ networks:
36
+ - spoor-network
37
+
38
+ redis:
39
+ image: redis:latest
40
+ ports:
41
+ - "${FORWARD_REDIS_PORT:-6379}:6379"
42
+ volumes:
43
+ - redis_data:/data
44
+ networks:
45
+ - spoor-network
46
+
47
+ networks:
48
+ spoor-network:
49
+ driver: bridge
50
+
51
+ volumes:
52
+ postgres_data:
53
+ driver: local
54
+ redis_data:
55
+ driver: local
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spoor
4
+ VERSION = "0.1.1"
5
+ end
data/lib/spoor.rb ADDED
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spoor/version"
4
+ require "spoor/cli"
5
+ require "fileutils"
6
+
7
+ # Spoor ClI
8
+ module Spoor
9
+ def self.docker_installed?
10
+ # Check if Docker is installed
11
+ system("docker --version > /dev/null 2>&1")
12
+ end
13
+
14
+ def self.docker_running?
15
+ # Check if Docker is running
16
+ system("docker info > /dev/null 2>&1")
17
+ end
18
+
19
+ def self.check_docker
20
+ unless docker_installed?
21
+ puts "Docker is not installed. Please install Docker and try again."
22
+ exit 1
23
+ end
24
+
25
+ return if docker_running?
26
+
27
+ puts "Docker is not running. Please start Docker and try again."
28
+ exit 1
29
+ end
30
+
31
+ def self.detect_ruby_version
32
+ # Check for .ruby-version file
33
+ return File.read(".ruby-version").strip if File.exist?(".ruby-version")
34
+
35
+ # Check for Ruby version in Gemfile
36
+ if File.exist?("Gemfile")
37
+ gemfile_content = File.read("Gemfile")
38
+ if match = gemfile_content.match(/ruby ['"]([^'"]+)['"]/)
39
+ return match[1]
40
+ end
41
+ end
42
+
43
+ # Default to a supported Ruby version
44
+ "3.2.0"
45
+ end
46
+
47
+ def self.install(force_dockerfile: false) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
48
+ check_docker
49
+
50
+ # Copy docker-compose.yml
51
+ FileUtils.cp(
52
+ File.join(__dir__, "spoor", "templates", "docker-compose.yml"),
53
+ "docker-compose.yml"
54
+ )
55
+
56
+ # Copy .env
57
+ FileUtils.cp(
58
+ File.join(__dir__, "spoor", "templates", ".env"),
59
+ ".env"
60
+ )
61
+
62
+ # Copy Dockerfile only if it doesn't exist or if forced
63
+ dockerfile_path = File.join(Dir.pwd, "Dockerfile")
64
+ if force_dockerfile || !File.exist?(dockerfile_path)
65
+ ruby_version = detect_ruby_version
66
+ dockerfile_content = ERB.new(File.read(File.join(__dir__, "spoor", "templates",
67
+ "Dockerfile.erb"))).result(binding)
68
+ File.write(dockerfile_path, dockerfile_content)
69
+ end
70
+
71
+ puts "Spoor has been installed! Run `spoor up` to start the environment."
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spoor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mohammed Bageri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Spoor simplifies setting up and managing a Dockerized development environment
84
+ for Ruby on Rails applications.
85
+ email:
86
+ - mohammed.bajiri.00@gmail.com
87
+ executables:
88
+ - spoor
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - CHANGELOG.md
93
+ - LICENSE.txt
94
+ - README.md
95
+ - exe/spoor
96
+ - lib/spoor.rb
97
+ - lib/spoor/cli.rb
98
+ - lib/spoor/templates/Dockerfile.erb
99
+ - lib/spoor/templates/docker-compose.yml
100
+ - lib/spoor/version.rb
101
+ homepage: https://github.com/mohammed-bageri/spoor
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ source_code_uri: https://github.com/mohammed-bageri/spoor
106
+ changelog_uri: https://github.com/mohammed-bageri/spoor/blob/main/CHANGELOG.md
107
+ allowed_push_host: https://rubygems.org
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.5.16
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: A Docker-based development environment for Rails, inspired by Laravel Sail.
127
+ test_files: []