Repository navigation
Expand default_env values in the systemd service - #12
Merged
Merged
Conversation
capistrano-rbenv ajoute RBENV_ROOT="$HOME/.rbenv" à default_env. Dans les commandes Capistrano, SSHKit exporte chaque valeur entre guillemets doubles, donc le shell du serveur remplace $HOME. Le template écrivait la valeur telle quelle : l'unité contenait RBENV_ROOT=$HOME/.rbenv, alors que son ExecStart (rbenv exec bundle) passe par le shell et contient le chemin absolu. Issue #1 : remplacer ExecStart par le shim bundle, qui exporte lui-même RBENV_ROOT, faisait démarrer le service. Chaque valeur passe maintenant par `printf %s "<valeur>"` sur le serveur, avec les guillemets doubles échappés comme le fait SSHKit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
capistrano-asdf ajoute à default_env RUBY_CONFIGURE_OPTS, dont la valeur commence par « --with-jemalloc » ou « --enable-yjit ». Depuis le commit précédent, la valeur passe par printf sur le serveur : le test vérifie, sur le printf de la CI (Linux), qu'elle arrive intacte dans l'unité. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #10 (reuses
run_capfromtest/test_helper.rb). Merge after #10.Problem
Issue #1: with rbenv, the service only starts after replacing
ExecStart=/home/ubuntu/.rbenv/bin/rbenv exec bundle …by hand withExecStart=/home/ubuntu/.rbenv/shims/bundle ….capistrano-rbenv 2.2.0 (
rbenv:map_bins, run after the stage is loaded):bundlewith$HOME/.rbenv/bin/rbenv exec;rbenv_root: "$HOME/.rbenv"andrbenv_versiontoSSHKit.config.default_env, the same hash asfetch(:default_env).In Capistrano commands, SSHKit exports each value inside double quotes (
sshkit/command.rb:153-158), so the server shell replaces$HOME. The template, however, wrote the value as is. The generated unit contained:ExecStartalready goes throughechoon the server, so its$HOMEis replaced; the one inRBENV_ROOTisn't. Thebundleshim exportsRBENV_ROOTitself with an absolute path, hence the workaround in the issue.Changes
Each
default_envvalue is printed by the server shell (printf %s "<value>", double quotes escaped as in SSHKit) before being written into the unit. It therefore has the same value there as in Capistrano commands. An installed service isn't regenerated on deploy:cap <stage> solid_queue:installhas to be run again (noted in the CHANGELOG).Tests
test_default_env_is_expanded_by_the_server_shell:set :default_env, { rbenv_root: "$HOME/.rbenv", rbenv_version: "3.3.0" }→ the unit containsRBENV_ROOT=<home>/.rbenv. Fails without the fix.test_default_env_keeps_double_quotes: asay "hi"value stayssay "hi".test_default_env_keeps_values_starting_with_dashes:RUBY_CONFIGURE_OPTS=--with-jemalloc=… --enable-yjit(added by capistrano-asdf) comes through intact, with theprintfof the CI (Linux).value.to_sback makes the first test fail; removing the double-quote escaping makes the second one fail.rbenv:map_binsreproduced in a Capfile (after stagehook): the unit now containsEnvironment='RBENV_ROOT=/Users/brice/.rbenv'.origin/mainof codeur/capistrano-asdf) loaded in the Capfile: same unit before and after the fix (PATHstill excluded,RUBY_CONFIGURE_OPTSunchanged,ExecStart=<home>/.asdf/bin/asdf exec bundle …).$HOMEinEnvironment=comes from its documentation (systemd.exec) and from the workaround described in the issue.bundle exec rake(tests + standard): green locally (Ruby 4.0.6).🤖 Generated with Claude Code