Explorar o código

Merge branch 'dashboard-build-context' into docker-build-context

Ivan Galakhov %!s(int64=4) %!d(string=hai) anos
pai
achega
a3ed61a06b

+ 1 - 0
cli/cmd/deploy/deploy.go

@@ -131,6 +131,7 @@ func NewDeployAgent(client *api.Client, app string, opts *DeployOpts) (*DeployAg
 		deployAgent.dockerfilePath = deployAgent.opts.LocalDockerfile
 	} else {
 		deployAgent.imageRepo = release.GitActionConfig.ImageRepoURI
+		deployAgent.opts.LocalPath = release.GitActionConfig.FolderPath
 	}
 
 	if deployAgent.opts.Method == DeployBuildTypeDocker {

+ 14 - 31
dashboard/src/components/repo-selector/ActionConfEditor.tsx

@@ -67,44 +67,26 @@ const ActionConfEditor: React.FC<Props> = (props) => {
         </BackButton>
       </>
     );
-  } else if (!props.dockerfilePath && !props.folderPath) {
-    return (
-      <>
-        <ContentsList
-          actionConfig={actionConfig}
-          branch={branch}
-          setActionConfig={setActionConfig}
-          setDockerfilePath={(x: string) => props.setDockerfilePath(x)}
-          setProcfilePath={(x: string) => props.setProcfilePath(x)}
-          setFolderPath={(x: string) => props.setFolderPath(x)}
-        />
-        <Br />
-        <BackButton
-          width="145px"
-          onClick={() => {
-            setBranch("");
-          }}
-        >
-          <i className="material-icons">keyboard_backspace</i>
-          Select Branch
-        </BackButton>
-      </>
-    );
-  }
-
-  if (
-    props.procfilePath &&
-    props.folderPath &&
-    !props.dockerfilePath &&
-    !props.procfileProcess
+  } else if (
+    // select dockerfile or buildpack build context
+    (!props.dockerfilePath && !props.folderPath) ||
+    // select procfile process
+    (props.procfilePath &&
+      props.folderPath &&
+      !props.dockerfilePath &&
+      !props.procfileProcess) ||
+    // select docker build context
+    (props.dockerfilePath && !props.folderPath)
   ) {
     return (
       <>
         <ContentsList
           actionConfig={actionConfig}
           branch={branch}
-          setActionConfig={setActionConfig}
+          dockerfilePath={props.dockerfilePath}
           procfilePath={props.procfilePath}
+          folderPath={props.folderPath}
+          setActionConfig={setActionConfig}
           setDockerfilePath={(x: string) => props.setDockerfilePath(x)}
           setProcfilePath={(x: string) => props.setProcfilePath(x)}
           setProcfileProcess={(x: string) => props.setProcfileProcess(x)}
@@ -115,6 +97,7 @@ const ActionConfEditor: React.FC<Props> = (props) => {
           width="145px"
           onClick={() => {
             setBranch("");
+            props.setDockerfilePath("");
           }}
         >
           <i className="material-icons">keyboard_backspace</i>

+ 12 - 9
dashboard/src/components/repo-selector/ActionDetails.tsx

@@ -124,7 +124,7 @@ export default class ActionDetails extends Component<PropsType, StateType> {
           width="100%"
           value={this.props.branch}
         />
-        {this.props.dockerfilePath ? (
+        {this.props.dockerfilePath && (
           <InputRow
             disabled={true}
             label="Dockerfile Path"
@@ -132,15 +132,18 @@ export default class ActionDetails extends Component<PropsType, StateType> {
             width="100%"
             value={this.props.dockerfilePath}
           />
-        ) : (
-          <InputRow
-            disabled={true}
-            label="Folder Path"
-            type="text"
-            width="100%"
-            value={this.props.folderPath}
-          />
         )}
+        <InputRow
+          disabled={true}
+          label={
+            this.props.dockerfilePath
+              ? "Docker Build Context"
+              : "Application Folder"
+          }
+          type="text"
+          width="100%"
+          value={this.props.folderPath}
+        />
         {this.renderRegistrySection()}
         <Br />
 

+ 61 - 4
dashboard/src/components/repo-selector/ContentsList.tsx

@@ -19,6 +19,8 @@ interface AutoBuildpack {
 type PropsType = {
   actionConfig: ActionConfigType | null;
   branch: string;
+  dockerfilePath?: string;
+  folderPath: string;
   procfilePath?: string;
   setActionConfig: (x: ActionConfigType) => void;
   setProcfileProcess?: (x: string) => void;
@@ -35,6 +37,7 @@ type StateType = {
   dockerfiles: string[];
   processes: Record<string, string>;
   autoBuildpack: AutoBuildpack;
+  showingBuildContextPrompt: boolean;
 };
 
 export default class ContentsList extends Component<PropsType, StateType> {
@@ -49,6 +52,7 @@ export default class ContentsList extends Component<PropsType, StateType> {
       valid: false,
       name: "",
     },
+    showingBuildContextPrompt: true,
   };
 
   componentDidMount() {
@@ -184,7 +188,7 @@ export default class ContentsList extends Component<PropsType, StateType> {
         );
       }
 
-      if (fileName.includes("Dockerfile")) {
+      if (fileName.includes("Dockerfile") && !this.props.dockerfilePath) {
         return (
           <FileItem
             key={i}
@@ -228,12 +232,20 @@ export default class ContentsList extends Component<PropsType, StateType> {
     return (
       <FileItem lastItem={false}>
         <img src={info} />
-        Select Application Folder
+        Select{" "}
+        {this.props.dockerfilePath
+          ? "Docker Build Context"
+          : "Application Folder"}
       </FileItem>
     );
   };
 
   handleContinue = () => {
+    if (this.props.dockerfilePath) {
+      this.props.setFolderPath(this.state.currentDir || "./");
+      return;
+    }
+
     let dockerfiles = [] as string[];
     this.state.contents.forEach((item: FileType, i: number) => {
       let splits = item.Path.split("/");
@@ -319,7 +331,7 @@ export default class ContentsList extends Component<PropsType, StateType> {
         </Overlay>
       );
     }
-    if (this.state.dockerfiles.length > 0) {
+    if (this.state.dockerfiles.length > 0 && !this.props.dockerfilePath) {
       return (
         <Overlay>
           <BgOverlay onClick={() => this.setState({ dockerfiles: [] })} />
@@ -364,6 +376,45 @@ export default class ContentsList extends Component<PropsType, StateType> {
         </Overlay>
       );
     }
+    if (
+      this.props.dockerfilePath &&
+      !this.props.folderPath &&
+      this.state.showingBuildContextPrompt
+    ) {
+      return (
+        <Overlay>
+          <BgOverlay onClick={() => this.props.setDockerfilePath("")} />
+          <CloseButton
+            onClick={() =>
+              this.props.setFolderPath(this.state.currentDir || "./")
+            }
+          >
+            <CloseButtonImg src={close} />
+          </CloseButton>
+          <Label>
+            Would you like to set the Docker build context to a different
+            directory?
+          </Label>
+          <MultiSelectRow>
+            <ConfirmButton
+              onClick={() => {
+                this.setState({ showingBuildContextPrompt: false });
+                this.setSubdirectory("");
+              }}
+            >
+              Yes
+            </ConfirmButton>
+            <ConfirmButton
+              onClick={() =>
+                this.props.setFolderPath(this.state.currentDir || "./")
+              }
+            >
+              No
+            </ConfirmButton>
+          </MultiSelectRow>
+        </Overlay>
+      );
+    }
   };
 
   render() {
@@ -477,12 +528,18 @@ const Indicator = styled.div<{ selected: boolean }>`
 `;
 
 const Label = styled.div`
-  max-width: 420px;
+  max-width: 500px;
   line-height: 1.5em;
   text-align: center;
   font-size: 14px;
 `;
 
+const MultiSelectRow = styled.div`
+  display: flex;
+  min-width: 150px;
+  justify-content: space-between;
+`;
+
 const DockerfileList = styled.div`
   border-radius: 3px;
   margin-top: 20px;

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

@@ -147,7 +147,15 @@ class SourcePage extends Component<PropsType, StateType> {
     } = this.props;
     return (
       <StyledSourceBox>
-        <CloseButton onClick={() => setSourceType("")}>
+        <CloseButton
+          onClick={() => {
+            setSourceType("");
+            setDockerfilePath("");
+            setFolderPath("");
+            setProcfilePath("");
+            setProcfileProcess("");
+          }}
+        >
           <CloseButtonImg src={close} />
         </CloseButton>
         <Subtitle>

+ 1 - 0
server/api/deploy_handler.go

@@ -186,6 +186,7 @@ func (app *App) HandleDeployTemplate(w http.ResponseWriter, r *http.Request) {
 			GitBranch:      form.GithubActionConfig.GitBranch,
 			ImageRepoURI:   form.GithubActionConfig.ImageRepoURI,
 			DockerfilePath: form.GithubActionConfig.DockerfilePath,
+			FolderPath:     form.GithubActionConfig.FolderPath,
 			GitRepoID:      form.GithubActionConfig.GitRepoID,
 			RegistryID:     form.GithubActionConfig.RegistryID,