Skip to content

Commit

Permalink
Merge pull request #310 from TimePrinciple/add_arch_development_guide
Browse files Browse the repository at this point in the history
Add developer guide on Arch Linux
  • Loading branch information
genedna authored Jan 26, 2024
2 parents 57c9df0 + e8d9230 commit 022c82e
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 12 deletions.
21 changes: 11 additions & 10 deletions .env
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## you should add the environment variable in .zshrc or other profile on production enviroment

## Database connect and pool configuration
MEGA_DB_POSTGRESQL_URL = "postgres://${PG_USERNAME}:${PG_SECRET}@${PG_HOST}/mega"
MEGA_DB_MYSQL_URL = "mysql://${MYSQL_USERNAME}:${MYSQL_SECRET}@${MYSQL_HOST}/mega"

# Fillin the following environment variables with values you set
DB = "" # {postgres, mysql}
DB_USERNAME = ""
DB_PASSWORD = ""
DB_HOST = ""

MEGA_DB_POSTGRESQL_URL = "${DB}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/mega"
MEGA_DB_MYSQL_URL = "${DB}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/mega"
MEGA_DB_MAX_CONNECTIONS = 32
MEGA_DB_MIN_CONNECTIONS = 16

MEGA_DB_SQLX_LOGGING = false # Whether to enabling SQLx Log
MEGA_DB_SQLX_LOGGING = false # Whether to disabling SQLx Log

## Mega SSH key path
# Mega SSH key path
MEGA_SSH_KEY = "/tmp/.mega/ssh"

## file storage configuration
Expand All @@ -25,11 +27,10 @@ MEGA_BIG_OBJ_THRESHOLD_SIZE = 1024 # Unit KB. If the object file size exceeds th
MEGA_INIT_DIRS = "projects,docs,third_parts" # init these repo directories in mega init command
MEGA_IMPORT_DIRS = "third_parts" # Only import directory support multi-branch commit and tag, repo under regular directory only support main branch only

## Objects decode configuration
GIT_INTERNAL_DECODE_CACHE_SIZE = 1000 # Maximum number of git objects in LRU cache
GIT_INTERNAL_DECODE_STORAGE_BATCH_SIZE = 10000 # The maximum number of git object in a "INSERT" SQL database operation
GIT_INTERNAL_DECODE_STORAGE_TQUEUE_SIZE = 10 # The maximum number of parallel insertion threads in the database operation queue
GIT_INTERNAL_DECODE_CACHE_TYEP = "lru" #{lru,redis}
GIT_INTERNAL_DECODE_CACHE_TYEP = "lru" # {lru,redis}
REDIS_CONFIG = "redis://127.0.0.1:6379"

## Bazel build configuration
Expand Down
140 changes: 138 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Centralized systems, despite their convenience and popularity, are not without t

To address these challenges, there's a growing need for a decentralized open-source collaboration model. Such a model would enhance the freedom of communication among developers and strengthen their ownership and control over their code. By moving away from centralized systems, developers can ensure that their contributions and the direction of their projects are not unduly influenced by the policies or stability of a single platform. This shift towards decentralization is not just a technical necessity but a step towards preserving the ethos of open-source: collaboration, freedom, and community-driven development.

## Quick Started for developing and testing on MacOS
## Quick Start for developing and testing

### MacOS

1. Install Rust on your MacOS machine.

