mirror of
				https://gitea.com/gitea/act_runner.git
				synced 2025-10-31 04:47:58 +01:00 
			
		
		
		
	ephemeral act runner (#649)
Works for both interactive and non-interactive registration mode. A further enhancement would be jitconfig support of the daemon command, because after some changes in Gitea Actions the registration token became reusable. removing runner and fail seems not possible at the current api level Part of https://github.com/go-gitea/gitea/pull/33570 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/649 Reviewed-by: Zettat123 <zettat123@noreply.gitea.com> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
This commit is contained in:
		
				
					committed by
					
						 Lunny Xiao
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							0d687268c7
						
					
				
				
					commit
					b1ae30dda8
				
			| @@ -75,6 +75,7 @@ type registerArgs struct { | ||||
| 	Token         string | ||||
| 	RunnerName    string | ||||
| 	Labels        string | ||||
| 	Ephemeral     bool | ||||
| } | ||||
|  | ||||
| type registerStage int8 | ||||
| @@ -101,6 +102,7 @@ type registerInputs struct { | ||||
| 	Token        string | ||||
| 	RunnerName   string | ||||
| 	Labels       []string | ||||
| 	Ephemeral    bool | ||||
| } | ||||
|  | ||||
| func (r *registerInputs) validate() error { | ||||
| @@ -258,6 +260,7 @@ func registerNoInteractive(ctx context.Context, configFile string, regArgs *regi | ||||
| 		Token:        regArgs.Token, | ||||
| 		RunnerName:   regArgs.RunnerName, | ||||
| 		Labels:       defaultLabels, | ||||
| 		Ephemeral:    regArgs.Ephemeral, | ||||
| 	} | ||||
| 	regArgs.Labels = strings.TrimSpace(regArgs.Labels) | ||||
| 	// command line flag. | ||||
| @@ -321,10 +324,11 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs) | ||||
| 	} | ||||
|  | ||||
| 	reg := &config.Registration{ | ||||
| 		Name:    inputs.RunnerName, | ||||
| 		Token:   inputs.Token, | ||||
| 		Address: inputs.InstanceAddr, | ||||
| 		Labels:  inputs.Labels, | ||||
| 		Name:      inputs.RunnerName, | ||||
| 		Token:     inputs.Token, | ||||
| 		Address:   inputs.InstanceAddr, | ||||
| 		Labels:    inputs.Labels, | ||||
| 		Ephemeral: inputs.Ephemeral, | ||||
| 	} | ||||
|  | ||||
| 	ls := make([]string, len(reg.Labels)) | ||||
| @@ -339,6 +343,7 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs) | ||||
| 		Version:     ver.Version(), | ||||
| 		AgentLabels: ls, // Could be removed after Gitea 1.20 | ||||
| 		Labels:      ls, | ||||
| 		Ephemeral:   reg.Ephemeral, | ||||
| 	})) | ||||
| 	if err != nil { | ||||
| 		log.WithError(err).Error("poller: cannot register new runner") | ||||
| @@ -350,6 +355,11 @@ func doRegister(ctx context.Context, cfg *config.Config, inputs *registerInputs) | ||||
| 	reg.Name = resp.Msg.Runner.Name | ||||
| 	reg.Token = resp.Msg.Runner.Token | ||||
|  | ||||
| 	if inputs.Ephemeral != resp.Msg.Runner.Ephemeral { | ||||
| 		// TODO we cannot remove the configuration via runner api, if we return an error here we just fill the database | ||||
| 		log.Error("poller: cannot register new runner as ephemeral upgrade Gitea to gain security, run-once will be used automatically") | ||||
| 	} | ||||
|  | ||||
| 	if err := config.SaveRegistration(cfg.Runner.File, reg); err != nil { | ||||
| 		return fmt.Errorf("failed to save runner config: %w", err) | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user