Skip to content

Commit

Permalink
Updated Build Process (#3583)
Browse files Browse the repository at this point in the history
- Updated Build Process
- added logic to handle M1/arm processors
- Updated to Golang 1.19
- Updated Build - Go 1.19 + Swagger Lib Updates
- updated to swagger v0.29.0
- updated go.mod openapi libs
- updated lint tool version
- resolved lint errors

Signed-off-by: David Deal <[email protected]>
  • Loading branch information
dealako authored Aug 31, 2022
1 parent 7d97620 commit 456b099
Show file tree
Hide file tree
Showing 32 changed files with 261 additions and 329 deletions.
20 changes: 4 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ set_functional_test_environment: &set_functional_test_environment
echo "export AUTH0_USER5_CLIENT_ID='${!AUTH0_USER5_CLIENT_ID_ENV_VAR}'" >> ${BASH_ENV}
step-library:
- &install-node-8
run:
name: Install node 8
command: |
set +e
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
node_version="v8.17.0"
echo "Installing node ${node_version}..."
nvm install ${node_version}
nvm alias default ${node_version}
echo "[ -s \"${NVM_DIR}/nvm.sh\" ] && . \"${NVM_DIR}/nvm.sh\"" >> $BASH_ENV
- &install-node-12
run:
name: Install node 12
Expand Down Expand Up @@ -198,10 +185,10 @@ jobs:

buildGoBackend: &buildGoBackendAnchor
docker:
- image: circleci/golang:1.17
working_directory: /go/src/github.com/communitybridge/easycla/
- image: cimg/go:1.19.0
steps:
- checkout
- run: go version
- add_ssh_keys:
fingerprints:
- "e9:13:85:f1:b1:a1:25:bf:f5:44:34:66:82:1e:31:59"
Expand Down Expand Up @@ -675,11 +662,12 @@ jobs:
functionalTestsGo: &functionalTestsGo
docker:
- image: circleci/golang:1.17
- image: cimg/go:1.19.0
steps:
- attach_workspace:
at: ~/
- checkout
- run: go version
- *set_functional_test_environment
- run:
name: functional-tests-go
Expand Down
31 changes: 25 additions & 6 deletions cla-backend-go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ COMMIT := $(shell sh -c 'git rev-parse --short HEAD')
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X main.buildDate=$(BUILD_TIME)"
BUILD_TAGS=-tags aws_lambda

ifeq "$(shell uname -p)" "arm"
BUILD_ARCH=arm64
else
# ifeq "$(shell uname -p)" "x86_64"
BUILD_ARCH=amd64
endif
ifeq "$(shell uname -s)" "Darwin"
BUILD_HOST=darwin
endif
Expand All @@ -28,11 +34,12 @@ ifeq "$(shell uname -s)" "Linux"
endif

LINT_TOOL=$(shell go env GOPATH)/bin/golangci-lint
LINT_VERSION=v1.46.2
LINT_VERSION=v1.48.0
SWAGGER_DIR=$(ROOT_DIR)/swagger
SWAGGER_BIN_DIR=/usr/local/bin
SWAGGER_TOOL_VERSION=v0.24.0
SWAGGER_ASSET="swagger_$(BUILD_HOST)_amd64"
#SWAGGER_TOOL_VERSION=v0.24.0
SWAGGER_TOOL_VERSION=v0.29.0
SWAGGER_ASSET="swagger_$(BUILD_HOST)_$(BUILD_ARCH)"
SWAGGER_ASSET_URL="https://github.com/go-swagger/go-swagger/releases/download/$(SWAGGER_TOOL_VERSION)/$(SWAGGER_ASSET)"
GO_PKGS=$(shell go list ./... | grep -v /vendor/ | grep -v /node_modules/)
GO_FILES=$(shell find . -type f -name '*.go' -not -path './vendor/*')
Expand Down Expand Up @@ -104,6 +111,8 @@ swagger-prep:

swagger-build-v1-services:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version )"
@echo "Go version is: $(shell go version )"
@echo "Generating v1 legacy API models..."
cd swagger; source .venv/bin/activate && python3 multi-file-swagger.py --spec-input-file cla.v1.yaml --spec-output-file cla.v1.compiled.yaml
swagger -q generate server \
Expand All @@ -114,10 +123,12 @@ swagger-build-v1-services:
--model-package=v1/models \
--exclude-main \
-A cla \
-P user.CLAUser
-P github.com/communitybridge/easycla/cla-backend-go/user.CLAUser

swagger-build-v2-services:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version)"
@echo "Go version is: $(shell go version )"
@echo "Generating v2 API models..."
cd swagger; source .venv/bin/activate && python3 multi-file-swagger.py --spec-input-file cla.v2.yaml --spec-output-file cla.v2.compiled.yaml
swagger -q generate server \
Expand All @@ -128,10 +139,12 @@ swagger-build-v2-services:
--model-package=v2/models \
--exclude-main \
-A easycla \
-P auth.User
-P github.com/LF-Engineering/lfx-kit/auth.User

swagger-build-project-service:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version)"
@echo "Go version is: $(shell go version )"
@echo "Generating swagger client for the project-service..."
@mkdir -p v2/project-service
curl -sfL https://api-gw.dev.platform.linuxfoundation.org/project-service/swagger.json --output swagger/project-service.yaml
Expand All @@ -144,6 +157,8 @@ swagger-build-project-service:

swagger-build-organization-service:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version )"
@echo "Go version is: $(shell go version )"
@echo "Generating swagger client for the organization-service..."
@mkdir -p v2/organization-service
curl -sfL https://api-gw.dev.platform.linuxfoundation.org/organization-service/swagger.json --output swagger/organization-service.yaml
Expand All @@ -156,6 +171,8 @@ swagger-build-organization-service:

swagger-build-user-service:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version )"
@echo "Go version is: $(shell go version )"
@echo "Generating swagger client for the user-service..."
@mkdir -p v2/user-service
curl -sfL https://api-gw.dev.platform.linuxfoundation.org/user-service/swagger.json --output swagger/user-service.yaml
Expand All @@ -168,6 +185,8 @@ swagger-build-user-service:

swagger-build-acs-service:
@echo
@echo "Swagger version is: $(shell $(SWAGGER_BIN_DIR)/swagger version )"
@echo "Go version is: $(shell go version )"
@echo "Generating swagger client for the acs-service..."
@mkdir -p v2/acs-service
curl -sfL https://api-gw.dev.platform.linuxfoundation.org/acs/v1/api-docs/swagger/swagger.json --output swagger/acs-service.yaml
Expand Down Expand Up @@ -333,6 +352,6 @@ build-functional-tests-mac: deps build-prep
@chmod +x $(BIN_DIR)/$(FUNCTIONAL_TESTS_BIN)-mac

lint:
@cd $(MAKEFILE_DIR) && echo "Running lint..." && $(LINT_TOOL) --version && $(LINT_TOOL) run --exclude="this method will not auto-escape HTML. Verify data is well formed" --allow-parallel-runners --config=.golangci.yaml ./... && echo "Lint check passed."
@cd $(MAKEFILE_DIR) && $(LINT_TOOL) version && echo "Running lint..." && $(LINT_TOOL) run --exclude="this method will not auto-escape HTML. Verify data is well formed" --allow-parallel-runners --config=.golangci.yaml ./... && echo "Lint check passed."
@cd $(MAKEFILE_DIR) && ./check-headers.sh

4 changes: 2 additions & 2 deletions cla-backend-go/cmd/user-subscribe-lambda/cmd/serve_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package cmd
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand All @@ -24,7 +24,7 @@ func postSQSEvent(w http.ResponseWriter, r *http.Request) {
return
}

