Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
NewbMiao committed Jun 8, 2023
1 parent 42ac807 commit b911c16
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 19 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ jobs:
fetch-depth: 0
- name: Install Rust
run: rustup toolchain install stable --component llvm-tools-preview
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: install nextest
uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v1
- name: Check code format
run: cargo fmt -- --check
# - name: Install cargo-llvm-cov
# uses: taiki-e/install-action@cargo-llvm-cov
# - name: install nextest
# uses: taiki-e/install-action@nextest
- name: Install sqlx-cli
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres
# - uses: Swatinem/rust-cache@v1
# - name: Check code format
# run: cargo fmt -- --check
- name: Start DB service
run: sh ./services-up.sh
- name: Check the package for errors
run: cargo check --all
- name: Lint rust sources
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
volumes:
- "postgresql_keycloak_data:/bitnami/postgresql"
environment:
ALLOW_EMPTY_PASSWORD: yes
ALLOW_EMPTY_PASSWORD: "yes"
POSTGRESQL_USERNAME: keycloak
POSTGRESQL_DATABASE: keycloak
POSTGRESQL_PASSWORD: keycloak-sec
Expand Down Expand Up @@ -46,7 +46,7 @@ services:
KC_DB_URL: jdbc:postgresql://keycloak_database:5432/keycloak
KC_DB_USERNAME: keycloak
KC_DB_PASSWORD: keycloak-sec
KEYCLOAK_CREATE_ADMIN_USER: true
KEYCLOAK_CREATE_ADMIN_USER: "true"
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin-sec
ports:
Expand Down
9 changes: 9 additions & 0 deletions src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod profile;
use sqlx::{postgres::PgPoolOptions, Pool, Postgres};

pub async fn get_db_pool(database_url: String) -> Result<Pool<Postgres>, sqlx::Error> {
PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
}
1 change: 0 additions & 1 deletion src/tables/profile.rs → src/database/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Profile {
created_date: DateTime<Utc>,
updated_date: Option<DateTime<Utc>>,
}

impl Profile {
pub fn new(account_id: String, username: String, email: String, refresh_token: String) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Deserialize;
use serde_json::json;
use sqlx::{Pool, Postgres};

use crate::{extensions::google_auth::GoogleAuth, tables::profile::Profile};
use crate::{database::profile::Profile, extensions::google_auth::GoogleAuth};

pub async fn auth_handler(Extension(google_auth): Extension<Arc<GoogleAuth>>) -> impl IntoResponse {
let auth_url = google_auth.auth_url().await;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod database;
pub mod extensions;
pub mod handlers;
pub mod middlewares;
pub mod tables;
8 changes: 2 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use axum::{middleware, routing::get, Extension, Router};
use axum_koans::{
database::get_db_pool,
extensions::{google_auth::GoogleAuth, keycloak_auth::KeycloakAuth},
handlers::{
auth::{auth_callback_handler, auth_handler},
Expand All @@ -8,7 +9,6 @@ use axum_koans::{
middlewares::log,
};
use dotenvy::{self, dotenv};
use sqlx::postgres::PgPoolOptions;
use std::{env, net::SocketAddr, sync::Arc};
use tower::ServiceBuilder;
use tower_http::trace::{self, TraceLayer};
Expand Down Expand Up @@ -36,11 +36,7 @@ async fn main() {
env::var("DATABASE_URL").expect("Missing the DATABASE_URL environment variable.");

// db pool
let db_pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await
.unwrap();
let db_pool = get_db_pool(database_url).await.unwrap();
// Start configuring a `fmt` subscriber
let subscriber = tracing_subscriber::fmt()
.compact()
Expand Down
1 change: 0 additions & 1 deletion src/tables/mod.rs

This file was deleted.

0 comments on commit b911c16

Please sign in to comment.