diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7e4a7f2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +*.iml +gen +.idea +*.md +.gitignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..596a5a5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +on: + push: + branches: [ main ] + +jobs: + package: + name: Build container images + runs-on: ubuntu-22.04 + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v4 + id: meta + with: + images: ghcr.io/${{ github.repository }} + - uses: docker/build-push-action@v3 + with: + context: . + push: true + file: Dockerfile + platforms: linux/amd64, linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..43530a6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM golang:1.19 as build +WORKDIR /build +COPY . . +RUN go build -o alpha main.go + +FROM scratch +COPY --from=build /build/alpha ./alpha +ENTRYPOINT ["alpha"] \ No newline at end of file diff --git a/docs/functions/node.md b/docs/functions/node.md new file mode 100644 index 0000000..c7ec9f3 --- /dev/null +++ b/docs/functions/node.md @@ -0,0 +1,27 @@ +# Create an Alpha-compliant Node.js function + +This guide will help you to set up your first Node.js function and execute it through Alpha. + +## Requirements + +- **Git repository** to host your function code (or similar, you will simply need something where you can store files and download them) + +## Create the function + +Once you've cloned / created your git repository, open it locally into your favourite code editor, and create an **index.js** file inside with the following placeholder content : + +> **The name of the file must be exactly `index.js`**. + +```javascript +exports.handler = function (ctx, params) { + ctx.logger.log("Hello from my first JS function !") + + let name = params["name"] || "world"; + return { message: `Hello ${name} !`}; +}; +``` + +- First, we export a function called **handler**. The name, like the file name, is important and can't be changed for now. +- Your function takes 2 parameters : `ctx` and `params`. `ctx` is an object provided by the runtime that contains helpers like logger. `params` is simply a Javascript object that contains the variables given to the function. +- The `return` statement at the end MUST return a valid JSON object representation. +