dataByte, err := ioutil.ReadAll(r.Body)
dataByte, err := io.ReadAll(r.Body)
if err != nil {
log.Println("Failed to read body")
http.Error(w, "Failed to read body", http.StatusInternalServerError)
Expand Down
13 changes: 10 additions & 3 deletions cla-backend-go/config/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ package config

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

log "github.com/communitybridge/easycla/cla-backend-go/logging"
"github.com/sirupsen/logrus"
)

func loadLocalConfig(configFilePath string) (Config, error) {
configData, err := ioutil.ReadFile(filepath.Clean(configFilePath))
f := logrus.Fields{
"functionName": "config.local.loadLocalConfig",
}
content, err := os.ReadFile(filepath.Clean(configFilePath))
if err != nil {
log.WithFields(f).WithError(err).Warnf("Failed to read config file: %s", configFilePath)
return Config{}, err
}

localConfig := Config{}
err = json.Unmarshal(configData, &localConfig)
err = json.Unmarshal(content, &localConfig)
if err != nil {
return Config{}, err
}
Expand Down
6 changes: 3 additions & 3 deletions cla-backend-go/emails/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ type CLAProjectParams struct {
// it checks at SignedAtFoundationLevel flag as well for this specific kind of projects
func (p CLAProjectParams) GetProjectFullURL() template.HTML {
if p.CorporateConsole == "" {
return template.HTML(p.ExternalProjectName)
return template.HTML(url.QueryEscape(p.ExternalProjectName)) // nolint gosec auto-escape HTML
}

u, err := url.Parse(p.CorporateConsole)
if err != nil {
log.Warnf("couldn't parse the console url, probably wrong configuration used : %s : %v", p.CorporateConsole, err)
// at least return the project name so we don't have broken email
return template.HTML(p.ExternalProjectName)
return template.HTML(url.QueryEscape(p.ExternalProjectName)) // nolint gosec auto-escape HTML
}

var projectConsolePathURL string
Expand All @@ -61,7 +61,7 @@ func (p CLAProjectParams) GetProjectFullURL() template.HTML {
projectConsolePathURL = u.String()
}

return template.HTML(fmt.Sprintf(fullURLHtml, projectConsolePathURL, p.ExternalProjectName))
return template.HTML(fmt.Sprintf(fullURLHtml, projectConsolePathURL, url.QueryEscape(p.ExternalProjectName))) // nolint gosec auto-escape HTML
}

// CLAGroupTemplateParams includes the params for the CLAGroupTemplateParams
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/emails/v2_cla_manager_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/communitybridge/easycla/cla-backend-go/utils"
)

//Contributor representing GH user details
// Contributor representing GH user details
type Contributor struct {
Email string
Username string
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/events/event_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type SignatureProjectInvalidatedEventData struct {
InvalidatedCount int
}

//SignatureInvalidatedApprovalRejectionEventData data model
// SignatureInvalidatedApprovalRejectionEventData data model
type SignatureInvalidatedApprovalRejectionEventData struct {
GHUsername string
Email string
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/events/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package events

import "github.com/communitybridge/easycla/cla-backend-go/gen/v1/models"

//IndividualSignedEvent represntative of ICLA signatures
// IndividualSignedEvent represntative of ICLA signatures
const IndividualSignedEvent = "IndividualSignatureSigned"

// Event data model
Expand Down
14 changes: 7 additions & 7 deletions cla-backend-go/gerrits/lf_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -81,7 +81,7 @@ func (lfg *LFGroup) getAccessToken(ctx context.Context) (string, error) {
}
}()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem reading the response from URL: %s", OauthURL)
return "", err
Expand Down Expand Up @@ -138,7 +138,7 @@ func (lfg *LFGroup) GetGroup(ctx context.Context, groupID string) (*LDAPGroup, e
}
}()

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem reading the response from URL: %s", getGroupURL)
return nil, err
Expand Down Expand Up @@ -178,7 +178,7 @@ func (lfg *LFGroup) GetUsersOfGroup(ctx context.Context, authUser *auth.User, cl
// API Docs: https://confluence.linuxfoundation.org/display/IPM/Drupal+Identity+REST+for+Auth0
url := fmt.Sprintf("%s/rest/auth0/og/%s", lfg.LfBaseURL, groupName)

// Setup the request
// Set up the request
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem creating a new request to URL: %s", url)
Expand Down Expand Up @@ -210,7 +210,7 @@ func (lfg *LFGroup) GetUsersOfGroup(ctx context.Context, authUser *auth.User, cl
log.WithFields(f).Debugf("successfully fetched members from group: %s", groupName)

var result v2Models.GerritGroupResponse
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem reading response for url: %s", url)
return nil, err
Expand Down Expand Up @@ -265,7 +265,7 @@ func (lfg *LFGroup) AddUserToGroup(ctx context.Context, authUser *auth.User, cla
return err
}

// Setup the request
// Set up the request
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(payloadBytes))
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem creating a new request to URL: %s", url)
Expand Down Expand Up @@ -347,7 +347,7 @@ func (lfg *LFGroup) RemoveUserFromGroup(ctx context.Context, authUser *auth.User
return err
}

// Setup the request
// Set up the request
req, err := http.NewRequest("DELETE", url, bytes.NewBuffer(payloadBytes))
if err != nil {
log.WithFields(f).WithError(err).Warnf("problem creating a new request to URL: %s", url)
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/github/branch_protection/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type V4BranchProtectionRepository interface {
GetRepositoryIDFromName(ctx context.Context, repositoryOwner, repositoryName string) (string, error)
}

//CombinedRepository is combination of V3Repositories and V4BranchProtectionRepository
// CombinedRepository is combination of V3Repositories and V4BranchProtectionRepository
type CombinedRepository interface {
V3Repositories
V4BranchProtectionRepository
Expand Down
8 changes: 4 additions & 4 deletions cla-backend-go/github/branch_protection/protected_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func (bp *BranchProtectionRepository) GetProtectedBranch(ctx context.Context, ow
return nil, ErrBranchNotProtected
}

//EnableBranchProtection enables branch protection if not enabled and makes sure passed arguments such as enforceAdmin
//statusChecks are applied. The operation makes sure it doesn't override the existing checks.
// EnableBranchProtection enables branch protection if not enabled and makes sure passed arguments such as enforceAdmin
// statusChecks are applied. The operation makes sure it doesn't override the existing checks.
func (bp *BranchProtectionRepository) EnableBranchProtection(ctx context.Context, owner, repoName, branchName string, enforceAdmin bool, enableStatusChecks, disableStatusChecks []string) error {
repoName = CleanGithubRepoName(repoName)

Expand Down Expand Up @@ -220,7 +220,7 @@ func (bp *BranchProtectionRepository) EnableBranchProtection(ctx context.Context
return nil
}

//mergeStatusChecks merges the current checks with the new ones and disable the ones that are specified
// mergeStatusChecks merges the current checks with the new ones and disable the ones that are specified
func mergeStatusChecks(currentChecks []string, enableContexts, disableContexts []string) []string {

// seems github api is not happy with nils for arrays ;)
Expand Down Expand Up @@ -321,7 +321,7 @@ func prepareBranchProtectionMutation(repoID string, currentProtections []BranchP
return nil, &updateInput
}

//IsEnforceAdminEnabled checks if enforce admin option is enabled for the branch protection
// IsEnforceAdminEnabled checks if enforce admin option is enabled for the branch protection
func IsEnforceAdminEnabled(protection *BranchProtectionRule) bool {
return protection.IsAdminEnforced
}
Expand Down
2 changes: 1 addition & 1 deletion cla-backend-go/github/github_org.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetOrganization(ctx context.Context, organizationName string) (*github.Orga
return org, nil
}

//GetOrganizationMembers gets members in organization
// GetOrganizationMembers gets members in organization
func GetOrganizationMembers(ctx context.Context, orgName string, installationID int64) ([]string, error) {
f := logrus.Fields{
"functionName": "GetOrganizationMembers",
Expand Down
Loading

0 comments on commit 456b099

Please sign in to comment.