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

odo deploy/odo build-images fails for docker backend #5322

Closed
dharmit opened this issue Jan 10, 2022 · 8 comments · Fixed by #5602
Closed

odo deploy/odo build-images fails for docker backend #5322

dharmit opened this issue Jan 10, 2022 · 8 comments · Fixed by #5602
Assignees
Labels
area/deploy Issues or PRs specific to the `odo deploy` command kind/bug Categorizes issue or PR as related to a bug.

Comments

@dharmit
Copy link
Member

dharmit commented Jan 10, 2022

/kind bug

What versions of software are you using?

Operating System: Fedora 35

Output of odo version: main

How did you run odo exactly?

$ git clone https://github.com/kadel/devfile-nodejs-deploy
$ cd devfile-nodejs-deploy
$ sed -i 's/kadel/<my-quay-username>/' devfile.yaml
$ odo project create nodejs-example
$ odo create
$ odo deploy

Actual behavior

$ odo deploy

Building image quay.io/dharmit_rh/devfile-nodejs-deploy:latest
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
 ✗  command execution failed: error running docker command: exit status 1

$ odo build-images

Building image quay.io/dharmit_rh/devfile-nodejs-deploy:latest
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
 ✗  error running docker command: exit status 1

Expected behavior

Both commands should pass

Any logs, error output, etc?

  • The docker build command that's generated by odo is: docker build -t "quay.io/dharmit_rh/devfile-nodejs-deploy:latest" -f "/home/dshah/src/devfile-nodejs-deploy/Dockerfile" ${PROJECT_SOURCE}

  • Appending above command with a . (period) or path to the directory containing the devfile (devfilePath) in the function below solves the issue.

    func getShellCommand(cmdName string, image *devfile.ImageComponent, devfilePath string) string {

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Jan 10, 2022
@dharmit
Copy link
Member Author

dharmit commented Jan 10, 2022

/area deploy

@openshift-ci openshift-ci bot added the area/deploy Issues or PRs specific to the `odo deploy` command label Jan 10, 2022
@feloy
Copy link
Contributor

feloy commented Jan 10, 2022

This is the role of `${PROJECT_SOURCE} to append the working directory. The problem is probably because this variable is empty or not expanded correctly

@dharmit
Copy link
Member Author

dharmit commented Jan 10, 2022

Yes, the variable is surely not getting expanded. But where is this value ${PROJECT_SOURCE} getting assigned to it? While tracing it to devfile library, I found it should be ${PROJECT_ROOT} by default:

type Dockerfile struct {
// Path of source directory to establish build context. Defaults to ${PROJECT_ROOT} in the container
// +optional
BuildContext string `json:"buildContext,omitempty"`

It says Defaults to ${PROJECT_ROOT} in the container, but odo deploy isn't being run inside a container, it's run on the user's host system where they are running odo commands. I'm not sure if I'm tracing this to the right place. 🤔

@feloy
Copy link
Contributor

feloy commented Jan 10, 2022

It comes from the buildContext field of the image to build in the devfile you are using:

  - name: prod-image
    image:
      imageName: "{{CONTAINER_IMAGE}}"
      dockerfile:
        uri: ./Dockerfile
        buildContext: ${PROJECT_SOURCE}

@dharmit
Copy link
Member Author

dharmit commented Jan 10, 2022

Wow! That feels like an embarrassing question that I asked. 😆

Shouldn't this variable be defined in the devfile at: https://github.com/kadel/devfile-nodejs-deploy/blob/2b7058af5cdac5a43ded2b6c44454add7cf82161/devfile.yaml#L6-L8

Is this devfile invalid/erroneous in that case?

@feloy
Copy link
Contributor

feloy commented Jan 10, 2022

Wow! That feels like an embarrassing question that I asked. laughing

Shouldn't this variable be defined in the devfile at: https://github.com/kadel/devfile-nodejs-deploy/blob/2b7058af5cdac5a43ded2b6c44454add7cf82161/devfile.yaml#L6-L8

Is this devfile invalid/erroneous in that case?

I'm not sure. @kadel, where is this variable ${PROJECT_SOURCE} coming from on your repo's Dockerfile?

@kadel
Copy link
Member

kadel commented Jan 11, 2022

I'm not sure. @kadel, where is this variable ${PROJECT_SOURCE} coming from on your repo's Dockerfile?

This is a predefined env variable. Odo is automatically adding it to containers.

From devfile spec:

Special variables that can be used:

$PROJECTS_ROOT: A path where projects sources are mounted as defined by container component's sourceMapping.

$PROJECT_SOURCE: A path to a project source ($PROJECTS_ROOT/). If there are multiple projects, this will point to the directory of the first one.

@kadel
Copy link
Member

kadel commented Mar 15, 2022

before odo executes docker/podman command it should set PROJECT_SOURCE variable. value of this variable should be path to the directory with the devfile.yaml (current directory)

@kadel kadel moved this to Todo in odo v3-alpha1 Mar 17, 2022
@rm3l rm3l moved this from Todo to For Review in odo v3-alpha1 Mar 29, 2022
openshift-merge-robot pushed a commit that referenced this issue Mar 30, 2022
…ironment (#5602)

* Add test in `odo build-images` highlighting the issue

* Add test in `odo deploy` highlighting the issue

* Add `PROJECT_SOURCE` env var to the image build command

This way, it will get expanded by the shell.

NOTE: This will still not work on Windows, but #5588 should fix that other issue.
Repository owner moved this from For Review to Done in odo v3-alpha1 Mar 30, 2022
cdrage pushed a commit to cdrage/odo that referenced this issue Aug 31, 2022
…uild command environment (redhat-developer#5602)

* Add test in `odo build-images` highlighting the issue

* Add test in `odo deploy` highlighting the issue

* Add `PROJECT_SOURCE` env var to the image build command

This way, it will get expanded by the shell.

NOTE: This will still not work on Windows, but redhat-developer#5588 should fix that other issue.
@rm3l rm3l added the v3 label Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deploy Issues or PRs specific to the `odo deploy` command kind/bug Categorizes issue or PR as related to a bug.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants