Skip to content

Commit

Permalink
Merge pull request #492 from hpi-studyu/issue/491-feat-studyu-selfhos…
Browse files Browse the repository at this point in the history
…t-cli

Issue/491 feat studyu selfhost cli
  • Loading branch information
johannesvedder authored Aug 8, 2023
2 parents 3f3c427 + 9d0cd94 commit 3f9f4a9
Show file tree
Hide file tree
Showing 13 changed files with 684 additions and 86 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Custom
backup/
docker/.studyu_config

# Miscellaneous
*.class
*.log
Expand Down
31 changes: 0 additions & 31 deletions .meta/kitty-dev

This file was deleted.

159 changes: 127 additions & 32 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,52 @@ You will need to install Docker to be able to run any of the following scripts.
Make sure you have [Docker](https://docker.com) installed and configured by
running `docker -v`.

For HPI VMs, [this
script](https://gist.github.com/johannesvedder/0fafcbeabe8e069f96085bfedaebd9d0)
For HPI VMs,
[this script](https://gist.github.com/johannesvedder/0fafcbeabe8e069f96085bfedaebd9d0)
can be used to install and setup docker.

All the following commands are meant to be run from this directory, i.e. the
`docker/` directory of the root repository, unless otherwise specified.

## Quick Start with the StudyU CLI

To get started quickly, run the StudyU CLI. It will interactively guide you
through the setup process. The CLI is a wrapper around the docker-compose
commands described in the following sections. It is located in the root
directory of the repository and can be run with `./studyu-cli.sh`.

During the configuration of the CLI, you will be asked to define the components
you want to run. The following components are available:

- `supabase-db`: A PostgreSQL database for Supabase
- `supabase`: A self-hosted Supabase instance (needs `supabase-db`)
- `proxy`: Nginx reverse proxy to access Supabase if no StudyU component is running
- `studyu-app`: The StudyU App (includes `proxy`)
- `studyu-designer`: The StudyU Designer (includes `proxy`)

A minimal full setup would be `supabase-db`, `supabase`, `studyu-app` and
`studyu-designer`. If you only want to run a self-hosted Supabase
instance and deploy StudyU elsewhere, you can choose `proxy` instead of
`studyu-app` and `studyu-designer` to access Supabase Studio. Otherwise, if you
only want to run the StudyU App and the StudyU Designer and not self-host Supabase,
you can choose the respective component without `supabase-db` and `supabase`.
Have a look into the use cases below for more details on the different
configurations.

```bash
chmod +x studyu-cli.sh
./studyu-cli.sh config
./studyu-cli.sh start
```

The CLI offers multiple commands to manage your StudyU instance. Run
`./studyu-cli.sh --help` to see all available commands.

After making changes to environment files such as `supabase/.env` or
`flutter_common/lib/envs/.env.*`, a rebuild of the StudyU components might be
necessary. You can run `./studyu-cli.sh delete` for this. Be sure to only remove
the containers and images and not the volumes.

## Overview

StudyU can be operated with docker in different ways. The setup is designed to
Expand All @@ -25,25 +67,44 @@ Choose this method if you do not want to setup your own Supabase instance, but
only launch StudyU applications with docker. This might be useful if you want to
run StudyU after you made changes to the codebase.

You can either use the StudyU CLI or manually run the docker-compose commands.

### StudyU CLI

Run the StudyU CLI with `./studyu-cli.sh config` and choose the following packages:

- `studyu-app`
- `studyu-designer`

Then run `./studyu-cli.sh start` to start the StudyU App and the StudyU Designer.

Read on at [Futher customize the setup](#further-customize-the-setup) to learn
how to change the default database and ports.

### Manual Docker Compose steps

To start both the StudyU App and the StudyU Designer, simply run `docker compose
up`.
-f studyu/docker-compose.yml up`.

If you only want to start a single StudyU application run `docker compose -f
docker-compose-{module} up`. Make sure to replace `{module}` with one of the
following:
studyu/docker-compose-{module} up`. Make sure to replace `{module}` with one of
the following:

- `app`: Start the StudyU App
- `designer`: Start the StudyU Designer
- `designer_legacy`: Start the outdated Designer v1 (not recommended)

### Further customize the setup

The default ports are 8080 for the [StudyU App](http://localhost:8080) and 8081
for the [StudyU Designer](http://localhost:8081).

If you want to use a different database, more steps are necessary. You can start
a managed Supabase project at [supabase.com](https://supabase.com) and link it
with your StudyU instance by replacing the values for `STUDYU_SUPABASE_URL` and
`STUDYU_SUPABASE_PUBLIC_ANON_KEY` in the file `.env.local`. Alternatively, you
can self-host Supabase on your own as explained in
By default the main StudyU database will be used. If you want to use a different
database, more steps are necessary. You can start a managed Supabase project at
[supabase.com](https://supabase.com) and link it with your StudyU instance by
replacing the values for `STUDYU_SUPABASE_URL` and
`STUDYU_SUPABASE_PUBLIC_ANON_KEY` in the file `flutter_common/lib/envs/.env.local`.
Alternatively, you can self-host Supabase on your own as explained in
[Use Case #2](#use-case-2-run-a-self-hosted-supabase-instance-together-with-studyu).

In order to run your StudyU instance under a custom domain or a different port,
Expand Down Expand Up @@ -94,17 +155,27 @@ Configuration](#advanced-configuration)**

### Run Supabase and StudyU

Make sure that you thoughtfully completed all the previous steps and then start
the following services:
Make sure that you thoughtfully completed all the previous steps. You can either
use the StudyU CLI or manually run the docker-compose commands.

StudyU CLI:

Run the StudyU CLI with `./studyu-cli.sh config` and choose the following packages:

In the directory `supabase`:
- `supabase-db`
- `supabase`
- `studyu-app`
- `studyu-designer`

- `docker compose -f docker-compose-db.yml up` (Start PostgreSQL)
- `docker compose up` (Start Supabase)
Then run `./studyu-cli.sh start`.

In the directory `docker`
Manual Docker Compose steps:

- `docker compose up` (Start StudyU App and StudyU Designer)
- `docker compose -f supabase/docker-compose-db.yml up` (Start PostgreSQL)
- `docker compose -f supabase/docker-compose.yml up` (Start Supabase)
- `docker compose -f studyu/docker-compose.yml up` (Start StudyU App and StudyU Designer)

Operation:

Open your local Supabase Studio instance on
[http://localhost:8082](http://localhost:8082) (default basic authentication
Expand Down Expand Up @@ -134,25 +205,36 @@ in *Supabase Machine* and running StudyU locally with Flutter.

On the machine where Supabase and PostgreSQL should be run, perform all the
Supabase related configuration steps described in [Configure](#configure) of Use
Case #2 (for local development, it is sufficient to copy the `.env.example` to
`.env` and leave everything else as is). However, this will not be sufficient to
access Supabase. Additionally, to the Supabase backend, a nginx reverse proxy,
will need to be started. This is further explained in [Some words about
nginx](#some-words-about-nginx).
Case #2 (for local development, it is sufficient to copy the `supabase/.env.example`
to `supabase/.env` and leave everything else as is). However, this will not be
sufficient to access Supabase. Additionally, to the Supabase backend, a nginx
reverse proxy, will need to be started. This is further explained in
[Some words about nginx](#some-words-about-nginx).

**BE AWARE THAT SUPABASE IS NOT SECURE BY DEFAULT. READ MORE AT [Advanced
Configuration](#advanced-configuration)**

Run the following services. In the directory `supabase`:
StudyU CLI:

Run the StudyU CLI with `./studyu-cli.sh config` and choose the following packages:

- `supabase-db`
- `supabase`
- `proxy`

Then run `./studyu-cli.sh start`.

- `docker compose -f docker-compose-db.yml up` (Start PostgreSQL)
- `docker compose up` (Start Supabase)
Manual Docker Compose steps:

In the directory `docker`:
Run the following services:

- `docker compose -f docker-compose-proxy.yml up` (Start the nginx reverse
- `docker compose -f supabase/docker-compose-db.yml up` (Start PostgreSQL)
- `docker compose -f supabase/docker-compose.yml up` (Start Supabase)
- `docker compose -f nginx/docker-compose-proxy.yml up` (Start the nginx reverse
proxy)

Operation:

The default ports are as follows:

- 8082 for [Supabase Studio](http://localhost:8082) (**INSECURE** username:
Expand All @@ -165,9 +247,20 @@ values with your custom ones in the file
`flutter_common/lib/envs/.env.local`. Make sure to set `STUDYU_SUPABASE_URL`
to the correct URL of the Supabase instace of your first machine.

Then run in the directory `docker`:
StudyU CLI:

Run the StudyU CLI with `./studyu-cli.sh config` and choose the following packages:

- `studyu-app`
- `studyu-designer`

Then run `./studyu-cli.sh start`.

- `docker compose up` (Start StudyU App and StudyU Designer)
Manual Docker Compose steps:

- `docker compose -f studyu/docker-compose.yml up` (Start StudyU App and StudyU Designer)

Operation:

The default ports are as follows:

Expand Down Expand Up @@ -197,7 +290,7 @@ To run flutter apps like StudyU in a web browser, a web server is necessary. We
have chosen to use nginx alpine for this task, since it features a very small
file size and can furthermore act as a reverse proxy. The configuration files
in the `nginx/conf.d/` directory are shipped together with each docker compose
file in the `/docker` directory. The nginx server serves various purposes.
file in the `studyu/` directory. The nginx server serves various purposes.

For the StudyU App and Designer (`nginx/conf.d/01_app.conf` and
`nginx/conf.d/02_designer.conf`), nginx makes sure that all requests to these
Expand Down Expand Up @@ -249,9 +342,11 @@ volume, but rather use specific postgres backup tools such as `pg_dump`.

All Supabase Storage data is stored in the docker volume `studyu-blob`.

Run the StudyU CLI with `./studyu-cli.sh backup` to backup the database.

## Update

TODO
Run the StudyU CLI with `./studyu-cli.sh update` to update the repository.

## Good to know

Expand All @@ -260,7 +355,7 @@ TODO
nginx. For this, get the name of the docker container with `docker ps`, and
then `sh` into the container with `docker exec -it <container name> sh` and
run `/usr/sbin/nginx -s reload` inside the container.
- After making changes to `docker-compose*.yml` files in the `docker/`
- After making changes to `docker-compose*.yml` files in the `studyu/`
directory, a rebuild of studyu is necessary. Run `docker compose up --build`.
- In order to stop docker containers from running press CTRL+C or run `docker
compose -p 'studyu' down --remove-orphans` and `docker compose -p 'supabase'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: '3'
name: 'studyu'
version: '3.8'
name: 'studyu_proxy'

networks:
default:
Expand All @@ -14,5 +14,5 @@ services:
- 8082:8082
# - 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d:ro
- ./nginx/.htpasswd:/etc/nginx/.htpasswd:ro
- ../nginx/conf.d:/etc/nginx/conf.d:ro
- ../nginx/.htpasswd:/etc/nginx/.htpasswd:ro
Loading

0 comments on commit 3f9f4a9

Please sign in to comment.