Nx – Run Commands – Docker

  docker, heroku, nrwl

I’m currently trying to configure my workspace.json file to include the commands to build a docker image and push it. These commands work running them through the terminal (bash or windows), but I would like to get them setup in the cli so I can pass in the appName.

Project Structure

   ---/
      Dockerfile.api
      workspace.json
      ....

Configuration

{
  "version": 1,
  "projects": {
    "api": {
      "heroku-deploy": {
        "builder": "@nrwl/workspace:run-commands",
        "options": {
          "commands": [
            {
              "command": "docker build -t registry.heroku.com/{args.appName}/web -f ./Dockerfile.api ."
            },
            {
              "command": "docker push registry.heroku.com/{args.appName}/web"
            },
            {
              "command": "heroku container:release web -a {args.appName}"
            }
          ]
        }
      }
    }
  }
}

Running the command

nx run api:heroku-deploy2 --args="--appName=nx-api-leopard" --verbose

Error

#1 [internal] load build definition from Dockerfile.web
#1 sha256:8f9045a5ed51569cdcff9c6e9f9052e7e724435b6f2eeec087ea2770af2a3b0d
#1 transferring dockerfile: 2B done
#1 DONE 0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount178807147/Dockerfile.web: no such file or directory
Warning: @nrwl/run-commands command "docker build -t registry.heroku.com/my-nx-app/web -f ./Dockerfile.web ." exited with non-zero status code

Resources

Source: Docker Questions

LEAVE A COMMENT