mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-14 03:43:42 +00:00
fix: honor configured Docker registration file (#1259)
The Docker entrypoint always checked `.runner` in `/data` and ignored `runner.file` from `CONFIG_FILE`. When `runner.file` pointed elsewhere, it re-registered on every start, or skipped registration because of a stale `.runner`. It now reads the path from a new `config runner-file` subcommand, which resolves `runner.file` the same way as `register` and `daemon`. Closes https://gitea.com/gitea/runner/issues/585 --------- Co-authored-by: silverwind <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1259 Reviewed-by: silverwind <[email protected]>
This commit is contained in:
1 parent
5a38a3d0c4
commit
bf03f36d5a
3 files changed
+25
-2
No files matched your search
@@ -27,6 +27,19 @@ func loadConfigCmd(configFile *string) *cobra.Command {
|
|||||||
|
|
||||||
configCmd.AddCommand(loadGenerateConfigCmd("generate"))
|
configCmd.AddCommand(loadGenerateConfigCmd("generate"))
|
||||||
configCmd.AddCommand(loadInitConfigCmd(configFile))
|
configCmd.AddCommand(loadInitConfigCmd(configFile))
|
||||||
|
configCmd.AddCommand(&cobra.Command{
|
||||||
|
Use: "runner-file",
|
||||||
|
Short: "Print the registration file path used by the runner",
|
||||||
|
Args: cobra.NoArgs,
|
||||||
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
|
cfg, err := config.LoadDefault(*configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Fprintln(cmd.OutOrStdout(), cfg.Runner.File)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
configCmd.AddCommand(&cobra.Command{
|
configCmd.AddCommand(&cobra.Command{
|
||||||
Use: "get <key>",
|
Use: "get <key>",
|
||||||
|
|||||||
@@ -97,3 +97,14 @@ func TestConfigCmdResolvesTheConfigFile(t *testing.T) {
|
|||||||
assert.Contains(t, err.Error(), "--config")
|
assert.Contains(t, err.Error(), "--config")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigCmdRunnerFileUsesConfiguredPathOrDefault(t *testing.T) {
|
||||||
|
out, _, err := runConfigCmd(t, "", "runner-file")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, ".runner\n", out)
|
||||||
|
file := filepath.Join(t.TempDir(), "config.yaml")
|
||||||
|
require.NoError(t, os.WriteFile(file, []byte("runner:\n file: 'state dir/registration.json'\n"), 0o600))
|
||||||
|
out, _, err = runConfigCmd(t, file, "runner-file")
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, "state dir/registration.json\n", out)
|
||||||
|
}
|
||||||
+1
-2
@@ -6,12 +6,11 @@ fi
|
|||||||
|
|
||||||
cd /data
|
cd /data
|
||||||
|
|
||||||
RUNNER_STATE_FILE=${RUNNER_STATE_FILE:-'.runner'}
|
|
||||||
|
|
||||||
CONFIG_ARG=""
|
CONFIG_ARG=""
|
||||||
if [[ ! -z "${CONFIG_FILE}" ]]; then
|
if [[ ! -z "${CONFIG_FILE}" ]]; then
|
||||||
CONFIG_ARG="--config ${CONFIG_FILE}"
|
CONFIG_ARG="--config ${CONFIG_FILE}"
|
||||||
fi
|
fi
|
||||||
|
RUNNER_STATE_FILE=${RUNNER_STATE_FILE:-$(gitea-runner ${CONFIG_ARG} config runner-file)}
|
||||||
LABEL_ARGS=""
|
LABEL_ARGS=""
|
||||||
if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then
|
if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then
|
||||||
LABEL_ARGS="--labels ${GITEA_RUNNER_LABELS}"
|
LABEL_ARGS="--labels ${GITEA_RUNNER_LABELS}"
|
||||||
|
|||||||
Reference in new issue
Block a user