Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare first version of the server #30

Merged
merged 10 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# flyctl launch added from .gitignore
**/.DS_Store
**/node_modules
**/coverage
**/.tmp
**/tmp
**/proto/build
dist
!drizzle/**/*.sql
**/.eslintcache
**/docs/api/html/*
**/test/fixtures/config/*.zip

# flyctl launch added from .husky/_/.gitignore
.husky/_/**/*
fly.toml
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules/
/*.tsbuildinfo
/*.tsbuildinfo

/dist/
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Best practices from https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/

ARG NODE_VERSION=20.17.0

# --------------> The build image__
FROM node:${NODE_VERSION} AS build
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
RUN npm ci --omit=dev

# --------------> The production image__
FROM node:${NODE_VERSION}-bullseye-slim

ENV NODE_ENV production
ENV PORT 8080
EXPOSE 8080
COPY --from=build /usr/bin/dumb-init /usr/bin/dumb-init
USER node
WORKDIR /usr/src/app
COPY --chown=node:node --from=build /usr/src/app/node_modules /usr/src/app/node_modules
COPY --chown=node:node . /usr/src/app
CMD ["dumb-init", "npm", "start"]
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# @comapeo/cloud

A self-hosted cloud server for CoMapeo.

## Deploying CoMapeo Cloud

CoMapeo Cloud comes with a [`Dockerfile`](./Dockerfile) that can be used to build a Docker image. This image can be used to deploy CoMapeo Cloud on a server.

Server configuration is done using environment variables. The following environment variables are available:

| Environment Variable | Required | Description | Default Value |
| --------------------- | -------- | -------------------------------------------------------------------- | ---------------- |
| `SERVER_BEARER_TOKEN` | Yes | Token for authenticating API requests. Should be large random string | |
| `PORT` | No | Port on which the server runs | `8080` |
| `SERVER_NAME` | No | Friendly server name, seen by users when adding server | `CoMapeo Server` |
| `ALLOWED_PROJECTS` | No | Number of projects allowed to register with the server | `1` |
| `STORAGE_DIR` | No | Path for storing app & project data | `$CWD/data` |

### Deploying with fly.io

CoMapeo Cloud can be deployed on [fly.io](https://fly.io) using the following steps:

1. Install the flyctl CLI tool by following the instructions [here](https://fly.io/docs/getting-started/installing-flyctl/).
2. Create a new app on fly.io by running `flyctl apps create`, take a note of the app name.
3. Set the SERVER_BEARER_TOKEN secret via:
```sh
flyctl secrets set SERVER_BEARER_TOKEN=<your-secret> --app <your-app-name>
```
4. Deploy the app by running (optionally setting the `ALLOWED_PROJECTS` environment variable):
```sh
flyctl deploy --app <your-app-name> -e ALLOWED_PROJECTS=10
```
5. The app should now be running on fly.io. You can access it at `https://<your-app-name>.fly.dev`.

To destroy the app (delete all data and project invites), run:

> [!WARNING]
> This action is irreversible and will permanently delete all data associated with the app, and projects that have already added the server will no longer be able to sync with it.

```sh
flyctl destroy --app <your-app-name>
```
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default [
'prefer-spread': 'error',
radix: 'error',
'require-atomic-updates': 'error',
'require-await': 'error',
'require-unicode-regexp': 'error',
strict: 'error',
'symbol-description': 'error',
Expand Down
36 changes: 36 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# fly.toml app configuration file generated for comapeo-cloud on 2024-10-07T20:59:21+01:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'comapeo-cloud'
primary_region = 'iad'

[env]
STORAGE_DIR = '/data'

[build]

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = 'suspend'
auto_start_machines = true
min_machines_running = 0
max_machines_running = 1
processes = ['app']

[[http_service.checks]]
grace_period = "10s"
interval = "30s"
method = "GET"
timeout = "5s"
path = "/healthcheck"

[[vm]]
size = 'shared-cpu-1x'

[mounts]
source = "myapp_data"
destination = "/data"
snapshot_retention = 14
Loading