How to execute npm run build before buildpack

Hi!

I’m exploring Waypoint to move from our current CI/CD stack to it. Until now I’m loving the tool :slight_smile:

I have a (problably) silly question, how can I execute npm run build before executing the use pack step?

Here is my waypoint.hcl file:

project = "execution-mode"

app "app" {
  build {
    use "pack" {
      builder = "gcr.io/buildpacks/builder:v1"
    }

    registry {
      use "aws-ecr" {
        region = "sa-east-1"
        repository = "execution-mode"
        tag = gitrefpretty()
      }
    }
  }

  deploy{
    use "exec" {
      command = [
        "bash",
        "-c",
        "bash <(curl -s https://raw.githubusercontent.com/budproj/gist/main/gitops/deploy.sh) -s develop -t ${gitrefpretty()}",
      ]
    }
  }
}

I don’t know if that should be a requirement from the build pack itself, or if we should run it before calling the buildpack :thinking:

Anyone can give me a hand?

Thanks!

I’m not too familiar with build packs but you could use a hook like this:

build {
  use "pack" {
    builder = "gcr.io/buildpacks/builder:v1"
  }

  hook {
      when = "before"
      command = ["npm", "run", "build"]
      on_failure = "continue"
  }

  registry {
    use "aws-ecr" {
      region = "sa-east-1"
      repository = "execution-mode"
      tag = gitrefpretty()
    }
  }
}

You can read more about hooks here:

1 Like