Skip to content

Commit

Permalink
Docker compose setup (#513)
Browse files Browse the repository at this point in the history
* fix password reset bug

* self hosted mode middleware changes on  pages

* fix lint

* wip: self hosted changes

* wip: self hosted frontend changes

* wip self hosted mode changes

* typo correction

* remove commented logic

* fix env variable names

* fix lint issues

* fix minor updates

* #445 Switched from single monolithic docker image to a docker-compose
 orchestrated network of services

* Automatically configures shared secret

* Working through some issues

* Use local file storage

* Moved the dockerfiles

* Fixed some issues when building from clean

* Corrected workflow

* Hopefully schedules everything correctly now

* Prep storage for worker process as well

* .env files are required

* Pinned dependency versions

* Disable self hosted in the client as well

* Removed double defaulting logic

* Using regexs is more succinct

* Added FRONT_URL environment variable

* Merge 236e4-self-hosted-mode-changes

* Improve inital user setup

* Finalized the new docker-compose setup

* Fix back-end formatting issues

---------

Co-authored-by: Frank <[email protected]>
Co-authored-by: Don Benjamin <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent 6b13f95 commit 3280e38
Show file tree
Hide file tree
Showing 49 changed files with 9,887 additions and 7,166 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.git
/Dockerfile
/data
\.env
16 changes: 2 additions & 14 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,19 @@ APP_NAME="OpnForm"
APP_ENV=local
APP_KEY=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://localhost

LOG_CHANNEL=errorlog
LOG_LEVEL=debug

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=postgres

FILESYSTEM_DRIVER=s3
FILESYSTEM_DISK=s3
FILESYSTEM_DRIVER=local

BROADCAST_CONNECTION=log
CACHE_STORE=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=log
MAIL_HOST=
MAIL_PORT=
Expand Down Expand Up @@ -57,3 +44,4 @@ MUX_WORKSPACE_ID=
MUX_API_TOKEN=

OPEN_AI_API_KEY=
SELF_HOSTED=true
25 changes: 18 additions & 7 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Get tag name
run: ( echo "TAG_NAME=${GITHUB_REF#refs/*/v}"; echo "DOCKER_REPO=${{secrets.DOCKER_REPO}}") >> $GITHUB_ENV
run: |
(
echo "TAG_NAME=${GITHUB_REF#refs/*/v}";
echo "DOCKER_UI_REPO=${{secrets.DOCKER_UI_REPO}}"
echo "DOCKER_API_REPO=${{secrets.DOCKER_API_REPO}}"
) >> $GITHUB_ENV
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
run: docker login -u "${{ secrets.DOCKER_USERNAME }}" -p "${{ secrets.DOCKER_ACCESS_TOKEN }}"

- name: Build docker image
run: docker build . -t $DOCKER_REPO:latest -t $DOCKER_REPO:$TAG_NAME

- name: Push Docker image
run: docker push $DOCKER_REPO:latest && docker push $DOCKER_REPO:$TAG_NAME

- name: Build docker api image
run: docker build -f docker/Dockerfile.api . -t $DOCKER_API_REPO:latest -t $DOCKER_API_REPO:$TAG_NAME

- name: Build docker ui image
run: docker build -f docker/Dockerfile.client . -t $DOCKER_UI_REPO:latest -t $DOCKER_UI_REPO:$TAG_NAME

- name: Push Docker api image
run: docker push $DOCKER_API_REPO:latest && docker push $DOCKER_API_REPO:$TAG_NAME

- name: Push Docker ui image
run: docker push $DOCKER_UI_REPO:latest && docker push $DOCKER_UI_REPO:$TAG_NAME
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public/.DS_Store
.env.production
.env.staging
_ide_helper.php

docker-compose.override.yml
/.make.*
98 changes: 0 additions & 98 deletions Dockerfile

This file was deleted.

130 changes: 63 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<a href="https://github.com/JhumanJ/OpnForm/stargazers"><img src="https://img.shields.io/github/stars/JhumanJ/OpnForm" alt="Github Stars"></a>
</a>
<a href="https://github.com/JhumanJ/OpnForm/pulse"><img src="https://img.shields.io/github/commit-activity/m/JhumanJ/OpnForm" alt="Commits per month"></a>
<a href="https://hub.docker.com/r/jhumanj/opnform">
<img src="https://img.shields.io/docker/pulls/jhumanj/opnform">
<a href="https://hub.docker.com/r/jhumanj/opnform-api">
<img src="https://img.shields.io/docker/pulls/jhumanj/opnform-api">
</a>
<a href="https://github.com/JhumanJ/OpnForm/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-AGPLv3-purple" alt="License">
<a href="https://github.com/JhumanJ/OpnForm/issues/new"><img src="https://img.shields.io/badge/Report a bug-Github-%231F80C0" alt="Report a bug"></a>
Expand Down Expand Up @@ -66,94 +66,90 @@ It takes 1 minute to try out the builder for free. You'll have high availability

## Installation

### Docker Installation 🐳

### Docker installation 🐳
OpnForm can be easily set up using Docker. Pre-built images are available on Docker Hub, which is the recommended method for most users.

This can be built and run locally but is also hosted publicly on docker hub at `jhumanj/opnform` and is generally best run directly from there.
#### Prerequisites
- Docker
- Docker Compose

#### Running from docker hub
#### Quick Start

```
docker run --name opnform -v $PWD/my-opnform-data:/persist -p 80:80 jhumanj/opnform
```

You should now be able to access the application by visiting http://localhost in a web browser.

> 👀 **Server Deployment**: If you are deploying OpnForm on a server (not locally), then you will [need to use 2 .env files](https://github.com/JhumanJ/opnform?tab=readme-ov-file#using-custom-env-files) to configure the app URLs (`APP_URL` in `.env` and both `NUXT_PUBLIC_APP_URL` & `NUXT_PUBLIC_API_BASE` in `client/.env`).
1. Clone the repository:
```
git clone https://github.com/JhumanJ/OpnForm.git
cd OpnForm
```

2. Set up environment files:
```
cp .env.docker .env
cp client/.env.docker client/.env
```

The `-v` argument creates a local directory called `my-opnform-data` which will store your database and files so that your work is not lost when you restart the container.
3. Start the application:
```
docker-compose up -d
```

The `--name` argument names the running container so that you can refer back to it later, with e.g. `docker stop opnform`. You can use any name you'd like.
4. Access OpnForm at http://localhost

> 🌐 **Server Deployment Note**: When deploying to a server, configure the app URLs in both `.env` and `client/.env` files. Set `APP_URL` in `.env`, and both `NUXT_PUBLIC_APP_URL` & `NUXT_PUBLIC_API_BASE` in `client/.env`.
#### Using custom .env files
#### Customization

If you have custom env file you can use them like so:

Custom Laravel .env file:
```
docker run --name opnform -v $PWD/custom-laravel-env-file.env:/app/.env -v $PWD/my-opnform-data:/persist -p 80:80 jhumanj/opnform
```
- **Environment Variables**: Modify `.env` and `client/.env` files to customize your setup. For example, to enable email features, configure a [supported mail driver](https://laravel.com/docs/11.x/mail) in the `.env` file.

Custom Nuxt .env file:
```
docker run --name opnform -v $PWD/custom-nuxt-env-file.env:/app/client/.env -v $PWD/my-opnform-data:/persist -p 80:80 jhumanj/opnform
```
#### Upgrading

This would load load in the env file located at `my-custom-env-file.env`, note that if you are creating a .env file for use like this it's best to start from the `.env.docker` example file as there are slightly different defaults for the dockerized setup.
1. Check the upgrade instructions for your target version in the documentation.
2. Update your `docker-compose.yml` file if necessary.
3. Apply changes:
```
docker-compose up -d
```

#### Using a custom HTTP port
### Initial Login

To run on port 8080
After installation, use these credentials to access the admin panel:
- Email: `[email protected]`
- Password: `password`

```
docker run --name opnform -v $PWD/my-opnform-data:/persist -p 8080:80 jhumanj/opnform
```
⚠️ Change these credentials immediately after your first login.

#### Building a custom docker image
Note: Public registration is disabled in the self-hosted version. Use the admin account to invite additional users.

To build a custom docker image from your local source code use this command from the root of the source repository:
### Building from Source

```
docker build . -t my-docker-image-name
```
For development or customization, you can build the Docker images locally:

This should create a new docker image tagged `my-docker-image-name` which can be run as follows:
1. Build the images:
```
docker build -t opnform-ui:local -f docker/Dockerfile.client .
docker build -t opnform-api:local -f docker/Dockerfile.api .
```

```
docker run --name opnform -v $PWD/my-opnform-data:/persist -p 80:80 my-docker-image-name
2. Create a docker-compose override file:
```
cp docker-compose.override.yml.example docker-compose.override.yml
```

```

#### Upgrading docker installations

**Please consult the upgrade instructions for the latest opnform version**, e.g. if upgrading from v1 to v2 please check the v2 instructions as the process may change in future releases.

Normal upgrade procedure would be to stop the running container, back up your data directory (you will need this backup if you want to rollback to the old version) and then start a container running the new image with the same arguments.

e.g. if you're running from a specific opnform version with

```docker run --name opnform -v $PWD/my-opnform-data:/persist -p 80:80 jhumanj/opnform:1.0.0```

You could run:

```
# stop the running container
docker stop opnform
# backup the data directory
cp -r my-opnform-data my-opnform-backup
# start the new container
docker run --name opnform-2 -v $PWD/my-opnform-data:/persist -p 80:80 jhumanj/opnform:2.0.0
```

Then if everything is running smoothly you can delete the old container with:
```
docker rm opnform
```
Edit the `docker-compose.override.yml` file to use your locally built images:
```yaml
services:
api:
image: opnform-api:local
ui:
image: opnform-ui:local
```
If you haven't specified a version e.g. if you are using the image `jhumanj/opnform` or `jhumanj/opnform:latest` you will need to run `docker pull jhumanj/opnform` or `docker pull jhumanj/opnform:latest` before starting the new container.
3. Start the application:
```
docker-compose up -d
```

This method allows you to make changes to the source code and rebuild the images as needed.

### Using Laravel Valet
This section explains how to get started locally with the project. It's most likely relevant if you're trying to work on the project.
Expand Down
Loading

0 comments on commit 3280e38

Please sign in to comment.