#How can I import a bash script into a layer when building a custom extension?

1 messages · Page 1 of 1 (latest)

lavish finch
#

I am building a custom extension, and would like to import a bash script that I can run from within a task. Where can I find an example of how to do it?

supple shuttleBOT
#

Hi @lavish finch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To import a bash script into a layer when building a custom extension for Trigger.dev, you can use the additionalFiles extension along with custom commands in your build layer. Here's how you can do it:

  1. First, use the additionalFiles extension to include your bash script in the build:
import { defineConfig } from "@trigger.dev/sdk/v3";
import { additionalFiles } from "@trigger.dev/build/extensions/core";

export default defineConfig({
  project: "<project ref>",
  build: {
    extensions: [
      additionalFiles({ files: ["path/to/your/script.sh"] }),
      // Your custom extension here
    ],
  },
});
  1. Then, in your custom extension, you can add a layer that copies the script to a specific location and makes it executable:
import { defineConfig } from "@trigger.dev/sdk/v3";
import { BuildExtension } from "@trigger.dev/build";

function myCustomExtension(): BuildExtension {
  return {
    name: "my-custom-extension",
    onBuildComplete: (context) => {
      context.addLayer({
        id: "my-script-layer",
        commands: [
          "mkdir -p /app/scripts",
          "cp /app/path/to/your/script.sh /app/scripts/",
          "chmod +x /app/scripts/script.sh"
        ],
      });
    },
  };
}

export default defineConfig({
  project: "<project ref>",
  build: {
    extensions: [
      additionalFiles({ files: ["path/to/your/script.sh"] }),
      myCustomExtension(),
    ],
  },
});

This approach is based on the information provided in the Build extensions documentation and the additionalFiles extension documentation.

After setting this up, you should be able to run your bash script from within a task using the exec function, pointing to /app/scripts/script.sh.

#

Note that while there isn't a specific example of importing a bash script in the provided knowledge sources, this approach combines the concepts of adding additional files and using custom build layers to achieve what you're looking for.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: