Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
211 changes: 11 additions & 200 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,210 +1,21 @@
# deploio-examples

This repository hosts example code for different languages and frameworks
supported by Deploio. More information can be found in the
This repository hosts example applications for different languages and frameworks
supported by [Deploio](https://docs.deplo.io/). More information can be found in the
[Deploio User Guides](https://docs.deplo.io/) or in the
[Nine Platform Reference](https://docs.nine.ch/docs/category/deploio-paas).

## Go
## How to build and deploy

```bash
nctl create application go \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=go
```
Deploio supports two approaches for building applications:

## Ruby on Rails
**Buildpacks** — Deploio automatically detects your language and framework and
builds the app without a Dockerfile. Two buildpack stacks are available:

This requires the `rails` command to be installed for the `SECRET_KEY_BASE`.
If you don't have it, any long random string will do (127+ chars).
- [`heroku-stack/`](heroku-stack/) — the default stack, using [Heroku Cloud Native Buildpacks](https://github.com/heroku/cnb-builder-images)
- [`paketo-stack/`](paketo-stack/) — uses [Paketo](https://paketo.io/) buildpacks; select it with `--buildpack-stack=paketo`

```bash
nctl create application rails \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=ruby/rails-basic \
--env=SECRET_KEY_BASE=$(rails secret)
```
**Dockerfile** — bring your own `Dockerfile` for full control over the build.
This approach is stack-independent:

### Ruby On Rails with ActiveStorage

Next to the basic Rails example, we also provide a Rails application that has ActiveStorage configured with
Deploio Object Storage.

Once deployed, you can head to the root page of the app and test the upload functionality. The example app supports
direct uploads from the browser (CORS configuration is required as below) and custom bucket hostnames
(DNS change required, see below).

```bash
# setup postgres database
nctl create postgresdatabase rails-active-storage-db --location=nine-es34 --wait
DATABASE_URL="$(nctl get postgresdatabase rails-active-storage-db --print-connection-string)"

# setup application
nctl create application rails-active-storage \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=ruby/rails-active-storage \
--env=SECRET_KEY_BASE=$(rails secret)\;DATABASE_URL=${DATABASE_URL}

# create bucket
nctl create bucket --location=nine-es34 rails-active-storage-bucket

# create bucket user
nctl create bucketuser --location=nine-es34 rails-active-storage-bucketuser

# grant bucket user read & write access to bucket
nctl update bucket rails-active-storage-bucket --permissions reader=rails-active-storage-bucketuser \
--permissions writer=rails-active-storage-bucketuser

# update application with object storage credentials
ACCESS_KEY="$(nctl get bucketuser rails-active-storage-bucketuser --print-credentials -o json | jq -r .s3_access_key)"
SECRET_KEY="$(nctl get bucketuser rails-active-storage-bucketuser --print-credentials -o json | jq -r .s3_secret_key)"
nctl update app rails-active-storage --env="S3_ACCESS_KEY=${ACCESS_KEY};S3_SECRET_KEY=${SECRET_KEY};S3_ENDPOINT=https://es34.objects.nineapis.ch;S3_BUCKET=rails-active-storage-bucket"

# optional: custom bucket hostnames
nctl update bucket rails-active-storage-bucket --custom-hostnames={S3_BUCKET_HOST}
nctl update app rails-active-storage --env="S3_BUCKET_HOST={S3_BUCKET_HOST}"
nctl get bucket rails-active-storage-bucket --output="yaml" # setup DNS

# CORS configuration for direct uploads from browser
# see https://guides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration
APP_HOST=$(nctl get app rails-active-storage -o json | jq -r ".status.atProvider.defaultURLs | first")
nctl update bucket rails-active-storage-bucket \
--cors origins=${APP_HOST} \
--cors allowed-headers=Content-Type,Content-MD5,Content-Disposition \
--cors response-headers=Content-Type,Content-MD5,Content-Disposition,ETag \
--cors max-age=3600
```

## Ruby - Sinatra on Falcon

```bash
nctl create app falcon-features-sinatra \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=ruby/falcon-sinatra
```

## Node.js

```bash
nctl create application nextjs \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=nodejs/nextjs \
--build-env=NODE_ENV="production" \
--env=NODE_ENV="production"
```

## PHP

A plain PHP application without a framework is provided at `php/plain`.
You can launch it with:

```bash
nctl create application php-plain \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=php/plain \
--build-env=BP_PHP_WEB_DIR=public \
--build-env=BP_COMPOSER_INSTALL_OPTIONS="--ignore-platform-reqs"
```

We also provide a Symfony sample application that makes use of all currently
available services on Deploio.
For the Symfony application to work, you will need to set up a database, a key
value store and object storage as explained in the
[tutorial](https://docs.deplo.io/quick-start/php/create_app).

```bash
nctl create application symfony \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=php/symfony\
--build-env=BP_PHP_WEB_DIR=public \
--build-env=BP_COMPOSER_INSTALL_OPTIONS="--ignore-platform-reqs --no-scripts -o"
```

## Python

The example provides a Django application which shows a random message on every
page reload. It uses a temporary local sqlite database. Please note that the
database will be recreated on every deployment or restart of the application
(all data will be lost), so it really just is useful for demonstration purposes.
For persistent data, please use a postgres or mysql external database. The
Django admin interface can be used to add messages. Just visit `https://<URL of
app>/admin` to access it and use the user credentials which you pass via the env
variables below to login.
Please also define the `SECRET_KEY` which is used to secure signed data and
should be kept secret.

```bash
nctl create application django-example \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=python/django \
--env=DJANGO_SU_NAME=admin \
--env=DJANGO_SU_EMAIL=admin@example.com \
--env=DJANGO_SU_PASSWORD=<INSERT A PASSWORD HERE> \
--env=SECRET_KEY=<VERY LONG RANDOM SECRET KEY>
```

## Static

For static sites we have two examples:

* just a plain `index.html`

```bash
nctl create application static-html \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=static/html
```

* a frontend react app built with `npm`

```bash
nctl create application static-react \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=static/react
```

## Dockerfile

With Dockerfile builds, Deploio can build any app that can be built using a
Dockerfile. To demonstrate this we have the following sample apps:

* a very basic Rust app:

```bash
nctl create application dockerfile-rust \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=dockerfile/rust \
--dockerfile
```
* a Java app based on Spring Boot that integrates with an [On-Demand Key-Value Store](https://docs.nine.ch/de/docs/on-demand-databases/on-demand-key-value-store/):

```bash
nctl create application dockerfile-java-kvs \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=dockerfile/java-kvs \
--env=KVS_HOST=<KEY-VALUE STORE HOSTNAME FROM COCKPIT OR NCTL> \
--env=KVS_PASSWORD=<KEY-VALUE STORE PASSWORD FROM COCKPIT OR NCTL> \
--env=KVS_SSL_ENABLED=true \
--dockerfile
```

See [dockerfile/java-kvs/README.md](dockerfile/java-kvs/README.md) for details and full setup instructions.

## KVS

This example uses an [On-Demand Key-Value Store](https://docs.nine.ch/de/docs/on-demand-databases/on-demand-key-value-store/).To get started, you'll need to first create a KVS instance - either through `nctl` or via the [Cockpit](https://cockpit.nine.ch/en) interface:

```bash
nctl create kvs <kvs-name>
```

Once your instance is ready you can create the app using the command below. You’ll need the instance’s connection details (FQDN and TOKEN), which can be retrieved using `nctl` or found in Cockpit under “Access Information.” For more details, see [Key-Value Store docs](https://docs.nine.ch/docs/on-demand-databases/on-demand-key-value-store#connecting):

```bash
export KVS_PASSWORD=$(nctl get kvs test --print-token)
export KVS_HOST=$(nctl get kvs test -o yaml | yq '.status.atProvider.fqdn')
nctl create application go \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=kvs \
--env="KVS_HOST=$KVS_HOST;KVS_PASSWORD=$KVS_PASSWORD"
```
- [`dockerfile/`](dockerfile/) — examples for languages not covered by buildpacks (e.g. Rust, Java)
32 changes: 32 additions & 0 deletions dockerfile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Dockerfile Examples

With Dockerfile builds, Deploio can build any app that can be containerized.
This approach is stack-independent — no buildpack is involved.

## Rust

A basic Rust web application:

```bash
nctl create application dockerfile-rust \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=dockerfile/rust \
--dockerfile
```

## Java (Spring Boot + KVS)

A Java app based on Spring Boot that integrates with an
[On-Demand Key-Value Store](https://docs.nine.ch/de/docs/on-demand-databases/on-demand-key-value-store/):

```bash
nctl create application dockerfile-java-kvs \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=dockerfile/java-kvs \
--env=KVS_HOST=<KEY-VALUE STORE HOSTNAME FROM COCKPIT OR NCTL> \
--env=KVS_PASSWORD=<KEY-VALUE STORE PASSWORD FROM COCKPIT OR NCTL> \
--env=KVS_SSL_ENABLED=true \
--dockerfile
```

See [java-kvs/README.md](java-kvs/README.md) for full setup instructions.
Loading