mirror of
https://github.com/harness/drone.git
synced 2025-05-19 10:29:55 +08:00
added support for rollback
This commit is contained in:
parent
e97b1e968b
commit
870e967ee8
@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- support for validation plugins, by [@bradrydzewski](https://github.com/bradrydzewski). [#2266](https://github.com/drone/drone/issues/2266).
|
- support for validation plugins, by [@bradrydzewski](https://github.com/bradrydzewski). [#2266](https://github.com/drone/drone/issues/2266).
|
||||||
- support for conversion plugins, by [@bradrydzewski](https://github.com/bradrydzewski).
|
- support for conversion plugins, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||||
- support for cron event type, by [@bradrydzewski](https://github.com/bradrydzewski). [#2705](https://github.com/drone/drone/issues/2705).
|
- support for cron event type, by [@bradrydzewski](https://github.com/bradrydzewski). [#2705](https://github.com/drone/drone/issues/2705).
|
||||||
|
- support for rollback event, by [@bradrydzewski](https://github.com/bradrydzewski). [#2695](https://github.com/drone/drone/issues/2695).
|
||||||
|
- support for lets encrypt email, by [@bradrydzewski](https://github.com/bradrydzewski). [#2505](https://github.com/drone/drone/issues/2505).
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Support for basic auth as an option for Gitea, by [@techknowlogick](https://giteahub.com/techknowlogick). [#2721](https://github.com/drone/drone/issues/2721)
|
- Support for basic auth as an option for Gitea, by [@techknowlogick](https://giteahub.com/techknowlogick). [#2721](https://github.com/drone/drone/issues/2721)
|
||||||
|
@ -238,6 +238,7 @@ type (
|
|||||||
Port string `envconfig:"DRONE_SERVER_PORT" default:":8080"`
|
Port string `envconfig:"DRONE_SERVER_PORT" default:":8080"`
|
||||||
Proto string `envconfig:"DRONE_SERVER_PROTO" default:"http"`
|
Proto string `envconfig:"DRONE_SERVER_PROTO" default:"http"`
|
||||||
Acme bool `envconfig:"DRONE_TLS_AUTOCERT"`
|
Acme bool `envconfig:"DRONE_TLS_AUTOCERT"`
|
||||||
|
Email string `envconfig:"DRONE_TLS_EMAIL"`
|
||||||
Cert string `envconfig:"DRONE_TLS_CERT"`
|
Cert string `envconfig:"DRONE_TLS_CERT"`
|
||||||
Key string `envconfig:"DRONE_TLS_KEY"`
|
Key string `envconfig:"DRONE_TLS_KEY"`
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -19,7 +19,7 @@ require (
|
|||||||
github.com/docker/go-units v0.3.3
|
github.com/docker/go-units v0.3.3
|
||||||
github.com/drone/drone-go v1.0.6
|
github.com/drone/drone-go v1.0.6
|
||||||
github.com/drone/drone-runtime v1.1.0
|
github.com/drone/drone-runtime v1.1.0
|
||||||
github.com/drone/drone-ui v0.0.0-20190826173727-43d81f243ef3
|
github.com/drone/drone-ui v0.0.0-20190904041021-b4bb5da2b193
|
||||||
github.com/drone/drone-yaml v1.2.3-0.20190902155851-ad8ad9816fbf
|
github.com/drone/drone-yaml v1.2.3-0.20190902155851-ad8ad9816fbf
|
||||||
github.com/drone/envsubst v1.0.1
|
github.com/drone/envsubst v1.0.1
|
||||||
github.com/drone/go-license v1.0.2
|
github.com/drone/go-license v1.0.2
|
||||||
|
2
go.sum
2
go.sum
@ -79,6 +79,8 @@ github.com/drone/drone-ui v0.0.0-20190821232913-65807c0b23a3 h1:imiIbuxHbMjvN1r2
|
|||||||
github.com/drone/drone-ui v0.0.0-20190821232913-65807c0b23a3/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI=
|
github.com/drone/drone-ui v0.0.0-20190821232913-65807c0b23a3/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI=
|
||||||
github.com/drone/drone-ui v0.0.0-20190826173727-43d81f243ef3 h1:HZl9aANRu3LqhO5Adm2kaccMUH8yvbNP+0fd0mXR5YI=
|
github.com/drone/drone-ui v0.0.0-20190826173727-43d81f243ef3 h1:HZl9aANRu3LqhO5Adm2kaccMUH8yvbNP+0fd0mXR5YI=
|
||||||
github.com/drone/drone-ui v0.0.0-20190826173727-43d81f243ef3/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI=
|
github.com/drone/drone-ui v0.0.0-20190826173727-43d81f243ef3/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI=
|
||||||
|
github.com/drone/drone-ui v0.0.0-20190904041021-b4bb5da2b193 h1:T9pGkdg6kKcfF0VKXQ6+kTDBWhMOMm1BD5NbwsvDiQE=
|
||||||
|
github.com/drone/drone-ui v0.0.0-20190904041021-b4bb5da2b193/go.mod h1:NBtVWW7NNJpD9+huMD/5TAE1db2nrEh0i35/9Rf1MPI=
|
||||||
github.com/drone/drone-ui v0.8.1 h1:I4WBAlnk/YQzCggQy/Qegb8Nu2T2R9KVzxso/lL98so=
|
github.com/drone/drone-ui v0.8.1 h1:I4WBAlnk/YQzCggQy/Qegb8Nu2T2R9KVzxso/lL98so=
|
||||||
github.com/drone/drone-yaml v1.0.4 h1:NYTEGhf/XJMiJT8CwGy+pMOxWC8C2vhhzEo6/gbT4tU=
|
github.com/drone/drone-yaml v1.0.4 h1:NYTEGhf/XJMiJT8CwGy+pMOxWC8C2vhhzEo6/gbT4tU=
|
||||||
github.com/drone/drone-yaml v1.0.4/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI=
|
github.com/drone/drone-yaml v1.0.4/go.mod h1:eM365p3g9M5sroFBTR/najiGrZnd/GiIpWHC2UW8PoI=
|
||||||
|
@ -188,9 +188,9 @@ func (s Server) Handler() http.Handler {
|
|||||||
acl.CheckWriteAccess(),
|
acl.CheckWriteAccess(),
|
||||||
).Post("/{number}/promote", builds.HandlePromote(s.Repos, s.Builds, s.Triggerer))
|
).Post("/{number}/promote", builds.HandlePromote(s.Repos, s.Builds, s.Triggerer))
|
||||||
|
|
||||||
// r.With(
|
r.With(
|
||||||
// acl.CheckAdminAccess(),
|
acl.CheckAdminAccess(),
|
||||||
// ).Post("/{number}/rollback", builds.HandleRollback(s.Repos, s.Builds, s.Triggerer))
|
).Post("/{number}/rollback", builds.HandleRollback(s.Repos, s.Builds, s.Triggerer))
|
||||||
|
|
||||||
r.With(
|
r.With(
|
||||||
acl.CheckAdminAccess(),
|
acl.CheckAdminAccess(),
|
||||||
|
@ -71,6 +71,7 @@ func HandlePromote(
|
|||||||
AuthorEmail: prev.AuthorEmail,
|
AuthorEmail: prev.AuthorEmail,
|
||||||
AuthorAvatar: prev.AuthorAvatar,
|
AuthorAvatar: prev.AuthorAvatar,
|
||||||
Deployment: environ,
|
Deployment: environ,
|
||||||
|
Cron: prev.Cron,
|
||||||
Sender: prev.Sender,
|
Sender: prev.Sender,
|
||||||
Params: map[string]string{},
|
Params: map[string]string{},
|
||||||
}
|
}
|
||||||
|
@ -5,3 +5,99 @@
|
|||||||
// +build !oss
|
// +build !oss
|
||||||
|
|
||||||
package builds
|
package builds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/drone/drone/core"
|
||||||
|
"github.com/drone/drone/handler/api/render"
|
||||||
|
"github.com/drone/drone/handler/api/request"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleRollback returns an http.HandlerFunc that processes http
|
||||||
|
// requests to rollback and re-execute a build.
|
||||||
|
func HandleRollback(
|
||||||
|
repos core.RepositoryStore,
|
||||||
|
builds core.BuildStore,
|
||||||
|
triggerer core.Triggerer,
|
||||||
|
) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
environ = r.FormValue("target")
|
||||||
|
namespace = chi.URLParam(r, "owner")
|
||||||
|
name = chi.URLParam(r, "name")
|
||||||
|
user, _ = request.UserFrom(r.Context())
|
||||||
|
)
|
||||||
|
number, err := strconv.ParseInt(chi.URLParam(r, "number"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
render.BadRequest(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
repo, err := repos.FindName(r.Context(), namespace, name)
|
||||||
|
if err != nil {
|
||||||
|
render.NotFound(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prev, err := builds.FindNumber(r.Context(), repo.ID, number)
|
||||||
|
if err != nil {
|
||||||
|
render.NotFound(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if environ == "" {
|
||||||
|
render.BadRequestf(w, "Missing target environment")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hook := &core.Hook{
|
||||||
|
Parent: prev.Number,
|
||||||
|
Trigger: user.Login,
|
||||||
|
Event: core.EventRollback,
|
||||||
|
Action: prev.Action,
|
||||||
|
Link: prev.Link,
|
||||||
|
Timestamp: prev.Timestamp,
|
||||||
|
Title: prev.Title,
|
||||||
|
Message: prev.Message,
|
||||||
|
Before: prev.Before,
|
||||||
|
After: prev.After,
|
||||||
|
Ref: prev.Ref,
|
||||||
|
Fork: prev.Fork,
|
||||||
|
Source: prev.Source,
|
||||||
|
Target: prev.Target,
|
||||||
|
Author: prev.Author,
|
||||||
|
AuthorName: prev.AuthorName,
|
||||||
|
AuthorEmail: prev.AuthorEmail,
|
||||||
|
AuthorAvatar: prev.AuthorAvatar,
|
||||||
|
Deployment: environ,
|
||||||
|
Cron: prev.Cron,
|
||||||
|
Sender: prev.Sender,
|
||||||
|
Params: map[string]string{},
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range prev.Params {
|
||||||
|
hook.Params[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range r.URL.Query() {
|
||||||
|
if key == "access_token" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if key == "target" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(value) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
hook.Params[key] = value[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := triggerer.Trigger(r.Context(), repo, hook)
|
||||||
|
if err != nil {
|
||||||
|
render.InternalError(w, err)
|
||||||
|
} else {
|
||||||
|
render.JSON(w, result, 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
37
handler/api/repos/builds/rollback_oss.go
Normal file
37
handler/api/repos/builds/rollback_oss.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// Copyright 2019 Drone IO, Inc.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// +build oss
|
||||||
|
|
||||||
|
package builds
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/drone/drone/core"
|
||||||
|
"github.com/drone/drone/handler/api/render"
|
||||||
|
)
|
||||||
|
|
||||||
|
var notImplemented = func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
render.NotImplemented(w, render.ErrNotImplemented)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleRollback returns a non-op http.HandlerFunc.
|
||||||
|
func HandleRollback(
|
||||||
|
core.RepositoryStore,
|
||||||
|
core.BuildStore,
|
||||||
|
core.Triggerer,
|
||||||
|
) http.HandlerFunc {
|
||||||
|
return notImplemented
|
||||||
|
}
|
@ -20,6 +20,7 @@ import (
|
|||||||
// A Server defines parameters for running an HTTP server.
|
// A Server defines parameters for running an HTTP server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Acme bool
|
Acme bool
|
||||||
|
Email string
|
||||||
Addr string
|
Addr string
|
||||||
Cert string
|
Cert string
|
||||||
Key string
|
Key string
|
||||||
@ -90,6 +91,7 @@ func (s Server) listenAndServeAcme(ctx context.Context) error {
|
|||||||
|
|
||||||
c := cacheDir()
|
c := cacheDir()
|
||||||
m := &autocert.Manager{
|
m := &autocert.Manager{
|
||||||
|
Email: s.Email,
|
||||||
Cache: autocert.DirCache(c),
|
Cache: autocert.DirCache(c),
|
||||||
Prompt: autocert.AcceptTOS,
|
Prompt: autocert.AcceptTOS,
|
||||||
HostPolicy: autocert.HostWhitelist(s.Host),
|
HostPolicy: autocert.HostWhitelist(s.Host),
|
||||||
|
Loading…
Reference in New Issue
Block a user