Sfoglia il codice sorgente

fix bugs that have come up

Alexander Belanger 4 anni fa
parent
commit
3ecf5417b9

+ 2 - 4
api/server/handlers/gitinstallation/get_buildpack.go

@@ -10,7 +10,6 @@ import (
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 )
 
@@ -44,10 +43,9 @@ func (c *GithubGetBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 		return
 	}
 
-	branch, reqErr := requestutils.GetURLParamString(r, types.URLParamGitBranch)
+	branch, ok := GetBranch(c, w, r)
 
-	if reqErr != nil {
-		c.HandleAPIError(w, r, reqErr)
+	if !ok {
 		return
 	}
 

+ 2 - 4
api/server/handlers/gitinstallation/get_contents.go

@@ -10,7 +10,6 @@ import (
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 )
 
@@ -44,10 +43,9 @@ func (c *GithubGetContentsHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		return
 	}
 
-	branch, reqErr := requestutils.GetURLParamString(r, types.URLParamGitBranch)
+	branch, ok := GetBranch(c, w, r)
 
-	if reqErr != nil {
-		c.HandleAPIError(w, r, reqErr)
+	if !ok {
 		return
 	}
 

+ 2 - 4
api/server/handlers/gitinstallation/get_procfile.go

@@ -12,7 +12,6 @@ import (
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 )
 
@@ -48,10 +47,9 @@ func (c *GithubGetProcfileHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		return
 	}
 
-	branch, reqErr := requestutils.GetURLParamString(r, types.URLParamGitBranch)
+	branch, ok := GetBranch(c, w, r)
 
-	if reqErr != nil {
-		c.HandleAPIError(w, r, reqErr)
+	if !ok {
 		return
 	}
 

+ 2 - 4
api/server/handlers/gitinstallation/get_tarball_url.go

@@ -10,7 +10,6 @@ import (
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
 )
 
@@ -36,10 +35,9 @@ func (c *GithubGetTarballURLHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
 		return
 	}
 
-	branch, reqErr := requestutils.GetURLParamString(r, types.URLParamGitBranch)
+	branch, ok := GetBranch(c, w, r)
 
-	if reqErr != nil {
-		c.HandleAPIError(w, r, reqErr)
+	if !ok {
 		return
 	}
 

+ 21 - 0
api/server/handlers/gitinstallation/helpers.go

@@ -2,10 +2,12 @@ package gitinstallation
 
 import (
 	"net/http"
+	"net/url"
 
 	"github.com/bradleyfalzon/ghinstallation"
 	"github.com/google/go-github/github"
 	"github.com/porter-dev/porter/api/server/handlers"
+	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/config"
 	"github.com/porter-dev/porter/api/server/shared/requestutils"
 	"github.com/porter-dev/porter/api/types"
@@ -91,3 +93,22 @@ func GetOwnerAndNameParams(c handlers.PorterHandler, w http.ResponseWriter, r *h
 
 	return owner, name, true
 }
+
+// GetBranch gets the unencoded branch
+func GetBranch(c handlers.PorterHandler, w http.ResponseWriter, r *http.Request) (string, bool) {
+	branch, reqErr := requestutils.GetURLParamString(r, types.URLParamGitBranch)
+
+	if reqErr != nil {
+		c.HandleAPIError(w, r, reqErr)
+		return "", false
+	}
+
+	branch, err := url.QueryUnescape(branch)
+
+	if reqErr != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return "", false
+	}
+
+	return branch, true
+}

+ 2 - 1
api/server/handlers/release/create.go

@@ -170,7 +170,7 @@ func createGitAction(
 	release *models.Release,
 ) (*types.GitActionConfig, []byte, error) {
 	// if the registry was provisioned through Porter, create a repository if necessary
-	if request.RegistryID != 0 {
+	if release != nil && request.RegistryID != 0 {
 		// read the registry
 		reg, err := config.Repo.Registry().ReadRegistry(projectID, request.RegistryID)
 
@@ -224,6 +224,7 @@ func createGitAction(
 		ProjectID:              projectID,
 		ClusterID:              clusterID,
 		ReleaseName:            name,
+		ReleaseNamespace:       namespace,
 		GitBranch:              request.GitBranch,
 		DockerFilePath:         request.DockerfilePath,
 		FolderPath:             request.FolderPath,

+ 1 - 1
dashboard/src/main/home/launch/launch-flow/WorkflowPage.tsx

@@ -33,7 +33,7 @@ const WorkflowPage: React.FC<PropsType> = (props) => {
       .getGHAWorkflowTemplate(
         "<token>",
         {
-          name: props.name,
+          release_name: props.name,
           github_action_config: props.fullActionConfig,
         },
         {

+ 3 - 5
dashboard/src/main/home/modals/AccountSettingsModal.tsx

@@ -13,7 +13,6 @@ import Helper from "components/form-components/Helper";
 import TabSelector from "components/TabSelector";
 
 interface GithubAppAccessData {
-  has_access: boolean;
   username?: string;
   accounts?: string[];
 }
@@ -24,9 +23,8 @@ const AccountSettingsModal = () => {
   const { setCurrentModal } = useContext(Context);
   const [accessLoading, setAccessLoading] = useState(true);
   const [accessError, setAccessError] = useState(false);
-  const [accessData, setAccessData] = useState<GithubAppAccessData>({
-    has_access: false,
-  });
+  const [accessData, setAccessData] = useState<GithubAppAccessData>({});
+
   const [currentTab, setCurrentTab] = useState("integrations");
 
   useEffect(() => {
@@ -72,7 +70,7 @@ const AccountSettingsModal = () => {
       ) : (
         <>
           {/* Will be styled (and show what account is connected) later */}
-          {accessData.has_access ? (
+          {accessData.accounts?.length > 0 ? (
             <Placeholder>
               <User>
                 You are currently authorized as <B>{accessData.username}</B> and

+ 1 - 1
dashboard/src/shared/api.tsx

@@ -276,7 +276,7 @@ const getNotificationConfig = baseApi<
 
 const getGHAWorkflowTemplate = baseApi<
   {
-    name: string;
+    release_name: string;
     github_action_config: FullActionConfigType;
   },
   {

+ 35 - 0
docker/cli.Dockerfile

@@ -0,0 +1,35 @@
+# syntax=docker/dockerfile:1.1.7-experimental
+
+# Base Go environment
+# -------------------
+FROM golang:1.15-alpine as base
+WORKDIR /porter
+
+RUN apk update && apk add --no-cache gcc musl-dev git make
+
+COPY go.mod go.sum ./
+COPY /cli ./cli
+COPY /internal ./internal
+COPY /api ./api
+
+RUN --mount=type=cache,target=$GOPATH/pkg/mod \
+    go mod download
+
+# Go build environment
+# --------------------
+FROM base AS build-go
+
+ARG version=production
+
+RUN make build-cli
+
+# Deployment environment
+# ----------------------
+FROM alpine
+RUN apk update
+
+COPY --from=build-go /porter/bin/porter .
+
+RUN chmod +x ./porter && mv ./porter /usr/local/bin/
+
+ENTRYPOINT ["porter"]