From ab1c674fb86016d5e1bbe6ce309278ed2ed614a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=80=81=E5=91=A8=E9=83=A8=E8=90=BD?=
 <laozhoubuluo@gmail.com>
Date: Mon, 4 Mar 2024 17:09:59 +0800
Subject: [PATCH] change dir structure, add docs, download by git

---
 dev/docker-dbonly/README.md                   | 13 +++++++++
 .../docker-compose.yml}                       |  0
 dev/{ => docker-dbonly}/install.sql           |  0
 dev/docker/README.md                          | 28 ++++++++++++++++++
 dev/{ => docker}/docker-compose.yml           |  0
 dev/{ => docker}/docker-entrypoint.sh         | 11 +++----
 docs/development.md                           | 29 ++++---------------
 scripts/dev-down.mjs                          |  6 +---
 scripts/dev-up.mjs                            |  7 +----
 9 files changed, 54 insertions(+), 40 deletions(-)
 create mode 100644 dev/docker-dbonly/README.md
 rename dev/{docker-compose-dbonly.yml => docker-dbonly/docker-compose.yml} (100%)
 rename dev/{ => docker-dbonly}/install.sql (100%)
 create mode 100644 dev/docker/README.md
 rename dev/{ => docker}/docker-compose.yml (100%)
 rename dev/{ => docker}/docker-entrypoint.sh (82%)