Expand Down Expand Up @@ -150,6 +152,140 @@ To address these challenges, there's a growing need for a decentralized open-sou
$ git clone http://localhost:8000/projects/mega.git
```

### Arch Linux

1. Install Rust.

```bash
$ pacman -S rustup
$ rustup default stable
```

2. Clone mega repository and build.

```bash
$ git clone https://github.com/web3infra-foundation/mega.git
$ cd mega
$ cargo build
```

3. Install PostgreSQL and initialize database.

1. Install PostgreSQL.

```bash
$ pacman -S postgresql
# Switch to `postgres` user
$ sudo -i -u postgres
postgres $ initdb -D /var/lib/postgres/data -E utf8 # /Volumes/Data is where data will be stored
postgres $ exit
$ systemctl enable --now postgresql
```

2. Create database.

```bash
$ sudo -u postgres psql postgres
```

```sql
postgres=# \l
postgres=# DROP DATABASE IF EXISTS mega;
postgres=# CREATE DATABASE mega;
postgres=# \q
```

3. Import `mega/sql/postgres/pg_<time>_init.sql` to `mega`.

```bash
$ cd mega/sql/postgres
$ psql mega < pg_<time>__init.sql
```

4. Craeate user and grant privileges.

```sql
postgres=# DROP USER IF EXISTS mega;
postgres=# CREATE USER mega WITH ENCRYPTED PASSWORD 'rustgit';
postgres=# GRANT ALL PRIVILEGES ON DATABASE mega TO mega;
```

```bash
$ psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
$ psql mega -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to mega;"
$ psql mega -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to mega;"
```

4. Install redis.

```bash
$ pacman -S redis
$ systemctl enable --now redis
```

5. Config `.env`.

```ini
# If you followed the installation guide, you can use below URL directly, comment it the otherwise.
MEGA_DB_POSTGRESQL_URL = "postgres://mega:[email protected]/mega"
# If you changed any of the username, password or host, you will need to uncomment the following line and replace the placeholders manually.
#MEGA_DB_POSTGRESQL_URL = "postgres://<username>:<password>@127.0.0.1/<db_name (or host)>"
MEGA_DB_MAX_CONNECTIONS = 32
MEGA_DB_MIN_CONNECTIONS = 16

MEGA_DB_SQLX_LOGGING = false # Whether to disabling SQLx Log

## file storage configuration
MEGA_OBJ_STORAGR_TYPE = "LOCAL" # LOCAL or REMOTE
MEGA_OBJ_LOCAL_PATH = "/tmp/.mega" # This configuration is used to set the local path of the project storage

MEGA_BIG_OBJ_THRESHOLD_SIZE = 1024 # Unit KB. If the object file size exceeds the threshold value, it will be handled by file storage instead of the database.

## Init directory configuration
MEGA_INIT_DIRS = "projects,docs,third_parts" # init these repo directories in mega init command
MEGA_IMPORT_DIRS = "third_parts" # Only import directory support multi-branch commit and tag, repo under regular directory only support main branch only


GIT_INTERNAL_DECODE_CACHE_SIZE = 100 # Maximum number of git objects in LRU cache
GIT_INTERNAL_DECODE_STORAGE_BATCH_SIZE = 1000 # The maximum number of git object in a "INSERT" SQL database operation
GIT_INTERNAL_DECODE_STORAGE_TQUEUE_SIZE = 1 # The maximum number of parallel insertion threads in the database operation queue
GIT_INTERNAL_DECODE_CACHE_TYEP = "redis" # {lru,redis}
REDIS_CONFIG = "redis://127.0.0.1:6379"

## Bazel build config, you can use service like buildfarm to enable RBE(remote build execution)
# you can refer to https://bazelbuild.github.io/bazel-buildfarm/docs/quick_start/ for more details about remote executor
BAZEL_BUILD_ENABLE = false # leave true if you want to trigger bazel build in each push process
BAZEL_BUILDP_PATH = "/tmp/.mega/bazel_build_projects" # Specify a temporary directory to build the project with bazel
BAZEL_REMOTE_EXECUTOR = "grpc://localhost:8980" # If enable the remote executor, please fillin the remote executor address, or else leave empty if you want to build by localhost.
BAZEL_GIT_CLONE_URL = "http://localhost:8000" # Tell bazel to clone the project from the specified git url
```

6. Init Mega.

```bash
$ cd mega
$ cargo run init
```

7. Start Mega server.

```bash
# Start a single https server
$ cargo run service https
# Or Start multiple server
$ cargo run service start http ssh p2p
```

8. Test `git push` and `git clone`

```bash
$ cd mega
$ git remote add local http://localhost:8000/projects/mega.git
$ git push local main
$ cd /tmp
$ git clone http://localhost:8000/projects/mega.git
```

## Contributing

The mega project relies on community contributions and aims to simplify getting started. To develop Mega, clone the repository, then install all dependencies and initialize the database schema, run the test suite and try it out locally. Pick an issue, make changes, and submit a pull request for community review.
Expand All @@ -161,4 +297,4 @@ More information on contributing to Mega is available in the [Contributing Guide
Mega is licensed under this Licensed:

- MIT LICENSE ( [LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)

0 comments on commit 022c82e

Please sign in to comment.