Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.9.0] Set build context default to Dockerfile dir #1184

Merged
merged 9 commits into from
Sep 21, 2021
8 changes: 6 additions & 2 deletions cli/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func init() {
&localPath,
"path",
"p",
".",
"if local build, the path to the build directory",
"",
"if local build, the path to the build directory (default: Dockerfile directory)",
)

createCmd.PersistentFlags().StringVar(
Expand Down Expand Up @@ -164,6 +164,10 @@ func createFull(resp *api.AuthCheckResponse, client *api.Client, args []string)

color.New(color.FgGreen).Printf("Creating %s release: %s\n", args[0], name)

if localPath == "" {
localPath = filepath.Dir(dockerfile)
}

fullPath, err := filepath.Abs(localPath)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ func init() {
&localPath,
"path",
"p",
".",
"If local build, the path to the build directory. If remote build, the relative path from the repository root to the build directory.",
"",
"If local build, the path to the build directory. If remote build, the relative path from the repository root to the build directory. (default: Dockerfile directory)",
)

updateCmd.PersistentFlags().StringVarP(
Expand Down
8 changes: 7 additions & 1 deletion cli/cmd/deploy/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,13 @@ func (c *CreateAgent) CreateFromDocker(
}

if opts.Method == DeployBuildTypeDocker {
err = buildAgent.BuildDocker(agent, opts.LocalPath, ".", opts.LocalDockerfile, "latest")
basePath, err := filepath.Abs(".")

if err != nil {
return "", err
}

err = buildAgent.BuildDocker(agent, basePath, opts.LocalPath, opts.LocalDockerfile, "latest")
} else {
err = buildAgent.BuildPack(agent, opts.LocalPath, "latest")
}
Expand Down
7 changes: 7 additions & 0 deletions cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ 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 {
if deployAgent.opts.LocalPath == "" {
deployAgent.opts.LocalPath = filepath.Dir(deployAgent.dockerfilePath)
}
}

deployAgent.tag = opts.OverrideTag
Expand Down
45 changes: 14 additions & 31 deletions dashboard/src/components/repo-selector/ActionConfEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -115,6 +97,7 @@ const ActionConfEditor: React.FC<Props> = (props) => {
width="145px"
onClick={() => {
setBranch("");
props.setDockerfilePath("");
}}
>
<i className="material-icons">keyboard_backspace</i>
Expand Down
21 changes: 12 additions & 9 deletions dashboard/src/components/repo-selector/ActionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,26 @@ 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"
type="text"
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 />

Expand Down
65 changes: 61 additions & 4 deletions dashboard/src/components/repo-selector/ContentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +37,7 @@ type StateType = {
dockerfiles: string[];
processes: Record<string, string>;
autoBuildpack: AutoBuildpack;
showingBuildContextPrompt: boolean;
};

export default class ContentsList extends Component<PropsType, StateType> {
Expand All @@ -49,6 +52,7 @@ export default class ContentsList extends Component<PropsType, StateType> {
valid: false,
name: "",
},
showingBuildContextPrompt: true,
};

componentDidMount() {
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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("/");
Expand Down Expand Up @@ -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: [] })} />
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion dashboard/src/main/home/launch/launch-flow/SourcePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions server/api/deploy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down