Skip to content

Commit

Permalink
feat: easy getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Aug 2, 2024
1 parent 0a3e7b2 commit b427578
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 208 deletions.
9 changes: 5 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
"*seeds.sql" filter=lfs diff=lfs merge=lfs -text
31 changes: 24 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
- name: Setup BEAM
uses: erlef/setup-beam@v1
with:
otp-version: "26.0.2"
gleam-version: "1.2.1"
rebar3-version: "3"
otp-version: '26.0.2'
gleam-version: '1.2.1'
rebar3-version: '3'
# elixir-version: "1.15.4"
- name: Download gleam dependencies
run: gleam deps download
Expand All @@ -33,22 +33,39 @@ jobs:
backend:
name: Backend tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: gloogle
POSTGRES_USER: gloogle
options: >-
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Setup BEAM
uses: erlef/setup-beam@v1
with:
otp-version: "26.0.2"
gleam-version: "1.2.1"
rebar3-version: "3"
# elixir-version: "1.15.4"
otp-version: '26.0.2'
gleam-version: '1.2.1'
rebar3-version: '3'
- name: Download gleam dependencies
run: gleam deps download
working-directory: apps/backend
- name: Populate DB
run: psql -U gloogle -h postgres < db/seeds.sql
working-directory: apps/backend
env:
PGPASSWORD: gloogle
- name: Run gleam test
run: gleam test
working-directory: apps/backend
env:
POSTGRES_HOST: postgres
- name: Check gleam format
run: gleam format --check src test
working-directory: apps/backend
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ Some features are already implemented, and some others are still on the roadmap!
<!-- - Implements a full-mirror of hex, in case hex is down (because we can, so why not) -->
<!-- - Add a way to visualise a package directly -->

## Getting Started

```sh
# Initialise the DB.
yarn backend:db:init
# Reset the DB when you need.
yarn backend:db:reset
```

```toml
# apps/backend/.mise.local.toml
# Used in env variables mainly.

[env]
# Default server options.
PORT = 3000
LOG_LEVEL = "DEBUG"

# Local database.
DATABASE_URL = "postgres://gloogle:gloogle@localhost:5432/gloogle?sslmode=disable"

# Used to access hex API.
HEX_API_KEY = "xxxxx"

# Used to crawl starsgazers.
GITHUB_TOKEN = "xxxxx"
```

## Contributing

If Gloogle please you, you can also contribute! Pull Requests are welcome!
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/db/seeds.sql
Git LFS file not shown
7 changes: 0 additions & 7 deletions apps/backend/deno.jsonc

This file was deleted.

87 changes: 0 additions & 87 deletions apps/backend/deno.lock

This file was deleted.

6 changes: 5 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "backend",
"packageManager": "yarn@4.2.2",
"scripts": {
"backend:dev": "gleam run"
"backend:dev": "gleam run",
"backend:db:create": "docker run --name gloogle-postgres -it -e POSTGRES_PASSWORD=gloogle -e POSTGRES_USER=gloogle -d -p 5432:5432 postgres",
"backend:db:init": "yarn backend:db:create && sleep 5 && PGPASSWORD=gloogle psql -h localhost -U gloogle < db/seeds.sql",
"backend:db:drop": "docker stop gloogle-postgres && docker rm gloogle-postgres",
"backend:db:reset": "yarn backend:db:drop && yarn backend:db:init"
},
"dependencies": {
"@chouqueth/gleam": "^1.3.2"
Expand Down
8 changes: 0 additions & 8 deletions apps/backend/scripts/database/drop.ts

This file was deleted.

10 changes: 0 additions & 10 deletions apps/backend/scripts/database/init.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/backend/scripts/database/reset.ts

This file was deleted.

53 changes: 0 additions & 53 deletions apps/backend/scripts/helpers.ts

This file was deleted.

5 changes: 0 additions & 5 deletions apps/backend/scripts/thread.ts

This file was deleted.

7 changes: 3 additions & 4 deletions apps/backend/src/backend/config.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ pub fn is_dev() {
}

pub fn bucket_uri() {
let assert Ok(content) = os.get_env("BUCKET_URI")
content
os.get_env("BUCKET_URI")
}

pub fn scaleway_keys() {
let assert Ok(access_key) = os.get_env("SCALEWAY_ACCESS_KEY")
let assert Ok(secret_key) = os.get_env("SCALEWAY_SECRET_KEY")
use access_key <- result.try(os.get_env("SCALEWAY_ACCESS_KEY"))
use secret_key <- result.map(os.get_env("SCALEWAY_SECRET_KEY"))
#(access_key, secret_key)
}

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/s3.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import gleam/option.{type Option, None, Some}
import gleam/result

fn request(url: String, method: http.Method, body: Option(BitArray)) {
let bucket_uri = config.bucket_uri()
let date = birl.to_erlang_universal_datetime(birl.now())
let #(access_key, secret_key) = config.scaleway_keys()
use bucket_uri <- result.try(config.bucket_uri())
use #(access_key, secret_key) <- result.try(config.scaleway_keys())
request.new()
|> request.set_method(method)
|> request.set_path(url)
Expand Down
Loading

0 comments on commit b427578

Please sign in to comment.