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