Update postgres (#252)
Reviewed-on: phoenix/icarus#252
This commit was merged in pull request #252.
This commit is contained in:
+110
-50
@@ -10,18 +10,38 @@ concurrency:
|
|||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
|
||||||
|
cargo check
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:18.3-alpine
|
image: postgres:18.4-alpine
|
||||||
env:
|
env:
|
||||||
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
|
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
||||||
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
|
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
||||||
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
|
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -30,55 +50,95 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
- name: Install Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
with:
|
||||||
toolchain: 1.96.1
|
toolchain: 1.96.1
|
||||||
components: clippy, rustfmt
|
- uses: Swatinem/rust-cache@v2
|
||||||
override: true
|
- name: Verify Docker Environment
|
||||||
|
|
||||||
- name: Cache dependencies
|
|
||||||
uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- name: Install libpq
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
echo "Runner User Info:"
|
||||||
sudo apt-get install -y libpq-dev postgresql-client
|
id
|
||||||
|
echo "Checking Docker Version:"
|
||||||
- name: Setup test database
|
docker --version
|
||||||
env:
|
echo "Checking Docker Daemon Status (info):"
|
||||||
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
|
docker info
|
||||||
run: |
|
echo "Checking Docker Daemon Status (ps):"
|
||||||
# Wait for PostgreSQL to be ready
|
docker ps -a
|
||||||
for i in {1..10}; do
|
echo "Docker environment check complete."
|
||||||
pg_isready -U ${{ secrets.POSTGRES_USER }} -d ${{ secrets.POSTGRES_DB }} && break
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
cargo install sqlx-cli --no-default-features --features native-tls,postgres
|
|
||||||
sqlx migrate run --database-url $DATABASE_URL
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
mkdir -p ~/.ssh
|
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitea_deploy_key
|
|
||||||
chmod 600 ~/.ssh/gitea_deploy_key
|
|
||||||
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
|
||||||
eval $(ssh-agent -s)
|
|
||||||
ssh-add -v ~/.ssh/gitea_deploy_key
|
|
||||||
cargo build --verbose --release
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
env:
|
env:
|
||||||
|
# Define DATABASE_URL for tests to use
|
||||||
|
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
|
RUST_LOG: info # Optional: configure test log level
|
||||||
|
SECRET_MAIN_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||||
|
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
||||||
ROOT_DIRECTORY: "/tmp"
|
ROOT_DIRECTORY: "/tmp"
|
||||||
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
|
|
||||||
run: |
|
run: |
|
||||||
cat .env.sample | head -6 > .env
|
mkdir -p ~/.ssh
|
||||||
cargo test --verbose --
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
- name: Run clippy
|
eval $(ssh-agent -s)
|
||||||
run: cargo clippy -- -D warnings
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
|
||||||
- name: Run rustfmt
|
cargo test
|
||||||
run: cargo fmt --all -- --check
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo build --release
|
||||||
|
|||||||
Generated
+1
-1
@@ -1040,7 +1040,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"axum-extra",
|
"axum-extra",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ Web API for the Icarus project.
|
|||||||
|
|
||||||
|
|
||||||
### Requires
|
### Requires
|
||||||
`icarus_auth` v0.7.x
|
`icarus_auth` v0.8.x
|
||||||
`songparser` v0.5.x
|
`songparser` v0.6.x
|
||||||
|
|
||||||
### Compatible with
|
### Compatible with
|
||||||
`icarus-dm` v0.9.x
|
`icarus-dm` v0.9.x
|
||||||
|
|||||||
+12
-21
@@ -3,12 +3,11 @@ version: '3.8' # Use a recent version
|
|||||||
services:
|
services:
|
||||||
# --- Web API ---
|
# --- Web API ---
|
||||||
api:
|
api:
|
||||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
build:
|
||||||
context: .
|
context: .
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"]
|
||||||
container_name: icarus # Optional: Give the container a specific name
|
container_name: icarus
|
||||||
ports:
|
ports:
|
||||||
# Map host port 8000 to container port 3000 (adjust as needed)
|
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
@@ -17,21 +16,18 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
restart: unless-stopped # Optional: Restart policy
|
restart: unless-stopped
|
||||||
|
|
||||||
# --- Web API auth ---
|
# --- Web API auth ---
|
||||||
auth_api:
|
auth_api:
|
||||||
build:
|
build:
|
||||||
context: ../icarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
context: ../icarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"]
|
||||||
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
||||||
container_name: auth_api
|
container_name: auth_api
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8001:8001" # Map host port 8000 to container port 8000 (adjust container port based on your app's EXPOSE in Dockerfile)
|
- "8001:8001"
|
||||||
# environment:
|
|
||||||
# Environment variables your API needs, e.g., database connection
|
|
||||||
# Add other necessary environment variables
|
|
||||||
env_file:
|
env_file:
|
||||||
- ../icarus_auth/.env
|
- ../icarus_auth/.env
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -63,10 +59,9 @@ services:
|
|||||||
|
|
||||||
|
|
||||||
# PostgreSQL Database Service
|
# PostgreSQL Database Service
|
||||||
# --- icarus web api db ---
|
|
||||||
main_db:
|
main_db:
|
||||||
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_db # Optional: Give the container a specific name
|
container_name: icarus_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
||||||
@@ -76,7 +71,6 @@ services:
|
|||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data:/var/lib/postgresql
|
- postgres_data:/var/lib/postgresql
|
||||||
ports:
|
ports:
|
||||||
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
|
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
@@ -85,14 +79,14 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always # Optional: Restart policy
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
|
|
||||||
# --- icarus web auth api db ---
|
# --- icarus web auth api db ---
|
||||||
auth_db:
|
auth_db:
|
||||||
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_auth_db # Optional: Give the container a specific name
|
container_name: icarus_auth_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
||||||
@@ -102,7 +96,6 @@ services:
|
|||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data_auth:/var/lib/postgresql
|
- postgres_data_auth:/var/lib/postgresql
|
||||||
ports:
|
ports:
|
||||||
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
|
|
||||||
- "5433:5432"
|
- "5433:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
@@ -111,18 +104,16 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always # Optional: Restart policy
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
|
|
||||||
# Define the named volume for data persistence
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
postgres_data_auth:
|
postgres_data_auth:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
|
|
||||||
# Define the network (optional, but good practice)
|
|
||||||
networks:
|
networks:
|
||||||
icarus-network:
|
icarus-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|||||||
+12
-4
@@ -61,7 +61,10 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let create_query = format!("CREATE DATABASE {}", db_name);
|
let create_query = format!("CREATE DATABASE {}", db_name);
|
||||||
match sqlx::query(&create_query).execute(template_pool).await {
|
match sqlx::query(sqlx::AssertSqlSafe(create_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
@@ -73,7 +76,9 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
||||||
sqlx::query(&drop_query).execute(template_pool).await?;
|
sqlx::query(sqlx::AssertSqlSafe(drop_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,13 +111,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod init {
|
mod init {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub async fn app(pool: sqlx::PgPool) -> axum::Router {
|
pub async fn app(pool: sqlx::PgPool) -> axum::Router {
|
||||||
crate::config::init::routes()
|
crate::config::init::routes()
|
||||||
.await
|
.await
|
||||||
.layer(axum::Extension(pool))
|
.layer(axum::Extension(pool))
|
||||||
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
|
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
|
||||||
.layer(tower_http::timeout::TimeoutLayer::new(
|
.layer(tower_http::timeout::TimeoutLayer::with_status_code(
|
||||||
std::time::Duration::from_secs(300),
|
axum::http::StatusCode::OK,
|
||||||
|
Duration::from_secs(300),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user