Skip to content

Commit

Permalink
Upgrade Build & Dev experience
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Jul 29, 2024
1 parent 28c6acd commit d25dbd4
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 73 deletions.
1 change: 1 addition & 0 deletions engine/.build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN ["/bin/bash", "-c", "set -x && rm target/x86_64-unknown-linux-musl/release/d

# Now add the rest of the project and build the real main
COPY src ./src
COPY migrations ./migrations
RUN set -x && cargo build --target x86_64-unknown-linux-musl --release
RUN mkdir -p /build-out
RUN set -x && cp target/x86_64-unknown-linux-musl/release/$BINARY_NAME /build-out/
Expand Down
12 changes: 6 additions & 6 deletions engine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ build:
# cargo build --release
docker buildx build -t ghcr.io/v3xlabs/v3x-property-engine:latest -f .build/Dockerfile .

dev:
docker compose -f compose.dev.yaml up -d

# dev-logs:
# docker compose -f compose.dev.yaml logs

env:
set -a
source .env
set +a

dev:
docker compose up -d

dev-down:
docker compose down
11 changes: 11 additions & 0 deletions engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ Simply copy the compose.yaml file to your local machine and run:
```sh
docker compose up -d
```

### Keycloak Configuration

To setup keycloak you need to create a client.
This can easily be done by heading to the `Clients` tab in the admin console.

Then you can click on `Create client` and create a basic new OpenID Connect client.
Choose a Client ID, and press `Next`.
Enable `Client Authentication` and specify the `Redirect URIs` to be `http://localhost:3000/callback`.

Once done you can head to the `Credentials` tab to see your Client Secret, insert this in your `.env` file.
48 changes: 0 additions & 48 deletions engine/compose.dev.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions engine/compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# runs the engine on port 3000
version: "3.9"
services:
engine:
image: ghcr.io/v3xlabs/v3x-property-engine:latest
ports:
- "3000:3000"
# Database
postgres:
image: postgres:16.3
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "5432:5432"
58 changes: 53 additions & 5 deletions engine/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
# runs the engine on port 3000
version: "3.9"
services:
engine:
image: ghcr.io/v3xlabs/v3x-property-engine:latest
ports:
- "3000:3000"
# Engine
# engine:
# image: ghcr.io/v3xlabs/v3x-property-engine:latest
# # build:
# # context: .
# # dockerfile: .build/Dockerfile
# ports:
# - "3000:3000"
# env_file: .env
# # OPENID_DISCOVERY_URL=http://localhost:8080/realms/master/.well-known/openid-configuration
# network_mode: host
# depends_on:
# - postgres
# - keycloak
# # networks:
# # - default
# Database
postgres:
image: postgres:16.3
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
POSTGRES_DB: property
ports:
- "5432:5432"
# networks:
# - default
# Keycloak
keycloak:
image: keycloak/keycloak:25.0
restart: always
environment:
KC_DB: postgres
KC_DB_URL: jdbc:postgresql://postgres:5432/postgres
KC_DB_USERNAME: postgres
KC_DB_PASSWORD: postgres

KC_HOSTNAME: localhost
KC_HOSTNAME_PORT: 8080
KC_HOSTNAME_STRICT: false
KC_HOSTNAME_STRICT_HTTPS: false

KC_LOG_LEVEL: info
KC_METRICS_ENABLED: true
KC_HEALTH_ENABLED: true
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
# KEYCLOAK_IMPORT: /tmp/realm.json
command: start-dev
depends_on:
- postgres
ports:
- "8080:8080"
# networks:
# - default
# volumes:
# - ./realm.json:/tmp/realm.json

# networks:
# default:
# driver: bridge
17 changes: 5 additions & 12 deletions engine/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ impl AppState {

// #[cfg(feature = "oauth")]
let openid = {
let openid_client_id = env::var("OPENID_CLIENT_ID").unwrap_or("devclient".to_string());
let openid_client_id = env::var("OPENID_CLIENT_ID").unwrap();
let openid_client_secret = env::var("OPENID_CLIENT_SECRET").unwrap();
let openid_redirect = Url::parse(
env::var("OPENID_REDIRECT")
.unwrap_or("http://localhost:3000/callback".to_string())
.as_str(),
)
.unwrap()
.to_string();
let openid_issuer = env::var("OPENID_ISSUER")
.unwrap_or("http://localhost:8080/realms/master".to_string())
.parse()
.unwrap();
let openid_redirect = Url::parse(env::var("OPENID_REDIRECT").unwrap().as_str())
.unwrap()
.to_string();
let openid_issuer = env::var("OPENID_ISSUER").unwrap().parse().unwrap();

DiscoveredClient::discover(
openid_client_id,
Expand Down
4 changes: 2 additions & 2 deletions web/src/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const useHttp = <K>(url: string, token: string | null) => useSWR(token &&
const response = await fetch("http://localhost:3000/api/properties", { headers });
const data = await response.json() as K;

return data as any;
return data as K;
} catch (error) {
console.error(error);
return null;
}
});
});

0 comments on commit d25dbd4

Please sign in to comment.