quoll-cli 0.2.0__py3-none-any.whl
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.
- quoll/__init__.py +0 -0
- quoll/cd/__init__.py +1 -0
- quoll/cd/config.py +75 -0
- quoll/ci/__init__.py +0 -0
- quoll/ci/config.py +213 -0
- quoll/ci/custom.py +32 -0
- quoll/ci/detect.py +139 -0
- quoll/ci/steps.py +85 -0
- quoll/ci/tools.py +104 -0
- quoll/commands/__init__.py +0 -0
- quoll/commands/_common.py +145 -0
- quoll/commands/_workspace.py +83 -0
- quoll/commands/add.py +104 -0
- quoll/commands/add_secret.py +75 -0
- quoll/commands/cd.py +214 -0
- quoll/commands/ci.py +521 -0
- quoll/commands/docker.py +244 -0
- quoll/commands/k8s.py +211 -0
- quoll/commands/new.py +337 -0
- quoll/commands/remove.py +79 -0
- quoll/config/__init__.py +0 -0
- quoll/config/quoll_toml.py +196 -0
- quoll/config/settings.py +22 -0
- quoll/config/store.py +39 -0
- quoll/console.py +3 -0
- quoll/docker/__init__.py +1 -0
- quoll/docker/config.py +64 -0
- quoll/docker/detect.py +41 -0
- quoll/docker/render.py +162 -0
- quoll/files.py +64 -0
- quoll/k8s/__init__.py +0 -0
- quoll/k8s/chart/templates/_helpers.tpl +38 -0
- quoll/k8s/chart/templates/deployment.yaml +93 -0
- quoll/k8s/chart/templates/hpa.yaml +24 -0
- quoll/k8s/chart/templates/ingress.yaml +35 -0
- quoll/k8s/chart/templates/pdb.yaml +16 -0
- quoll/k8s/chart/templates/service.yaml +18 -0
- quoll/k8s/chart/templates/serviceaccount.yaml +10 -0
- quoll/k8s/ci.py +39 -0
- quoll/k8s/config.py +97 -0
- quoll/k8s/deploy.py +22 -0
- quoll/k8s/detect.py +32 -0
- quoll/k8s/render.py +94 -0
- quoll/languages/__init__.py +121 -0
- quoll/languages/base.py +350 -0
- quoll/languages/cpp/Dockerfile.j2 +37 -0
- quoll/languages/cpp/__init__.py +17 -0
- quoll/languages/cpp/ci.py +192 -0
- quoll/languages/cpp/detect.py +84 -0
- quoll/languages/cpp/docker.py +47 -0
- quoll/languages/dotnet/Dockerfile.j2 +21 -0
- quoll/languages/dotnet/__init__.py +17 -0
- quoll/languages/dotnet/ci.py +88 -0
- quoll/languages/dotnet/detect.py +53 -0
- quoll/languages/dotnet/docker.py +47 -0
- quoll/languages/go/Dockerfile.j2 +25 -0
- quoll/languages/go/__init__.py +17 -0
- quoll/languages/go/ci.py +126 -0
- quoll/languages/go/detect.py +30 -0
- quoll/languages/go/docker.py +40 -0
- quoll/languages/java/Dockerfile.j2 +28 -0
- quoll/languages/java/__init__.py +20 -0
- quoll/languages/java/ci.py +163 -0
- quoll/languages/java/detect.py +77 -0
- quoll/languages/java/docker.py +45 -0
- quoll/languages/java/frameworks/__init__.py +1 -0
- quoll/languages/java/frameworks/spring_boot/Dockerfile.j2 +18 -0
- quoll/languages/java/frameworks/spring_boot/__init__.py +10 -0
- quoll/languages/java/frameworks/spring_boot/detect.py +9 -0
- quoll/languages/java/frameworks/spring_boot/docker.py +19 -0
- quoll/languages/java/frameworks/spring_boot/services.py +24 -0
- quoll/languages/node/Dockerfile.j2 +98 -0
- quoll/languages/node/__init__.py +29 -0
- quoll/languages/node/ci.py +200 -0
- quoll/languages/node/detect.py +164 -0
- quoll/languages/node/docker.py +141 -0
- quoll/languages/node/frameworks/__init__.py +1 -0
- quoll/languages/node/frameworks/angular/__init__.py +18 -0
- quoll/languages/node/frameworks/angular/ci.py +34 -0
- quoll/languages/node/frameworks/angular/detect.py +20 -0
- quoll/languages/node/frameworks/angular/docker.py +31 -0
- quoll/languages/node/frameworks/angular/starter.py +74 -0
- quoll/languages/node/frameworks/astro/__init__.py +10 -0
- quoll/languages/node/frameworks/astro/ci.py +17 -0
- quoll/languages/node/frameworks/astro/detect.py +14 -0
- quoll/languages/node/frameworks/astro/docker.py +17 -0
- quoll/languages/node/frameworks/nestjs/__init__.py +7 -0
- quoll/languages/node/frameworks/nestjs/detect.py +9 -0
- quoll/languages/node/frameworks/nestjs/docker.py +10 -0
- quoll/languages/node/frameworks/nextjs/Dockerfile.j2 +14 -0
- quoll/languages/node/frameworks/nextjs/__init__.py +8 -0
- quoll/languages/node/frameworks/nextjs/ci.py +29 -0
- quoll/languages/node/frameworks/nextjs/detect.py +13 -0
- quoll/languages/node/frameworks/nextjs/docker.py +41 -0
- quoll/languages/node/frameworks/nuxt/__init__.py +10 -0
- quoll/languages/node/frameworks/nuxt/ci.py +17 -0
- quoll/languages/node/frameworks/nuxt/detect.py +17 -0
- quoll/languages/node/frameworks/nuxt/docker.py +24 -0
- quoll/languages/node/frameworks/sveltekit/__init__.py +15 -0
- quoll/languages/node/frameworks/sveltekit/ci.py +15 -0
- quoll/languages/node/frameworks/sveltekit/detect.py +18 -0
- quoll/languages/node/frameworks/sveltekit/docker.py +18 -0
- quoll/languages/node/starter.py +42 -0
- quoll/languages/node/templates/express/README.md +11 -0
- quoll/languages/node/templates/express/env.example +2 -0
- quoll/languages/node/templates/express/eslint.config.js +15 -0
- quoll/languages/node/templates/express/gitignore +4 -0
- quoll/languages/node/templates/express/nvmrc +1 -0
- quoll/languages/node/templates/express/package.json +16 -0
- quoll/languages/node/templates/express/prettierignore +6 -0
- quoll/languages/node/templates/express/src/app.ts +27 -0
- quoll/languages/node/templates/express/src/server.ts +11 -0
- quoll/languages/node/templates/express/test/app.test.ts +29 -0
- quoll/languages/node/templates/express/tsconfig.build.json +8 -0
- quoll/languages/node/templates/express/tsconfig.json +14 -0
- quoll/languages/node/templates/express/vitest.config.ts +12 -0
- quoll/languages/php/Dockerfile.j2 +40 -0
- quoll/languages/php/__init__.py +19 -0
- quoll/languages/php/ci.py +147 -0
- quoll/languages/php/detect.py +75 -0
- quoll/languages/php/docker.py +59 -0
- quoll/languages/php/frameworks/__init__.py +1 -0
- quoll/languages/php/frameworks/laravel/__init__.py +17 -0
- quoll/languages/php/frameworks/laravel/ci.py +24 -0
- quoll/languages/php/frameworks/laravel/detect.py +13 -0
- quoll/languages/php/frameworks/laravel/docker.py +29 -0
- quoll/languages/php/frameworks/laravel/services.py +25 -0
- quoll/languages/php/frameworks/symfony/__init__.py +15 -0
- quoll/languages/php/frameworks/symfony/ci.py +22 -0
- quoll/languages/php/frameworks/symfony/detect.py +17 -0
- quoll/languages/php/frameworks/symfony/docker.py +25 -0
- quoll/languages/python/Dockerfile.j2 +61 -0
- quoll/languages/python/__init__.py +19 -0
- quoll/languages/python/ci.py +157 -0
- quoll/languages/python/detect.py +175 -0
- quoll/languages/python/docker.py +80 -0
- quoll/languages/python/frameworks/__init__.py +1 -0
- quoll/languages/python/frameworks/django/__init__.py +16 -0
- quoll/languages/python/frameworks/django/ci.py +43 -0
- quoll/languages/python/frameworks/django/detect.py +17 -0
- quoll/languages/python/frameworks/django/docker.py +20 -0
- quoll/languages/python/frameworks/fastapi/__init__.py +7 -0
- quoll/languages/python/frameworks/fastapi/detect.py +9 -0
- quoll/languages/python/frameworks/fastapi/docker.py +21 -0
- quoll/languages/python/frameworks/flask/__init__.py +7 -0
- quoll/languages/python/frameworks/flask/detect.py +9 -0
- quoll/languages/python/frameworks/flask/docker.py +22 -0
- quoll/languages/ruby/Dockerfile.j2 +45 -0
- quoll/languages/ruby/__init__.py +19 -0
- quoll/languages/ruby/ci.py +110 -0
- quoll/languages/ruby/detect.py +72 -0
- quoll/languages/ruby/docker.py +63 -0
- quoll/languages/ruby/frameworks/__init__.py +1 -0
- quoll/languages/ruby/frameworks/rails/Dockerfile.j2 +16 -0
- quoll/languages/ruby/frameworks/rails/__init__.py +18 -0
- quoll/languages/ruby/frameworks/rails/ci.py +26 -0
- quoll/languages/ruby/frameworks/rails/detect.py +15 -0
- quoll/languages/ruby/frameworks/rails/docker.py +62 -0
- quoll/languages/ruby/frameworks/rails/services.py +10 -0
- quoll/languages/rust/Dockerfile.j2 +23 -0
- quoll/languages/rust/__init__.py +17 -0
- quoll/languages/rust/ci.py +125 -0
- quoll/languages/rust/detect.py +46 -0
- quoll/languages/rust/docker.py +38 -0
- quoll/main.py +50 -0
- quoll/platforms/__init__.py +62 -0
- quoll/platforms/base.py +103 -0
- quoll/platforms/github/__init__.py +4 -0
- quoll/platforms/github/actions.py +78 -0
- quoll/platforms/github/api.py +124 -0
- quoll/platforms/github/cd.py +265 -0
- quoll/platforms/github/ci.py +497 -0
- quoll/platforms/github/dependabot.yml.j2 +49 -0
- quoll/platforms/github/platform.py +52 -0
- quoll/platforms/github/workflow.py +74 -0
- quoll/platforms/gitlab/__init__.py +4 -0
- quoll/platforms/gitlab/api.py +158 -0
- quoll/platforms/gitlab/cd.py +226 -0
- quoll/platforms/gitlab/ci.py +400 -0
- quoll/platforms/gitlab/pipeline.py +136 -0
- quoll/platforms/gitlab/platform.py +54 -0
- quoll/project.py +60 -0
- quoll/services.py +117 -0
- quoll/starters.py +117 -0
- quoll/workspace.py +232 -0
- quoll/yaml_dump.py +137 -0
- quoll_cli-0.2.0.dist-info/METADATA +641 -0
- quoll_cli-0.2.0.dist-info/RECORD +191 -0
- quoll_cli-0.2.0.dist-info/WHEEL +4 -0
- quoll_cli-0.2.0.dist-info/entry_points.txt +2 -0
- quoll_cli-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence
|
|
4
|
+
|
|
5
|
+
from quoll.ci.steps import ROOT, Cache, Item, Step, on_github, step
|
|
6
|
+
from quoll.languages.base import THRESHOLD_REGEX, CISteps, TestReports
|
|
7
|
+
from quoll.platforms.github.actions import ACTIONS
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from quoll.ci.config import CIConfig
|
|
11
|
+
|
|
12
|
+
_LINT = {
|
|
13
|
+
"rubocop": ("RuboCop", "bundle exec rubocop"),
|
|
14
|
+
"standard": ("Standard", "bundle exec standardrb"),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_TEST = {"rspec": "bundle exec rspec", "minitest": "bundle exec rake test"}
|
|
18
|
+
_RSPEC_RUNNERS = ("rspec", "rails-rspec")
|
|
19
|
+
# RSpec's JUnit formatter, installed outside the bundle and loaded from its directory.
|
|
20
|
+
_RSPEC_JUNIT = "/tmp/quoll-rspec-junit"
|
|
21
|
+
_RSPEC_JUNIT_INSTALL = (
|
|
22
|
+
f"gem install --no-document --install-dir {_RSPEC_JUNIT} --ignore-dependencies rspec_junit_formatter -v '~> 0.6'"
|
|
23
|
+
)
|
|
24
|
+
_RSPEC_JUNIT_FLAGS = (
|
|
25
|
+
f' -I "$(echo {_RSPEC_JUNIT}/gems/rspec_junit_formatter-*/lib)" -r rspec_junit_formatter'
|
|
26
|
+
" --format progress --format RspecJunitFormatter --out junit.xml"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# SimpleCov writes the last line coverage to coverage/.last_run.json ("line" since 0.18, "covered_percent" before).
|
|
30
|
+
_SIMPLECOV_CHECK = """ruby -rjson -e '
|
|
31
|
+
result = JSON.parse(File.read("coverage/.last_run.json"))["result"]
|
|
32
|
+
pct = result["line"] || result["covered_percent"]
|
|
33
|
+
summary = ENV["GITHUB_STEP_SUMMARY"]
|
|
34
|
+
File.write(summary, format("### Coverage: %.1f%%\\n", pct), mode: "a") if summary
|
|
35
|
+
if pct < {threshold}
|
|
36
|
+
puts format("::error::Coverage %.1f%% is below the {threshold}%% threshold", pct)
|
|
37
|
+
exit 1
|
|
38
|
+
end
|
|
39
|
+
puts format("Coverage %.1f%% (threshold {threshold}%%)", pct)'"""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class RubyCI(CISteps):
|
|
43
|
+
version_key = "ruby-version"
|
|
44
|
+
codeql_language = "ruby"
|
|
45
|
+
|
|
46
|
+
def setup(self, cfg: CIConfig, version: Optional[str]) -> List[Item]:
|
|
47
|
+
# Without a version, setup-ruby reads .ruby-version / .tool-versions.
|
|
48
|
+
with_: Dict[str, Any] = {"ruby-version": version} if version else {}
|
|
49
|
+
# bundler-cache runs `bundle install` and caches the gems.
|
|
50
|
+
with_["bundler-cache"] = cfg.cache
|
|
51
|
+
if cfg.directory != ".":
|
|
52
|
+
with_["working-directory"] = cfg.directory
|
|
53
|
+
return [step("Set up Ruby", uses=ACTIONS["setup-ruby"], with_=with_)]
|
|
54
|
+
|
|
55
|
+
def image(self, cfg: CIConfig, version: str) -> str:
|
|
56
|
+
return f"ruby:{version}"
|
|
57
|
+
|
|
58
|
+
def image_setup(self, cfg: CIConfig) -> List[Step]:
|
|
59
|
+
# On GitHub, setup-ruby installs the gems when caching (see install).
|
|
60
|
+
return [step("Install dependencies", run=cfg.install)] if cfg.cache else []
|
|
61
|
+
|
|
62
|
+
def cache(self, cfg: CIConfig) -> Optional[Cache]:
|
|
63
|
+
if not cfg.cache:
|
|
64
|
+
return None
|
|
65
|
+
env = {"BUNDLE_PATH": f"{ROOT}/vendor/bundle"}
|
|
66
|
+
return Cache("gems", ("vendor/bundle",), key_files=("Gemfile.lock",), env=env)
|
|
67
|
+
|
|
68
|
+
def install(self, cfg: CIConfig, packages: Sequence[str] = ()) -> List[Item]:
|
|
69
|
+
return [] if cfg.cache else [step("Install dependencies", run=cfg.install)]
|
|
70
|
+
|
|
71
|
+
def lint(self, cfg: CIConfig, tools: List[str]) -> List[Item]:
|
|
72
|
+
github = on_github(cfg, " --format github")
|
|
73
|
+
return [*self.install(cfg), *(step(_LINT[t][0], run=_LINT[t][1] + github) for t in tools)]
|
|
74
|
+
|
|
75
|
+
def test(self, cfg: CIConfig) -> List[Item]:
|
|
76
|
+
return test_steps(cfg, _TEST[cfg.test.runner])
|
|
77
|
+
|
|
78
|
+
def coverage_file(self, cfg: CIConfig) -> str:
|
|
79
|
+
return "coverage/.resultset.json"
|
|
80
|
+
|
|
81
|
+
def reports(self, cfg: CIConfig) -> TestReports:
|
|
82
|
+
return TestReports(
|
|
83
|
+
junit="junit.xml" if cfg.test.runner in _RSPEC_RUNNERS else "",
|
|
84
|
+
coverage_regex=THRESHOLD_REGEX if cfg.test.coverage else "",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def audit(self, cfg: CIConfig) -> List[Item]:
|
|
88
|
+
return [
|
|
89
|
+
step("Install bundler-audit", run="gem install bundler-audit --no-document"),
|
|
90
|
+
step("Dependency vulnerability scan", run="bundle-audit check --update"),
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
def build(self, cfg: CIConfig) -> List[Item]:
|
|
94
|
+
return [*self.install(cfg), step("Build", run=cfg.build.command)]
|
|
95
|
+
|
|
96
|
+
def dependabot_ecosystem(self, cfg: CIConfig) -> str:
|
|
97
|
+
return "bundler"
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_steps(cfg: CIConfig, command: str) -> List[Step]:
|
|
101
|
+
"""Install, run `command`, then enforce the SimpleCov threshold when coverage is enabled."""
|
|
102
|
+
t = cfg.test
|
|
103
|
+
steps = list(RubyCI().install(cfg))
|
|
104
|
+
if t.reports and t.runner in _RSPEC_RUNNERS:
|
|
105
|
+
steps.append(step("JUnit formatter for RSpec", run=_RSPEC_JUNIT_INSTALL))
|
|
106
|
+
command += _RSPEC_JUNIT_FLAGS
|
|
107
|
+
steps.append(step("Tests", run=command, secrets=t.env_secrets))
|
|
108
|
+
if t.coverage:
|
|
109
|
+
steps.append(step("Coverage threshold", run=_SIMPLECOV_CHECK.format(threshold=t.coverage_threshold)))
|
|
110
|
+
return steps
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from quoll.languages.base import Detection
|
|
6
|
+
from quoll.project import Project
|
|
7
|
+
from quoll.services import detect_services
|
|
8
|
+
|
|
9
|
+
RUBY_DEFAULT = "3.4"
|
|
10
|
+
RUBY_SUPPORTED = ("3.2", "3.3", "3.4")
|
|
11
|
+
|
|
12
|
+
# Gems revealing a backing service.
|
|
13
|
+
_SERVICE_GEMS = {
|
|
14
|
+
"postgres": ("pg",),
|
|
15
|
+
"mysql": ("mysql2", "trilogy"),
|
|
16
|
+
"redis": ("redis", "redis-client"),
|
|
17
|
+
"mongodb": ("mongoid", "mongo"),
|
|
18
|
+
}
|
|
19
|
+
# (file, pattern capturing major.minor), by priority.
|
|
20
|
+
_VERSION_SOURCES = (
|
|
21
|
+
(".ruby-version", r"(\d+\.\d+)"),
|
|
22
|
+
(".tool-versions", r"^ruby\s+(\d+\.\d+)"),
|
|
23
|
+
("Gemfile", r"^\s*ruby\s+[\"'](\d+\.\d+)"),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def detect(project: Project) -> Detection:
|
|
28
|
+
det = Detection(package_manager="bundler", install="bundle install")
|
|
29
|
+
det.lockfile = "Gemfile.lock" if project.exists("Gemfile.lock") else ""
|
|
30
|
+
if not det.lockfile:
|
|
31
|
+
det.warnings.append("No Gemfile.lock found — commit it for reproducible builds.")
|
|
32
|
+
|
|
33
|
+
# setup-ruby reads .ruby-version and .tool-versions itself.
|
|
34
|
+
for name, pattern in _VERSION_SOURCES:
|
|
35
|
+
m = re.search(pattern, project.read_text(name), re.M)
|
|
36
|
+
if m:
|
|
37
|
+
det.version_file = name if name != "Gemfile" else ""
|
|
38
|
+
det.version = m.group(1)
|
|
39
|
+
break
|
|
40
|
+
else:
|
|
41
|
+
det.version = RUBY_DEFAULT
|
|
42
|
+
det.matrix_versions = [v for v in RUBY_SUPPORTED if _key(v) >= _key(det.version)] or [det.version]
|
|
43
|
+
|
|
44
|
+
det.lint_tools = [tool for tool in ("rubocop", "standard") if has_gem(project, tool)]
|
|
45
|
+
if has_gem(project, "rspec-core") or has_gem(project, "rspec-rails") or project.exists(".rspec"):
|
|
46
|
+
det.test_runner = "rspec"
|
|
47
|
+
elif project.is_dir("test"):
|
|
48
|
+
det.test_runner = "minitest"
|
|
49
|
+
else:
|
|
50
|
+
det.warnings.append("No tests found (spec/ with RSpec or test/) — the test job is disabled.")
|
|
51
|
+
# The threshold is read from SimpleCov's results; without SimpleCov there is nothing to check.
|
|
52
|
+
det.coverage = has_gem(project, "simplecov")
|
|
53
|
+
|
|
54
|
+
det.services = detect_services(
|
|
55
|
+
[gem for gems in _SERVICE_GEMS.values() for gem in gems if has_gem(project, gem)], _SERVICE_GEMS
|
|
56
|
+
)
|
|
57
|
+
if project.glob_any("*.gemspec"):
|
|
58
|
+
det.build_command = "gem build ./*.gemspec"
|
|
59
|
+
return det
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def has_gem(project: Project, name: str) -> bool:
|
|
63
|
+
"""True when `name` is declared in the Gemfile or resolved in Gemfile.lock."""
|
|
64
|
+
gem = re.escape(name)
|
|
65
|
+
return bool(
|
|
66
|
+
re.search(rf"^\s*gem\s+[\"']{gem}[\"']", project.read_text("Gemfile"), re.M)
|
|
67
|
+
or re.search(rf"^\s{{4}}{gem} \(", project.read_text("Gemfile.lock"), re.M)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _key(version: str) -> tuple:
|
|
72
|
+
return tuple(int(p) for p in version.split(".")[:2])
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
|
|
5
|
+
|
|
6
|
+
from quoll.languages.base import Detection, DockerDefaults, DockerImage
|
|
7
|
+
from quoll.languages.ruby.detect import has_gem
|
|
8
|
+
from quoll.project import Project
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from quoll.docker.config import DockerConfig
|
|
12
|
+
|
|
13
|
+
# gem: (build packages, runtime packages) on Debian.
|
|
14
|
+
_NATIVE_GEMS = {
|
|
15
|
+
"pg": ("libpq-dev", "libpq5"),
|
|
16
|
+
"mysql2": ("default-libmysqlclient-dev", "libmariadb3"),
|
|
17
|
+
"ruby-vips": ("", "libvips42t64"),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RubyImage(DockerImage):
|
|
22
|
+
def writable_paths(self, cfg: DockerConfig) -> Optional[List[str]]:
|
|
23
|
+
# Ruby refuses a temporary directory anyone can write to without the sticky bit — what Kubernetes' emptyDir
|
|
24
|
+
# volumes are: the root filesystem stays writable.
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
def defaults(self, project: Project, det: Detection) -> DockerDefaults:
|
|
28
|
+
m = re.search(r"^web:\s*(.+)$", project.read_text("Procfile"), re.M)
|
|
29
|
+
if m:
|
|
30
|
+
return DockerDefaults(port=3000, command=m.group(1).strip())
|
|
31
|
+
if project.exists("config.ru"):
|
|
32
|
+
return DockerDefaults(port=9292, command="bundle exec rackup --host 0.0.0.0 --port 9292")
|
|
33
|
+
return DockerDefaults(
|
|
34
|
+
port=3000, warnings=["Couldn't infer how to start the app (Procfile or config.ru) — set docker.command."]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def context(self, project: Project, cfg: DockerConfig) -> Dict[str, Any]:
|
|
38
|
+
build, runtime = native_packages(project)
|
|
39
|
+
lockfile = project.exists("Gemfile.lock")
|
|
40
|
+
env = {"BUNDLE_DEPLOYMENT": "1"} if lockfile else {}
|
|
41
|
+
return {
|
|
42
|
+
"workdir": "/app",
|
|
43
|
+
"env": {**env, "BUNDLE_PATH": "/usr/local/bundle", "BUNDLE_WITHOUT": "development:test"},
|
|
44
|
+
"lockfile": lockfile,
|
|
45
|
+
"gemspec": bool(re.search(r"^\s*gemspec", project.read_text("Gemfile"), re.M)),
|
|
46
|
+
"ruby_version_file": project.exists(".ruby-version"),
|
|
47
|
+
"build_packages": build,
|
|
48
|
+
"runtime_packages": runtime,
|
|
49
|
+
"bundle_install": ["bundle install", 'rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache'],
|
|
50
|
+
"after_copy": [],
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def dockerignore(self, cfg: DockerConfig) -> List[str]:
|
|
54
|
+
return [".bundle", "vendor/bundle", "log", "tmp", "coverage", ".env", ".env.*", "!.env.example"]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def native_packages(project: Project) -> Tuple[List[str], List[str]]:
|
|
58
|
+
build, runtime = [], []
|
|
59
|
+
for gem, (dev, lib) in _NATIVE_GEMS.items():
|
|
60
|
+
if has_gem(project, gem):
|
|
61
|
+
build += [dev] if dev else []
|
|
62
|
+
runtime += [lib] if lib else []
|
|
63
|
+
return build, runtime
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Ruby frameworks."""
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{% extends "ruby/Dockerfile.j2" %}
|
|
2
|
+
|
|
3
|
+
{% block user %}
|
|
4
|
+
COPY --from=build /usr/local/bundle /usr/local/bundle
|
|
5
|
+
COPY --from=build /rails /rails
|
|
6
|
+
# The code stays root-owned: the app user only owns what Rails writes to.
|
|
7
|
+
RUN groupadd --system --gid 1000 rails \
|
|
8
|
+
&& useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash \
|
|
9
|
+
&& mkdir -p db log storage tmp \
|
|
10
|
+
&& chown -R rails:rails db log storage tmp
|
|
11
|
+
USER 1000:1000
|
|
12
|
+
{% if entrypoint %}
|
|
13
|
+
# Generated by Rails: prepares the database before `rails server`.
|
|
14
|
+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
|
|
15
|
+
{% endif %}
|
|
16
|
+
{% endblock %}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Ruby on Rails: tests need the test database prepared; Brakeman scans the app for vulnerabilities."""
|
|
2
|
+
|
|
3
|
+
from quoll.languages.base import Framework
|
|
4
|
+
from quoll.languages.ruby.frameworks.rails.ci import RailsCI
|
|
5
|
+
from quoll.languages.ruby.frameworks.rails.detect import detect
|
|
6
|
+
from quoll.languages.ruby.frameworks.rails.docker import RailsImage
|
|
7
|
+
from quoll.languages.ruby.frameworks.rails.services import service_env
|
|
8
|
+
|
|
9
|
+
framework = Framework(
|
|
10
|
+
name="rails",
|
|
11
|
+
language="ruby",
|
|
12
|
+
detect=detect,
|
|
13
|
+
ci=RailsCI(),
|
|
14
|
+
lint_tools=("brakeman",),
|
|
15
|
+
test_runners=("rails", "rails-rspec"),
|
|
16
|
+
docker=RailsImage(),
|
|
17
|
+
service_env=service_env,
|
|
18
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, List
|
|
4
|
+
|
|
5
|
+
from quoll.ci.steps import Item, step
|
|
6
|
+
from quoll.languages.base import FrameworkCI
|
|
7
|
+
from quoll.languages.ruby.ci import test_steps
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from quoll.ci.config import CIConfig
|
|
11
|
+
|
|
12
|
+
_TEST = {
|
|
13
|
+
"rails": "bin/rails db:test:prepare test",
|
|
14
|
+
"rails-rspec": "bin/rails db:test:prepare\nbundle exec rspec",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class RailsCI(FrameworkCI):
|
|
19
|
+
def env(self, cfg: CIConfig) -> dict:
|
|
20
|
+
return {"RAILS_ENV": "test"}
|
|
21
|
+
|
|
22
|
+
def lint(self, cfg: CIConfig, tool: str) -> List[Item]:
|
|
23
|
+
return [step("Brakeman", run="bundle exec brakeman --no-pager")]
|
|
24
|
+
|
|
25
|
+
def test(self, cfg: CIConfig) -> List[Item]:
|
|
26
|
+
return test_steps(cfg, _TEST[cfg.test.runner])
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from quoll.languages.base import Detection
|
|
4
|
+
from quoll.languages.ruby.detect import has_gem
|
|
5
|
+
from quoll.project import Project
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def detect(project: Project, det: Detection) -> bool:
|
|
9
|
+
if not has_gem(project, "rails") or not project.exists("bin/rails"):
|
|
10
|
+
return False
|
|
11
|
+
if has_gem(project, "brakeman"):
|
|
12
|
+
det.lint_tools.append("brakeman")
|
|
13
|
+
if det.test_runner:
|
|
14
|
+
det.test_runner = "rails-rspec" if det.test_runner == "rspec" else "rails"
|
|
15
|
+
return True
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, List
|
|
4
|
+
|
|
5
|
+
from quoll.languages.base import Detection, DockerDefaults
|
|
6
|
+
from quoll.languages.ruby.detect import has_gem
|
|
7
|
+
from quoll.languages.ruby.docker import RubyImage
|
|
8
|
+
from quoll.project import Project
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from quoll.docker.config import DockerConfig
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class RailsImage(RubyImage):
|
|
15
|
+
def defaults(self, project: Project, det: Detection) -> DockerDefaults:
|
|
16
|
+
warnings = []
|
|
17
|
+
if project.exists("package.json") and not has_gem(project, "importmap-rails"):
|
|
18
|
+
warnings.append("Assets built with Node (jsbundling/cssbundling) are not built by this image yet.")
|
|
19
|
+
return DockerDefaults(port=3000, command="./bin/rails server -b 0.0.0.0 -p 3000", warnings=warnings)
|
|
20
|
+
|
|
21
|
+
def context(self, project: Project, cfg: DockerConfig) -> Dict[str, Any]:
|
|
22
|
+
context = super().context(project, cfg)
|
|
23
|
+
bootsnap = has_gem(project, "bootsnap")
|
|
24
|
+
bundle_install = [
|
|
25
|
+
"bundle install",
|
|
26
|
+
'rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git',
|
|
27
|
+
]
|
|
28
|
+
after_copy = []
|
|
29
|
+
if bootsnap:
|
|
30
|
+
bundle_install.append("bundle exec bootsnap precompile --gemfile")
|
|
31
|
+
after_copy.append("bundle exec bootsnap precompile app/ lib/")
|
|
32
|
+
if has_gem(project, "propshaft") or has_gem(project, "sprockets-rails"):
|
|
33
|
+
# The production secret isn't needed to compile assets.
|
|
34
|
+
after_copy.append("SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile")
|
|
35
|
+
return {
|
|
36
|
+
**context,
|
|
37
|
+
"workdir": "/rails",
|
|
38
|
+
"env": {"RAILS_ENV": "production", "BUNDLE_DEPLOYMENT": "1", **context["env"]},
|
|
39
|
+
"bundle_install": bundle_install,
|
|
40
|
+
"after_copy": after_copy,
|
|
41
|
+
# Generated by Rails 7.1+.
|
|
42
|
+
"entrypoint": project.exists("bin/docker-entrypoint"),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def dockerignore(self, cfg: DockerConfig) -> List[str]:
|
|
46
|
+
return [
|
|
47
|
+
"log/*",
|
|
48
|
+
"!log/.keep",
|
|
49
|
+
"tmp/*",
|
|
50
|
+
"!tmp/.keep",
|
|
51
|
+
"storage/*",
|
|
52
|
+
"!storage/.keep",
|
|
53
|
+
"node_modules",
|
|
54
|
+
"public/assets",
|
|
55
|
+
"app/assets/builds/*",
|
|
56
|
+
"!app/assets/builds/.keep",
|
|
57
|
+
"config/master.key",
|
|
58
|
+
"config/credentials/*.key",
|
|
59
|
+
".env",
|
|
60
|
+
".env.*",
|
|
61
|
+
"!.env.example",
|
|
62
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def service_env(service: str, host: str, database: str) -> Dict[str, str]:
|
|
7
|
+
"""Rails picks its adapter from the DATABASE_URL scheme: mysql2:// for MySQL."""
|
|
8
|
+
if service == "mysql":
|
|
9
|
+
return {"DATABASE_URL": f"mysql2://root:root@{host}:3306/{database}"}
|
|
10
|
+
return {}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{% block build %}
|
|
2
|
+
FROM rust:{{ rust_tag }}-slim AS build
|
|
3
|
+
{% if openssl %}
|
|
4
|
+
RUN apt-get update && apt-get install --no-install-recommends -y pkg-config libssl-dev \
|
|
5
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
6
|
+
{% endif %}
|
|
7
|
+
WORKDIR /src
|
|
8
|
+
COPY . .
|
|
9
|
+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
|
|
10
|
+
--mount=type=cache,target=/src/target \
|
|
11
|
+
{{ cfg.build_command }} \
|
|
12
|
+
&& cp target/release/{{ binary }} /app
|
|
13
|
+
{% endblock %}
|
|
14
|
+
|
|
15
|
+
{% block runtime %}
|
|
16
|
+
# glibc and OpenSSL on distroless: no shell, no package manager, non-root.
|
|
17
|
+
FROM gcr.io/distroless/cc-debian13:nonroot
|
|
18
|
+
COPY --from=build /app /app
|
|
19
|
+
# distroless' nonroot, numeric: Kubernetes can then check it isn't root (runAsNonRoot).
|
|
20
|
+
USER 65532:65532
|
|
21
|
+
EXPOSE {{ cfg.port }}
|
|
22
|
+
CMD {{ cfg.command | exec_form }}
|
|
23
|
+
{% endblock %}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Rust: cargo projects and workspaces."""
|
|
2
|
+
|
|
3
|
+
from quoll.languages.base import Language
|
|
4
|
+
from quoll.languages.rust.ci import RustCI
|
|
5
|
+
from quoll.languages.rust.detect import detect
|
|
6
|
+
from quoll.languages.rust.docker import RustImage
|
|
7
|
+
|
|
8
|
+
language = Language(
|
|
9
|
+
name="rust",
|
|
10
|
+
markers=("Cargo.toml",),
|
|
11
|
+
package_managers=("cargo",),
|
|
12
|
+
lint_tools=("rustfmt", "clippy"),
|
|
13
|
+
test_runners=("cargo", "nextest"),
|
|
14
|
+
detect=detect,
|
|
15
|
+
ci=RustCI(),
|
|
16
|
+
docker=RustImage(),
|
|
17
|
+
)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence
|
|
4
|
+
|
|
5
|
+
from quoll.ci.steps import ROOT, Cache, Item, Step, step
|
|
6
|
+
from quoll.languages.base import CISteps, TestReports
|
|
7
|
+
from quoll.platforms.github.actions import ACTIONS
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from quoll.ci.config import CIConfig
|
|
11
|
+
|
|
12
|
+
_LINT = {
|
|
13
|
+
"rustfmt": ("rustfmt", "cargo fmt --all --check"),
|
|
14
|
+
"clippy": ("Clippy", "cargo clippy --workspace --all-targets --all-features -- -D warnings"),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_BINSTALL = (
|
|
18
|
+
"curl -sSfL https://github.com/cargo-bins/cargo-binstall/releases/latest/download/"
|
|
19
|
+
'cargo-binstall-"$(uname -m)"-unknown-linux-musl.tgz | tar -xz -C /usr/local/bin'
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# nextest writes JUnit results with a profile setting: added by a tool config, so the project's own config applies.
|
|
23
|
+
_NEXTEST_CONFIG = "/tmp/quoll-nextest.toml"
|
|
24
|
+
_NEXTEST_JUNIT = f"""printf '[profile.default.junit]\\npath = "junit.xml"\\n' > {_NEXTEST_CONFIG}"""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RustCI(CISteps):
|
|
28
|
+
version_key = "rust-version"
|
|
29
|
+
codeql_language = "rust"
|
|
30
|
+
# cargo-audit is a standalone binary; cargo is preinstalled on the runners.
|
|
31
|
+
audit_needs_setup = False
|
|
32
|
+
|
|
33
|
+
def setup(self, cfg: CIConfig, version: Optional[str]) -> List[Item]:
|
|
34
|
+
components = _components(cfg)
|
|
35
|
+
# Without a toolchain, the action reads rust-toolchain(.toml).
|
|
36
|
+
with_: Dict[str, Any] = {"toolchain": version} if version else {}
|
|
37
|
+
with_["components"] = ", ".join(components)
|
|
38
|
+
if not cfg.cache:
|
|
39
|
+
with_["cache"] = False
|
|
40
|
+
if cfg.directory != ".":
|
|
41
|
+
# Where rust-toolchain(.toml) and Cargo.lock are.
|
|
42
|
+
with_["rust-src-dir"] = cfg.directory
|
|
43
|
+
with_["cache-workspaces"] = cfg.directory
|
|
44
|
+
return [step("Set up Rust", uses=ACTIONS["setup-rust"], with_=with_)]
|
|
45
|
+
|
|
46
|
+
def image(self, cfg: CIConfig, version: str) -> str:
|
|
47
|
+
if version.startswith("nightly"):
|
|
48
|
+
return "rustlang/rust:nightly"
|
|
49
|
+
# The "1" tag follows the latest stable release.
|
|
50
|
+
return f"rust:{'1' if version in ('stable', 'beta') else version}"
|
|
51
|
+
|
|
52
|
+
def image_setup(self, cfg: CIConfig) -> List[Step]:
|
|
53
|
+
return [step("Add components", run=f"rustup component add {' '.join(_components(cfg))}")]
|
|
54
|
+
|
|
55
|
+
def cache(self, cfg: CIConfig) -> Optional[Cache]:
|
|
56
|
+
if not cfg.cache:
|
|
57
|
+
return None
|
|
58
|
+
paths = (".cargo/registry", ".cargo/git", "target")
|
|
59
|
+
return Cache("cargo", paths, key_files=("Cargo.lock",), env={"CARGO_HOME": f"{ROOT}/.cargo"})
|
|
60
|
+
|
|
61
|
+
def install(self, cfg: CIConfig, packages: Sequence[str] = ()) -> List[Step]:
|
|
62
|
+
steps = [step("Fetch dependencies", run=cfg.install)]
|
|
63
|
+
if packages:
|
|
64
|
+
steps.append(install_tools(packages))
|
|
65
|
+
return steps
|
|
66
|
+
|
|
67
|
+
def lint(self, cfg: CIConfig, tools: List[str]) -> List[Item]:
|
|
68
|
+
return [*self.install(cfg), *(step(_LINT[t][0], run=_LINT[t][1]) for t in tools)]
|
|
69
|
+
|
|
70
|
+
def test(self, cfg: CIConfig) -> List[Item]:
|
|
71
|
+
t = cfg.test
|
|
72
|
+
nextest = t.runner == "nextest"
|
|
73
|
+
tools = (["cargo-llvm-cov"] if t.coverage else []) + (["cargo-nextest"] if nextest else [])
|
|
74
|
+
if nextest:
|
|
75
|
+
cmd = "cargo llvm-cov nextest" if t.coverage else "cargo nextest run"
|
|
76
|
+
else:
|
|
77
|
+
cmd = "cargo llvm-cov" if t.coverage else "cargo test"
|
|
78
|
+
cmd += " --workspace --all-features"
|
|
79
|
+
setup: List[Item] = []
|
|
80
|
+
if nextest and t.reports:
|
|
81
|
+
setup.append(step("JUnit output for nextest", run=_NEXTEST_JUNIT))
|
|
82
|
+
cmd += f" --tool-config-file quoll:{_NEXTEST_CONFIG}"
|
|
83
|
+
if t.coverage:
|
|
84
|
+
cmd += f" --lcov --output-path lcov.info --fail-under-lines {t.coverage_threshold}"
|
|
85
|
+
name = "Tests" + (" with coverage" if t.coverage else "")
|
|
86
|
+
return [*self.install(cfg, tools), *setup, step(name, run=cmd, secrets=t.env_secrets)]
|
|
87
|
+
|
|
88
|
+
def coverage_file(self, cfg: CIConfig) -> str:
|
|
89
|
+
return "lcov.info"
|
|
90
|
+
|
|
91
|
+
def reports(self, cfg: CIConfig) -> TestReports:
|
|
92
|
+
# The lines column of cargo-llvm-cov's TOTAL row.
|
|
93
|
+
regex = r"/^TOTAL(?:\s+\S+){8}\s+(\d+(?:\.\d+)?)%/"
|
|
94
|
+
# `cargo test` has no stable JUnit output: nextest only.
|
|
95
|
+
junit = "target/nextest/default/junit.xml" if cfg.test.runner == "nextest" else ""
|
|
96
|
+
return TestReports(junit=junit, coverage_regex=regex if cfg.test.coverage else "")
|
|
97
|
+
|
|
98
|
+
def audit(self, cfg: CIConfig) -> List[Item]:
|
|
99
|
+
return [
|
|
100
|
+
install_tools(["cargo-audit"], "Install cargo-audit"),
|
|
101
|
+
step("Dependency vulnerability scan", run="cargo audit"),
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
def build(self, cfg: CIConfig) -> List[Item]:
|
|
105
|
+
return [*self.install(cfg), step("Build", run=cfg.build.command)]
|
|
106
|
+
|
|
107
|
+
def dependabot_ecosystem(self, cfg: CIConfig) -> str:
|
|
108
|
+
return "cargo"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def install_tools(tools: Sequence[str], name: str = "Install CI tools") -> Step:
|
|
112
|
+
"""Prebuilt binaries of cargo tools: taiki-e/install-action on GitHub, cargo-binstall elsewhere."""
|
|
113
|
+
return step(
|
|
114
|
+
name,
|
|
115
|
+
run=f"{_BINSTALL}\ncargo binstall --no-confirm --install-path /usr/local/bin {' '.join(tools)}",
|
|
116
|
+
uses=ACTIONS["install-tool"],
|
|
117
|
+
with_={"tool": ",".join(tools)},
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _components(cfg: CIConfig) -> List[str]:
|
|
122
|
+
components = ["rustfmt", "clippy"]
|
|
123
|
+
if cfg.test.enabled and cfg.test.coverage:
|
|
124
|
+
components.append("llvm-tools-preview")
|
|
125
|
+
return components
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from quoll.languages.base import Detection
|
|
6
|
+
from quoll.project import Project
|
|
7
|
+
from quoll.services import detect_services
|
|
8
|
+
|
|
9
|
+
# Crates (or sqlx/diesel/sea-orm features) revealing a backing service.
|
|
10
|
+
_SERVICE_CRATES = {
|
|
11
|
+
"postgres": ("tokio-postgres", "postgres", "deadpool-postgres"),
|
|
12
|
+
"mysql": ("mysql", "mysql_async"),
|
|
13
|
+
"redis": ("redis", "deadpool-redis", "fred"),
|
|
14
|
+
"mongodb": ("mongodb",),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def detect(project: Project) -> Detection:
|
|
19
|
+
det = Detection(package_manager="cargo", lint_tools=["rustfmt", "clippy"])
|
|
20
|
+
locked = project.exists("Cargo.lock")
|
|
21
|
+
det.lockfile = "Cargo.lock" if locked else ""
|
|
22
|
+
det.install = "cargo fetch --locked" if locked else "cargo fetch"
|
|
23
|
+
if not locked:
|
|
24
|
+
det.warnings.append("No Cargo.lock found — commit it for reproducible builds (recommended for binaries).")
|
|
25
|
+
|
|
26
|
+
# rust-toolchain(.toml) is read by the setup action itself.
|
|
27
|
+
toolchain_file = next((f for f in ("rust-toolchain.toml", "rust-toolchain") if project.exists(f)), "")
|
|
28
|
+
if toolchain_file:
|
|
29
|
+
det.version_file = toolchain_file
|
|
30
|
+
m = re.search(r'channel\s*=\s*"([^"]+)"', project.read_text(toolchain_file))
|
|
31
|
+
det.version = m.group(1) if m else project.read_text(toolchain_file).strip() or "stable"
|
|
32
|
+
else:
|
|
33
|
+
det.version = "stable"
|
|
34
|
+
cargo = project.read_toml("Cargo.toml")
|
|
35
|
+
msrv = cargo.get("package", {}).get("rust-version", "")
|
|
36
|
+
det.matrix_versions = [msrv, "stable"] if isinstance(msrv, str) and msrv else ["stable", "beta"]
|
|
37
|
+
|
|
38
|
+
crates = [*cargo.get("dependencies", {}), *cargo.get("dev-dependencies", {})]
|
|
39
|
+
cargo_text = project.read_text("Cargo.toml")
|
|
40
|
+
if any(orm in crates for orm in ("sqlx", "diesel", "sea-orm")):
|
|
41
|
+
crates += [db for db in ("postgres", "mysql") if re.search(rf"\b{db}\b", cargo_text)]
|
|
42
|
+
det.services = detect_services(crates, _SERVICE_CRATES)
|
|
43
|
+
|
|
44
|
+
det.test_runner = "nextest" if project.exists(".config/nextest.toml") else "cargo"
|
|
45
|
+
det.build_command = "cargo build --release --locked" if locked else "cargo build --release"
|
|
46
|
+
return det
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, List
|
|
4
|
+
|
|
5
|
+
from quoll.languages.base import Detection, DockerDefaults, DockerImage
|
|
6
|
+
from quoll.project import Project
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from quoll.docker.config import DockerConfig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RustImage(DockerImage):
|
|
13
|
+
def defaults(self, project: Project, det: Detection) -> DockerDefaults:
|
|
14
|
+
build = "cargo build --release --locked" if project.exists("Cargo.lock") else "cargo build --release"
|
|
15
|
+
warnings = [] if binary_name(project) else ["No binary target in Cargo.toml — check docker.build_command."]
|
|
16
|
+
return DockerDefaults(port=8080, command="/app", build_command=build, warnings=warnings)
|
|
17
|
+
|
|
18
|
+
def context(self, project: Project, cfg: DockerConfig) -> Dict[str, Any]:
|
|
19
|
+
tag = "1" if cfg.version in ("stable", "") else cfg.version
|
|
20
|
+
return {
|
|
21
|
+
"rust_tag": tag,
|
|
22
|
+
"binary": binary_name(project) or project.name,
|
|
23
|
+
# openssl-sys links against the system OpenSSL.
|
|
24
|
+
"openssl": "openssl-sys" in project.read_text("Cargo.lock"),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def dockerignore(self, cfg: DockerConfig) -> List[str]:
|
|
28
|
+
return ["target", ".env", ".env.*", "!.env.example"]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def binary_name(project: Project) -> str:
|
|
32
|
+
cargo = project.read_toml("Cargo.toml")
|
|
33
|
+
bins = cargo.get("bin", [])
|
|
34
|
+
if bins and isinstance(bins, list) and bins[0].get("name"):
|
|
35
|
+
return bins[0]["name"]
|
|
36
|
+
if project.exists("src/main.rs"):
|
|
37
|
+
return cargo.get("package", {}).get("name", "")
|
|
38
|
+
return ""
|