Skip to content

Commit

Permalink
feat: add koyeb preset (#1248)
Browse files Browse the repository at this point in the history
  • Loading branch information
imchairmanm authored Feb 27, 2024
1 parent fcc4918 commit 508cfc6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
93 changes: 93 additions & 0 deletions docs/2.deploy/20.providers/koyeb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Koyeb

> Deploy Nitro apps to Koyeb.
**Preset:** `koyeb`

:read-more{to="https://www.koyeb.com"}

## Using the control panel


1. In the [Koyeb control panel](https://app.koyeb.com/), click **Create App**.
2. Choose **GitHub** as your deployment method.
3. Choose the GitHub **repository** and **branch** containing your application code.
4. Name your Service.
5. If you did not add a `start` command to your `package.json` file, under the **Build and deployment settings**, toggle the override switch associated with the run command field. In the **Run command** field, enter:
```bash
node .output/server/index.mjs`
```
6. In the **Advanced** section, click **Add Variable** and add a `NITRO_PRESET` variable set to `koyeb`.
7. Name the App.
8. Click the **Deploy** button.

## Using the Koyeb CLI

1. Follow the instructions targeting your operating system to [install the Koyeb CLI client](https://www.koyeb.com/docs/cli/installation) with an installer. Alternatively, visit the [releases page on GitHub](https://github.com/koyeb/koyeb-cli/releases) to directly download required files.
2. Create a Koyeb API access token by visiting the [API settings for your organization](https://app.koyeb.com/settings/api) in the Koyeb control panel.
3. Log into your account with the Koyeb CLI by typing:
```bash
koyeb login
```
Paste your API credentials when prompted.
4. Deploy your Nitro application from a GitHub repository with the following command. Be sure to substitute your own values for `<APPLICATION_NAME>`, `<YOUR_GITHUB_USERNAME>`, and `<YOUR_REPOSITORY_NAME>`:
```bash
koyeb app init <APPLICATION_NAME> \
--git github.com/<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME> \
--git-branch main \
--git-run-command "node .output/server/index.mjs" \
--ports 3000:http \
--routes /:3000 \
--env PORT=3000 \
--env NITRO_PRESET=koyeb
```

## Using a docker container

1. Create a `.dockerignore` file in the root of your project and add the following lines:

```docker
Dockerfile
.dockerignore
node_modules
npm-debug.log
.nitro
.output
.git
dist
README.md
```

2. Add a `Dockerfile` to the root of your project:

```ini
FROM node:18-alpine AS base
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build && npm cache clean --force
FROM base AS runner
WORKDIR /app
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nitro
COPY --from=builder /app .
USER nitro
EXPOSE 3000
ENV PORT 3000
CMD ["npm", "run", "start"]
```

The Dockerfile above provides the minimum requirements to run the Nitro application. You can easily extend it depending on your needs.
You will then need to push your Docker image to a registry. You can use [Docker Hub](https://hub.docker.com/) or [GitHub Container Registry](https://docs.github.com/en/packages/guides/about-github-container-registry) for example.
In the Koyeb control panel, use the image and the tag field to specify the image you want to deploy.
You can also use the [Koyeb CLI](https://www.koyeb.com/docs/build-and-deploy/cli/installation)
Refer to the Koyeb [Docker documentation](https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images) for more information.
1 change: 1 addition & 0 deletions src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { cleavr } from "./cleavr";
export { layer0 } from "./layer0";
export { flightControl } from "./flightcontrol";
export { lagon } from "./lagon";
export { koyeb } from "./koyeb";
export { iis, iisHandler, iisNode } from "./iis";
export { _static as static } from "./static";
export { githubPages } from "./github-pages";
Expand Down
5 changes: 5 additions & 0 deletions src/presets/koyeb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineNitroPreset } from "../preset";

export const koyeb = defineNitroPreset({
extends: "node-server",
});

0 comments on commit 508cfc6

Please sign in to comment.