diff --git a/dev/docker-dbonly/README.md b/dev/docker-dbonly/README.md
new file mode 100644
index 0000000000..46802e639f
--- /dev/null
+++ b/dev/docker-dbonly/README.md
@@ -0,0 +1,13 @@
+## Containerized Database Environment
+
+The Firefish repo comes with containerized database environment to help make development!
+
+## Prerequisites
+
+- Latest [Docker](https://docs.docker.com/get-docker/) installation
+    - Alternatively, you can use [Podman](https://podman.io/docs/installation) and [Podman Compose](https://github.com/containers/podman-compose).
+
+## Start up the environment
+
+1. Run `git clone https://firefish.dev/firefish/firefish.git && cd firefish` to fetch needed files.
+1. Using the scripts located in scripts folder to make the development environment running.
diff --git a/dev/docker-compose-dbonly.yml b/dev/docker-dbonly/docker-compose.yml
similarity index 100%
rename from dev/docker-compose-dbonly.yml
rename to dev/docker-dbonly/docker-compose.yml
diff --git a/dev/install.sql b/dev/docker-dbonly/install.sql
similarity index 100%
rename from dev/install.sql
rename to dev/docker-dbonly/install.sql
diff --git a/dev/docker/README.md b/dev/docker/README.md
new file mode 100644
index 0000000000..79288c12b2
--- /dev/null
+++ b/dev/docker/README.md
@@ -0,0 +1,28 @@
+# Containerized Environment
+
+The Firefish repo comes with a new containerized environment to help make development!
+
+## Prerequisites
+
+- Latest [Docker](https://docs.docker.com/get-docker/) installation
+    - Alternatively, you can use [Podman](https://podman.io/docs/installation) and [Podman Compose](https://github.com/containers/podman-compose).
+- The following ports are not in use
+    - 3030
+    - 25432
+    - 26379
+
+## Start up the environment
+
+1. Download the [`dev/docker` directory](https://firefish.dev/firefish/firefish/-/tree/develop/dev/docker) and execute `chmod +x docker-entrypoint.sh`.
+    - Alternatively, you can manually run `git clone https://firefish.dev/firefish/firefish.git && cd firefish` to fetch needed files, or let the script take care of itself.
+1. Open `docker-compose.yml` and set `URL` to the URL you want to use (or leave it to `http://localhost:3030`).
+1. Run `docker compose up`. This will build the environment, dependencies and prepare the needed config files.
+    - If you use Podman, you should run `podman-compose up` instead.
+1. Wait until the following message shows up.
+    ```
+    DONE *  [core boot]     All workers started
+    DONE *  [core boot]     Now listening on port 3030 on https://your_firefish_url.example.com
+    ```
+1. A fresh Firefish environment is created on the URL you have set!
+
+When you want to restart the dev server, you just need to terminate the process (a.k.a. press `Ctrl+C`) and run `docker compose up` again.
diff --git a/dev/docker-compose.yml b/dev/docker/docker-compose.yml
similarity index 100%
rename from dev/docker-compose.yml
rename to dev/docker/docker-compose.yml
diff --git a/dev/docker-entrypoint.sh b/dev/docker/docker-entrypoint.sh
similarity index 82%
rename from dev/docker-entrypoint.sh
rename to dev/docker/docker-entrypoint.sh
index 541c304ea6..2a5303cb48 100755
--- a/dev/docker-entrypoint.sh
+++ b/dev/docker/docker-entrypoint.sh
@@ -8,24 +8,25 @@ if [ ! -f '/.firefish_env_initialized' ]; then
 
 	# Install compilation dependencies
 	apt-get update
-	DEBIAN_FRONTEND='noninteractive' apt-get install -y --no-install-recommends curl build-essential ca-certificates python3 postgresql-client-15
+	DEBIAN_FRONTEND='noninteractive' apt-get install -y --no-install-recommends curl build-essential ca-certificates python3 postgresql-client-15 git
 	curl -vvv --proto '=https' --tlsv1.2 --show-error --fail https://sh.rustup.rs | sh -s -- -y
 
 	# Add Cargo PATH
 	PATH="/root/.cargo/bin:${PATH}"
 
+	# If Firefish not exist
 	if [ ! -f '/firefish/README.md' ]; then
 
-		# Download Firefish and decompress
-		curl -vvv -O --proto '=https' --tlsv1.2 --show-error --fail https://firefish.dev/firefish/firefish/-/archive/develop/firefish-develop.tar.bz2
-		tar -xjvf firefish-develop.tar.bz2 --strip-components 1 -C /firefish
+		# Clone Firefish
+		cd /
+		git clone -v https://firefish.dev/firefish/firefish.git
 
 		# Configuring a new server
 		cd /firefish
 		cp .config/devenv.yml .config/default.yml
 
 		URL="$(echo "${URL}" | sed 's#/#\\/#g')"
-		sed -i'.bak' "s/http:\/\/localhost:3030/${URL}/" .config/default.yml 
+		sed -i'.bak' "s/http:\/\/localhost:3030/${URL}/" .config/default.yml
 
 	fi
 
diff --git a/docs/development.md b/docs/development.md
index 64fe517b39..0ff66c4970 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -1,30 +1,11 @@
 # Firefish Developer Docs
 
+We support multiple methods to build a development environment, and you can choose the method you like.
+
 ## Containerized Environment
 
-The Firefish repo comes with a new containerized environment to help make development!
+You can find documentation at [Here](../dev/docker/README.md).
 
-### Prerequisites
+## Containerized Database Environment
 
-- Latest [Docker](https://docs.docker.com/get-docker/) installation
-    - Alternatively, you can use [Podman](https://podman.io/docs/installation) and [Podman Compose](https://github.com/containers/podman-compose).
-- The following ports are not in use
-    - 3030
-    - 25432
-    - 26379
-
-### Start up the environment
-
-1. Download the [`dev` directory](https://firefish.dev/firefish/firefish/-/tree/develop/dev) and execute `chmod +x dev/docker-entrypoint.sh`.
-    - Alternatively, you can just run `git clone https://firefish.dev/firefish/firefish.git && cd firefish` to fetch needed files (it clones the entire repository, though).
-1. Open `dev/docker-compose.yml` and set `URL` to the URL you want to use (or leave it to `http://localhost:3030`).
-1. Run `docker compose --file dev/docker-compose.yml up`. This will build the environment, dependencies and prepare the needed config files.
-    - If you use Podman, you should run `podman-compose --file dev/docker-compose.yml up` instead.
-1. Wait until the following message shows up.
-    ```
-    DONE *  [core boot]     All workers started
-    DONE *  [core boot]     Now listening on port 3030 on https://your_firefish_url.example.com
-    ```
-1. A fresh Firefish environment is created on the URL you have set!
-
-When you want to restart the dev server, you just need to terminate the process (a.k.a. press `Ctrl+C`) and run `docker compose up` again.
+You can find documentation at [Here](../dev/docker-dbonly/README.md).
diff --git a/scripts/dev-down.mjs b/scripts/dev-down.mjs
index 8c7a83435a..73573a2151 100644
--- a/scripts/dev-down.mjs
+++ b/scripts/dev-down.mjs
@@ -5,11 +5,7 @@ import { execa } from "execa";
 (async () => {
 	const __dirname = path.dirname(fileURLToPath(import.meta.url));
 
-	execa("podman-compose", [
-		"--file",
-		"docker-compose-dbonly.yml",
-		"down",
-	], {
+	execa("podman-compose", {
 		cwd: join(__dirname, "/../dev"),
 		stdio: "inherit",
 	});
diff --git a/scripts/dev-up.mjs b/scripts/dev-up.mjs
index 166c8dbad3..73573a2151 100644
--- a/scripts/dev-up.mjs
+++ b/scripts/dev-up.mjs
@@ -5,12 +5,7 @@ import { execa } from "execa";
 (async () => {
 	const __dirname = path.dirname(fileURLToPath(import.meta.url));
 
-	execa("podman-compose", [
-		"--file",
-		"docker-compose-dbonly.yml",
-		"up",
-		"--detach",
-	], {
+	execa("podman-compose", {
 		cwd: join(__dirname, "/../dev"),
 		stdio: "inherit",
 	});