diff --git a/Dockerfile b/Dockerfile index 1582452..8d48ee4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -90,7 +90,6 @@ RUN curl -sSL https://curl.haxx.se/download/curl-$CURL_VER.tar.gz | tar xz && \ cd .. && rm -rf curl-$CURL_VER # Build libpq -# TODO: fix so that --with-openssl works with pqssl tests RUN curl -sSL https://ftp.postgresql.org/pub/source/v$PQ_VER/postgresql-$PQ_VER.tar.gz | tar xz && \ cd postgresql-$PQ_VER && \ CC="musl-gcc -fPIE -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure \ diff --git a/Makefile b/Makefile index 21ef7b5..748c574 100644 --- a/Makefile +++ b/Makefile @@ -21,8 +21,6 @@ test-pq: ./test.sh pq test-dieselpg: ./test.sh dieselpg -test-dieselpgssl: - ./test.sh dieselpgssl test-dieselsqlite: ./test.sh dieselsqlite test-ssl: @@ -41,6 +39,6 @@ clean-builds: sudo rm -f test/dieselsqlitecrate/main.db clean: clean-docker clean-lock clean-builds -test: test-plain test-ssl test-pq test-serde test-curl test-zlib test-hyper test-dieselpgssl test-dieselsqlite +test: test-plain test-ssl test-pq test-serde test-curl test-zlib test-hyper test-dieselpg test-dieselsqlite .PHONY: test-plain test-ssl test-pq test-rocket test-serde test-curl test-zlib test-hyper test-dieselpg test-dieselsqlite diff --git a/README.md b/README.md index 0fa8f99..b0c5bcc 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,15 @@ Works without fork now. See the [test/dieselpgcrate](./test/dieselpgcrate) for h For stuff like `infer_schema!` to work you need to explicitly pass on `-e DATABASE_URL=$DATABASE_URL` to the `docker run`. It's probably easier to just make `diesel print-schema > src/schema.rs` part of your migration setup though. +Note that diesel compiles with `openssl` statically since `1.34.0`, so you need to include the `openssl` crate **before** `diesel` due to [pq-sys#25](https://github.com/sgrif/pq-sys/issues/25): + +```rs +extern crate openssl; +#[macro_use] extern crate diesel; +``` + +This is true even if you connect without `sslmode=require`. + ## Caching Cargo Locally Repeat builds locally are always from scratch (thus slow) without a cached cargo directory. You can set up a docker volume by just adding `-v cargo-cache:/root/.cargo/registry` to the docker run command. diff --git a/test/dieselpgcrate/Cargo.toml b/test/dieselpgcrate/Cargo.toml index af9edff..98ff2e7 100644 --- a/test/dieselpgcrate/Cargo.toml +++ b/test/dieselpgcrate/Cargo.toml @@ -4,4 +4,5 @@ name = "dieselpgcrate" version = "0.1.0" [dependencies] -diesel = { version = "1.2.*", features = ["postgres"] } +diesel = { version = "1.4.*", features = ["postgres"] } +openssl = "*" diff --git a/test/dieselpgcrate/src/main.rs b/test/dieselpgcrate/src/main.rs index 2c8e55b..880e00a 100644 --- a/test/dieselpgcrate/src/main.rs +++ b/test/dieselpgcrate/src/main.rs @@ -1,5 +1,7 @@ -#[macro_use] -extern crate diesel; +// The order of these extern crate lines matter for ssl! +extern crate openssl; +#[macro_use] extern crate diesel; +// openssl must be included before diesel atm. mod schema { table! { @@ -35,7 +37,8 @@ use diesel::prelude::*; use diesel::pg::PgConnection; fn main() { - let database_url = std::env::var("DATABASE_URL").unwrap_or("postgres://localhost?connect_timeout=1".into()); + let database_url = std::env::var("DATABASE_URL") + .unwrap_or("postgres://localhost?connect_timeout=1&sslmode=require".into()); match PgConnection::establish(&database_url) { Err(e) => { println!("Should fail to connect here:"); diff --git a/test/dieselpgsslcrate/Cargo.toml b/test/dieselpgsslcrate/Cargo.toml deleted file mode 100644 index c1880c5..0000000 --- a/test/dieselpgsslcrate/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -authors = ["clux "] -name = "dieselpgsslcrate" -version = "0.1.0" -edition = "2018" - -[dependencies] -log = "0.4.*" -env_logger = "0.6" -uuid = { version = "0.7.*", features = ["v4"] } -diesel = { version = "1.4.*", features = ["postgres", "uuid", "r2d2"] } -openssl = "*" diff --git a/test/dieselpgsslcrate/src/db.rs b/test/dieselpgsslcrate/src/db.rs deleted file mode 100644 index 942c063..0000000 --- a/test/dieselpgsslcrate/src/db.rs +++ /dev/null @@ -1,15 +0,0 @@ -use diesel::pg::PgConnection; -use diesel::r2d2::{ConnectionManager, Pool}; -use std::sync::Arc; - -pub(crate) type ConnectionPool = Arc>>; - -pub(crate) fn create_database_pool(url: &str, size: u32) -> ConnectionPool { - let manager = ConnectionManager::::new(url); - let pool = Pool::builder() - .max_size(size) - .build(manager) - .expect("Error creating a database pool"); - - Arc::new(pool) -} diff --git a/test/dieselpgsslcrate/src/main.rs b/test/dieselpgsslcrate/src/main.rs deleted file mode 100644 index f168fb6..0000000 --- a/test/dieselpgsslcrate/src/main.rs +++ /dev/null @@ -1,30 +0,0 @@ -// The order of these extern crate lines matter for ssl! -extern crate openssl; -#[macro_use] extern crate diesel; -// openssl must be included before diesel atm. - -use std::env; - -fn main() { - env_logger::init(); - - let _db = { - let url = std::env::var("DATABASE_URL") - .unwrap_or("postgres://localhost?connect_timeout=1&sslmode=require".into()); - let size = env::var("DATABASE_POOL_SIZE") - .map(|val| { - val.parse::() - .expect("Error converting DATABASE_POOL_SIZE variable into u32") - }) - .unwrap_or_else(|_| 5); - - crate::db::create_database_pool(&url, size) - }; - - { - let mut input = String::new(); - std::io::stdin().read_line(&mut input).unwrap(); - } -} - -pub(crate) mod db; diff --git a/test/dieselpgsslcrate/src/schema.rs b/test/dieselpgsslcrate/src/schema.rs deleted file mode 100644 index 63d947f..0000000 --- a/test/dieselpgsslcrate/src/schema.rs +++ /dev/null @@ -1,6 +0,0 @@ -table! { - room (id) { - id -> Uuid, - data -> Text, - } -}