feat: Deployment update (#169)

* docs: add ubuntu setup guide

* feat: add docker ci

* feat: create admin frontend image

* feat: trigger push docker ci

* ci: multiple arch

* fix: build

* chore: update ci

* chore: update ci

* fix: build

* fix: build

* fix: test

* fix: database access

* fix: test

* fix: test

* chore: update

* chore: update
This commit is contained in:
Nathan.fooo 2023-11-16 00:29:18 +08:00 committed by GitHub
parent e94ea53ec6
commit 82bcb5e879
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 254 additions and 11 deletions

View file

@ -37,9 +37,14 @@ jobs:
sed -i 's/GOTRUE_SMTP_ADMIN_EMAIL=.*/GOTRUE_SMTP_ADMIN_EMAIL=${{ secrets.GOTRUE_SMTP_ADMIN_EMAIL }}/' .env
sed -i 's/GOTRUE_EXTERNAL_GOOGLE_ENABLED=.*/GOTRUE_EXTERNAL_GOOGLE_ENABLED=true/' .env
- name: Disable pull docker image
run: |
sed -i '/image: appflowyinc\/appflowy_cloud:/d' docker-compose.yml
sed -i '/image: appflowyinc\/admin_frontend:/d' docker-compose.yml
- name: Run Docker-Compose
run: |
docker compose up -d
docker compose up -d
- name: Run tests
run: |

View file

@ -0,0 +1,43 @@
name: Build and Push latest docker image
on:
push:
branches:
- 'main'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push appflowy-cloud
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: appflowyinc/appflowy_cloud:latest
- name: Build and push admin frontend
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: appflowyinc/admin_frontend:latest
- name: Logout from Docker Hub
if: always()
run: docker logout

10
Cargo.lock generated
View file

@ -2906,6 +2906,15 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "300.1.6+3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439fac53e092cd7442a3660c85dde4643ab3b5bd39040912388dcdabf6b88085"
dependencies = [
"cc",
]
[[package]]
name = "openssl-sys"
version = "0.9.93"
@ -2914,6 +2923,7 @@ checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d"
dependencies = [
"cc",
"libc",
"openssl-src",
"pkg-config",
"vcpkg",
]

View file

@ -16,7 +16,7 @@ actix-identity = "0.6.0"
actix-cors = "0.6.4"
actix-router = "0.5.1"
actix-session = { version = "0.8", features = ["redis-rs-tls-session"] }
openssl = { version = "0.10.45" }
openssl = { version = "0.10.45", features = ["vendored"] }
# serde
serde_json.workspace = true

142
doc/EC2_GUIDE.md Normal file
View file

@ -0,0 +1,142 @@
## Create an EC2 Instance
To create a default EC2 instance on AWS, you can follow these steps:
1. Open the Amazon EC2 console at [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/).
2. In the navigation bar at the top of the screen, the current AWS Region is displayed. Select a Region in which to launch the instance. This is important because some Amazon EC2 resources can be shared between Regions, while others cannot.
3. From the Amazon EC2 console dashboard, choose "Launch instance."
4. (Optional) Under "Name and tags," for Name, enter a descriptive name for your instance.
5. Under "Application and OS Images (Amazon Machine Image)," choose "Quick Start," and then choose the ubuntu.
6. Under "Key pair (login)," for "Key pair name," choose an existing key pair or create a new one.
7. In the Summary panel, choose "Launch instance"
## Install Docker on EC2 Ubuntu
To install Docker on an Ubuntu server hosted on AWS, you typically follow these steps:
Add your user to the Docker group**: This lets your user run Docker commands without `sudo`. Run the following command to add your user to the Docker group:
```bash
sudo usermod -aG docker ${USER}
```
1. Update your existing list of packages:
```bash
sudo apt update
```
2. Install prerequisite packages which let `apt` use packages over HTTPS:
```bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common
```
3. Add the GPG key for the official Docker repository to your system:
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
4. Add the Docker repository to APT sources:
```bash
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
```
5. Update the package database with the Docker packages from the newly added repo:
```bash
sudo apt update
```
6. Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
```bash
apt-cache policy docker-ce
```
7. Finally, install Docker:
```bash
sudo apt install docker-ce
```
8. Check that Docker is running:
```bash
sudo systemctl status docker
```
Add your user to the Docker group, which will allow you to run Docker commands without `sudo`:
```bash
sudo usermod -aG docker ${USER}
```
## Install AppFlowy-Cloud on EC2 Ubuntu
To install AppFlowy-Cloud on an EC2 Ubuntu instance, here's a streamlined guide:
1. **Clone the AppFlowy-Cloud Repository**:
Access your EC2 instance via SSH and execute the following commands to clone the AppFlowy-Cloud repository and navigate into the directory:
```bash
git clone https://github.com/AppFlowy-IO/AppFlowy-Cloud
cd AppFlowy-Cloud
```
2. **Prepare the Configuration File**:
Create a `.env` file from the provided template:
```bash
cp dev.env .env
```
3. **Configure Gotrue Mailer**:
Edit the `.env` file to set up the mailer for auto-confirmation:
```bash
echo "GOTRUE_MAILER_AUTOCONFIRM=true" >> .env
```
4. **Customize `.env` Settings**:
Open the `.env` file to replace placeholders with your instance details:
```bash
vim .env
```
(Here, replace placeholders with the actual IP or hostname of your EC2 instance.)
5. **Authentication Setup**:
Consult the [Authentication documentation](./AUTHENTICATION.md) for instructions on setting up the authentication service.
6. **Start AppFlowy**:
Use Docker to launch the AppFlowy services:
```bash
docker-compose up -d
```
7. **Check Service Status**:
Confirm that the services have started successfully:
```bash
docker ps -a
```
Make sure to review and follow the authentication guide closely, adjusting the `.env` file as necessary for your specific setup.
## Helpful Docker Commands
Be careful when running these commands. They can be destructive.
1. **Remove all containers in Docker**:
```bash
docker rm -f $(sudo docker ps -a)
```
2. **Restart the Docker service**: Sometimes, the Docker daemon might be in a state that prevents access. Restarting it can resolve the issue:
```bash
sudo systemctl restart docker
```
3. **Clean up everything except volumes**:
```bash
docker system prune -af
```
4. **Remove volumes**:
```bash
docker system prune -af --volumes
```

26
doc/LOCAL_BUILD.md Normal file
View file

@ -0,0 +1,26 @@
# To build a multi-architecture Docker image
Docker's buildx tool, which is a part of Docker BuildKit. This tool allows you to create images for different platforms from a single build command. Here's a basic rundown of the steps:
1. **Enable experimental features** by setting `"experimental": "enabled"` in your Docker configuration file (`~/.docker/config.json`).
2. **Install QEMU** on your macOS to emulate different architectures:
```sh
brew install qemu
```
3. **Create a new builder** that enables buildx and specify the platforms you want to target:
```sh
docker buildx create --name mybuilder --use
```
4. **Inspect the builder** to ensure it's correctly configured and can build for the target platforms:
```sh
docker buildx inspect mybuilder --bootstrap
```
5. **Build and push the image** to Docker Hub (or another registry) for the desired platforms using the `--platform` flag:
```sh
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t <username>/myimage:latest --push .
```

View file

@ -10,18 +10,25 @@ we recommend using cloud compute services (as your host server) such as
- Minimum 2GB Ram (4GB Recommended)
- Ports 80/443 available
## Software Requirements
- [docker compose](https://docs.docker.com/compose)
This is needed be installed in your host server
- We recommend using approach as proposed by offical docker website: [Install Docker Engine](https://docs.docker.com/engine/install/)
Ensure you have Docker Compose installed on your host server. Follow the official guidelines for a reliable setup:
- **Docker Compose:** Install it as per the [official documentation](https://docs.docker.com/compose/install/).
- **Docker Engine:** We suggest adhering to the instructions provided by Docker for [installing Docker Engine](https://docs.docker.com/engine/install/).
> **Note for AWS Users:** Here is a step by step guide to self host AppFlowy Cloud on AWS EC2 instance: [EC2 Guide](./EC2_GUIDE.md)
## Steps
### 1. Getting source files
- Clone this repository into your host server and `cd` into it
```bash
git clone https://github.com/AppFlowy-IO/AppFlowy-Cloud`
cd AppFlowy-Cloud`
git clone https://github.com/AppFlowy-IO/AppFlowy-Cloud
cd AppFlowy-Cloud
```
### 2. Preparing the configuration
@ -80,9 +87,12 @@ AWS_S3_BUCKET=appflowy
AWS_REGION=us-east-1 # This option only applicable for AWS S3
```
For authentication, please read the [Authentication](./AUTHENTICATION.md) for more details.
For authentication details, refer to the [Authentication](./AUTHENTICATION.md) documentation. You will need to update the
redirect URI to match your host server's public IP or hostname, such as `http://<your-host-server-public-ip-or-hostname>/callback`.
If using localhost, then just keep the default value.
```bash
GOTRUE_EXTERNAL_GOOGLE_ENABLED=false
GOTRUE_EXTERNAL_GOOGLE_ENABLED=true
GOTRUE_EXTERNAL_GOOGLE_CLIENT_ID=
GOTRUE_EXTERNAL_GOOGLE_SECRET=
GOTRUE_EXTERNAL_GOOGLE_REDIRECT_URI=http://localhost:9998/callback
@ -103,7 +113,8 @@ GOTRUE_EXTERNAL_DISCORD_REDIRECT_URI=http://localhost:9998/callback
### 3. Running the services
### Start and run AppFlowy-Cloud
- The following command will build and start the AppFlowy-Cloud
- The following command will build and start the AppFlowy-Cloud.
```bash
docker compose up -d
```
@ -112,6 +123,11 @@ docker compose up -d
docker ps -a
```
> When using the `docker compose up -d` command without specifying a tag, Docker Compose will pull the `latest`
tag for the `appflowy_cloud` and `admin_frontend` images from Docker Hub by default. If you've set the `BACKEND_VERSION`
environment variable, it will pull the specified version instead. If `BACKEND_VERSION` is not set, Docker Compose
defaults to using the `latest` tag.
### 4. Reconfiguring and redeployment
- It is very common to reconfigure and restart. To do so, simply edit the `.env` and do `docker compose up -d` again

View file

@ -149,7 +149,7 @@ services:
build:
context: .
dockerfile: Dockerfile
image: appflowy_cloud:${BACKEND_VERSION:-latest}
image: appflowyinc/appflowy_cloud:${BACKEND_VERSION:-latest}
depends_on:
- redis
- postgres
@ -162,6 +162,7 @@ services:
build:
context: .
dockerfile: ./admin_frontend/Dockerfile
image: appflowyinc/admin_frontend:${BACKEND_VERSION:-latest}
depends_on:
- gotrue
ports: