Skip to content

Commit

Permalink
Merge branch 'main' into pipeline-build-table
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Jul 20, 2023
2 parents c186d90 + af55191 commit ae60cbd
Show file tree
Hide file tree
Showing 451 changed files with 22,870 additions and 17,815 deletions.
14 changes: 13 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,16 @@ VELA_API=http://localhost:8080
# VELA_SCM_CLIENT=

# github client secret from oauth application
# VELA_SCM_SECRET=
# VELA_SCM_SECRET=

# COMPILER FLAGS
#
# compiler github is whether or not the compiler uses github to pull templates
#
# default: false
# VELA_COMPILER_GITHUB=

# compiler github url is the url used by the compiler to fetch templates
#
# default: https://github.com
# VELA_COMPILER_GITHUB_URL
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,30 @@ secrets.env
.env.test

# Files to be excluded.
.DS_Store
.DS_Store
api-spec.json

# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
__debug_bin

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Use of this source code is governed by the LICENSE file in this repository.

FROM alpine as certs
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70 as certs

RUN apk add --update --no-cache ca-certificates

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Use of this source code is governed by the LICENSE file in this repository.

FROM alpine
FROM alpine:3.18.2@sha256:25fad2a32ad1f6f510e528448ae1ec69a28ef81916a004d3629874104f8a7f70

RUN apk add --update --no-cache ca-certificates

Expand Down
6 changes: 3 additions & 3 deletions api/admin/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func AllBuildsQueue(c *gin.Context) {
after := c.DefaultQuery("after", strconv.FormatInt(time.Now().UTC().Add(-24*time.Hour).Unix(), 10))

// send API call to capture pending and running builds
b, err := database.FromContext(c).GetPendingAndRunningBuilds(after)
b, err := database.FromContext(c).ListPendingAndRunningBuilds(after)
if err != nil {
retErr := fmt.Errorf("unable to capture all running and pending builds: %w", err)

Expand Down Expand Up @@ -116,7 +116,7 @@ func UpdateBuild(c *gin.Context) {
}

// send API call to update the build
err = database.FromContext(c).UpdateBuild(input)
b, err := database.FromContext(c).UpdateBuild(input)
if err != nil {
retErr := fmt.Errorf("unable to update build %d: %w", input.GetID(), err)

Expand All @@ -125,5 +125,5 @@ func UpdateBuild(c *gin.Context) {
return
}

c.JSON(http.StatusOK, input)
c.JSON(http.StatusOK, b)
}
135 changes: 135 additions & 0 deletions api/admin/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

package admin

import (
"fmt"
"net/http"
"strconv"
"time"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types"
"github.com/go-vela/types/constants"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

// swagger:operation PUT /api/v1/admin/clean admin AdminCleanResources
//
// Update pending build resources to error status before a given time
//
// ---
// produces:
// - application/json
// parameters:
// - in: query
// name: before
// description: filter pending resources created before a certain time
// required: true
// type: integer
// - in: body
// name: body
// description: Payload containing error message
// required: true
// schema:
// "$ref": "#/definitions/Error"
// security:
// - ApiKeyAuth: []
// responses:
// '200':
// description: Successfully updated pending resources with error message
// schema:
// type: string
// '400':
// description: Unable to update resources — bad request
// schema:
// "$ref": "#/definitions/Error"
// '401':
// description: Unable to update resources — unauthorized
// schema:
// "$ref": "#/definitions/Error"
// '500':
// description: Unable to update resources
// schema:
// "$ref": "#/definitions/Error"

// CleanResources represents the API handler to
// update any user stored in the database.
func CleanResources(c *gin.Context) {
u := user.Retrieve(c)
logrus.Infof("platform admin %s: updating pending resources in database", u.GetName())

// default error message
msg := "build cleaned by platform admin"

// capture body from API request
input := new(types.Error)

err := c.Bind(input)
if err != nil {
retErr := fmt.Errorf("unable to decode JSON for error message: %w", err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

// if a message is provided, set the error message to that
if input.Message != nil {
msg = *input.Message
}

// capture before query parameter, default to max build timeout
before, err := strconv.ParseInt(c.DefaultQuery("before", fmt.Sprint((time.Now().Add(-(time.Minute * (constants.BuildTimeoutMax + 5)))).Unix())), 10, 64)
if err != nil {
retErr := fmt.Errorf("unable to convert before query parameter %s to int64: %w", c.Query("before"), err)

util.HandleError(c, http.StatusBadRequest, retErr)

return
}

// send API call to clean builds
builds, err := database.FromContext(c).CleanBuilds(msg, before)
if err != nil {
retErr := fmt.Errorf("unable to update builds: %w", err)

util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

logrus.Infof("platform admin %s: cleaned %d builds in database", u.GetName(), builds)

// clean services
services, err := database.FromContext(c).CleanServices(msg, before)
if err != nil {
retErr := fmt.Errorf("%d builds cleaned. unable to update services: %w", builds, err)

util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

logrus.Infof("platform admin %s: cleaned %d services in database", u.GetName(), services)

// clean steps
steps, err := database.FromContext(c).CleanSteps(msg, before)
if err != nil {
retErr := fmt.Errorf("%d builds cleaned. %d services cleaned. unable to update steps: %w", builds, services, err)

util.HandleError(c, http.StatusInternalServerError, retErr)

return
}

logrus.Infof("platform admin %s: cleaned %d steps in database", u.GetName(), steps)

c.JSON(http.StatusOK, fmt.Sprintf("%d builds cleaned. %d services cleaned. %d steps cleaned.", builds, services, steps))
}
4 changes: 2 additions & 2 deletions api/admin/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func UpdateHook(c *gin.Context) {
}

// send API call to update the hook
err = database.FromContext(c).UpdateHook(input)
h, err := database.FromContext(c).UpdateHook(input)
if err != nil {
retErr := fmt.Errorf("unable to update hook %d: %w", input.GetID(), err)

Expand All @@ -73,5 +73,5 @@ func UpdateHook(c *gin.Context) {
return
}

c.JSON(http.StatusOK, input)
c.JSON(http.StatusOK, h)
}
10 changes: 10 additions & 0 deletions api/auth/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2023 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.

// Package auth provides the auth handlers (authenticate, login, ...) for the Vela API.
//
// Usage:
//
// import "github.com/go-vela/server/api/auth"
package auth
Loading

0 comments on commit ae60cbd

Please sign in to comment.