1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

add oracle support

This commit is contained in:
Robin Appelman 2023-05-04 16:43:57 +02:00
commit a1c8e3c338
9 changed files with 92 additions and 14 deletions

View file

@ -36,8 +36,8 @@ See the [configuration section](#configuration) for more options.
haze start [database] [php-version]
```
Where `database` is one of `sqlite`, `mysql`, `mariadb` or `pgsql` with an optional version (e.g. `pgsql:12`), defaults to `sqlite`.
And `php-version` is one of `7.3`, `7.4`, `8.0`, `8.1`, `7` or `8`, defaults to `8.1`
Where `database` is one of `sqlite`, `mysql`, `mariadb`, `pgsql` or `oracle` with an optional version (e.g. `pgsql:12`), defaults to `sqlite`.
And `php-version` is one of `8.0`, `8.1`, `8.2`, defaults to `8.1`. `7.3` and `7.4` are still supported but the docker images for those versions aren't being updated anymore so they might be missing some newer features.
Additionally, you can use the following options when starting an instance:
- `s3`: setup an S3 server and configure to Nextcloud to use it as primary storage

View file

@ -4,7 +4,7 @@ set -e
export DOCKER_BUILDKIT=1
versions=("7.3" "7.4" "8.0" "8.1")
versions=("8.0" "8.1" "8.2")
for version in "${versions[@]}"; do
echo "building haze-php-$version"

View file

@ -2,8 +2,8 @@
$AUTOCONFIG = [
'dbname' => 'xe',
'dbhost' => 'oci',
'dbhost' => 'oracle',
'dbuser' => 'system',
'dbpass' => 'oracle',
'dbpass' => 'haze',
'dbtype' => 'oci'
];

View file

@ -12,7 +12,7 @@ cd $WEBROOT
if [ "$SQL" = "oci" ]; then
# oracle is a special snowflake
occ maintenance:install --admin-user=$USER --admin-pass=$PASSWORD --database=$SQL --database-name=xe --database-host=$SQL --database-user=system --database-pass=oracle
occ maintenance:install --admin-user=$USER --admin-pass=$PASSWORD --database=$SQL --database-name=xe --database-host=$SQL --database-user=system --database-pass=haze
elif [ "$SQL" = "mariadb" ]; then
occ maintenance:install --admin-user=$USER --admin-pass=$PASSWORD --database=mysql --database-name=haze --database-host=$SQL --database-user=haze --database-pass=haze
else

View file

@ -79,6 +79,11 @@ RUN echo "extension=imagick.so" > $PHP_INI_DIR/conf.d/imagick.ini \
&& echo "memory_limit = 512M" > $PHP_INI_DIR/conf.d/memory_limit.ini \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
ADD install-oci.sh /
RUN /install-oci.sh \
&& echo "extension=oci8.so" > $PHP_INI_DIR/conf.d/oci8.ini
ADD apcu.ini opcache.ini redis.ini $PHP_INI_DIR/conf.d/
ADD nginx.conf nginx-app.conf /etc/nginx/

25
images/php/install-oci.sh Executable file
View file

@ -0,0 +1,25 @@
#!/bin/sh
PHP=$(echo "$PHP_VERSION" | cut -c -3)
echo "php $PHP"
case $PHP in
"7.4") OCI_VERSION="-2.2.0" ;;
"8.0") OCI_VERSION="-3.0.1" ;;
"8.1") OCI_VERSION="-3.2.1" ;;
*) status=$status ;;
esac
echo "using oci8$OCI_VERSION"
mkdir /opt/oracle
cd /opt/oracle
wget https://download.oracle.com/otn_software/linux/instantclient/2110000/instantclient-basiclite-linux.x64-21.10.0.0.0dbru.zip
wget https://download.oracle.com/otn_software/linux/instantclient/2110000/instantclient-sdk-linux.x64-21.10.0.0.0dbru.zip
unzip instantclient-basiclite-linux.x64-21.10.0.0.0dbru.zip
unzip instantclient-sdk-linux.x64-21.10.0.0.0dbru.zip
rm instantclient*.zip
echo /opt/oracle/instantclient_21_10 > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig
pecl install -D 'with-oci8="instantclient,/opt/oracle/instantclient_21_10"' oci8$OCI_VERSION

View file

@ -2,7 +2,7 @@
set -e
versions=("7.3" "7.4" "8.0" "8.1" "7.3-dbg" "7.4-dbg" "8.0-dbg" "8.1-dbg")
versions=("8.0" "8.1" "8.2" "8.0-dbg" "8.1-dbg" "8.2-dbg")
for version in "${versions[@]}"; do
docker push "icewind1991/haze-php:$version"

View file

@ -11,11 +11,13 @@ use std::str::FromStr;
use std::time::Duration;
use tokio::time::{sleep, timeout};
#[derive(Eq, PartialEq)]
pub enum DatabaseFamily {
Sqlite,
Mysql,
MariaDB,
Postgres,
Oracle,
}
impl DatabaseFamily {
@ -25,6 +27,7 @@ impl DatabaseFamily {
DatabaseFamily::Mysql => "mysql",
DatabaseFamily::MariaDB => "mariadb",
DatabaseFamily::Postgres => "pgsql",
DatabaseFamily::Oracle => "oci",
}
}
}
@ -50,6 +53,7 @@ pub enum Database {
Postgres12,
Postgres13,
Postgres14,
Oracle,
}
impl Default for Database {
@ -96,6 +100,8 @@ impl FromStr for Database {
"postgresql:12" => Ok(Database::Postgres12),
"postgresql:13" => Ok(Database::Postgres13),
"postgresql:14" => Ok(Database::Postgres14),
"oracle" => Ok(Database::Oracle),
"oci" => Ok(Database::Oracle),
_ => Err(Report::msg("Unknown db type")),
}
}
@ -122,6 +128,7 @@ impl Database {
Database::Postgres12 => "postgres:12",
Database::Postgres13 => "postgres:13",
Database::Postgres14 => "postgres:14",
Database::Oracle => "gvenzl/oracle-xe:21-faststart",
}
}
@ -148,6 +155,7 @@ impl Database {
| Database::Postgres12
| Database::Postgres13
| Database::Postgres14 => DatabaseFamily::Postgres,
Database::Oracle => DatabaseFamily::Oracle,
}
}
@ -165,6 +173,7 @@ impl Database {
"POSTGRES_USER=haze",
"POSTGRES_DATABASE=haze",
],
DatabaseFamily::Oracle => vec!["ORACLE_PASSWORD=haze"],
}
}
@ -177,9 +186,15 @@ impl Database {
if matches!(self, Database::Sqlite) {
return Ok(None);
}
if self.image().contains('/') {
pull_image(docker, self.image())
.await
.wrap_err("Failed to pull database image")?;
} else {
pull_image(docker, &format!("library/{}", self.image()))
.await
.wrap_err("Failed to pull database image")?;
}
let options = Some(CreateContainerOptions {
name: format!("{}-db", cloud_id),
});
@ -280,19 +295,35 @@ impl Database {
)
.await
}
DatabaseFamily::Oracle => {
exec_tty(
docker,
format!("{}-db", cloud_id),
"root",
vec!["sqlplus", "system/haze"],
vec![],
)
.await
}
}
}
pub async fn wait_for_start(&self, docker: &mut Docker, cloud_id: &str) -> Result<()> {
timeout(Duration::from_secs(15), async {
let time = if self.family() == DatabaseFamily::Oracle {
45
} else {
15
};
timeout(Duration::from_secs(time), async {
while !self.is_healthy(docker, cloud_id).await? {
sleep(Duration::from_millis(100)).await
sleep(Duration::from_millis(250)).await
}
Ok(())
Result::<(), Report>::Ok(())
})
.await
.into_diagnostic()
.wrap_err("Timeout after 15 seconds")?
.wrap_err(format!("Timeout after {time} seconds"))?
}
pub async fn ip(&self, docker: &mut Docker, cloud_id: &str) -> Option<IpAddr> {
@ -355,6 +386,20 @@ impl Database {
Ok(false)
}
}
DatabaseFamily::Oracle => {
let mut output = Vec::new();
exec(
docker,
format!("{}-db", cloud_id),
"root",
vec!["sh", "-c", r#"echo "show user" | sqlplus -S system/haze"#],
vec![],
Some(&mut output),
)
.await?;
let output = String::from_utf8(output).into_diagnostic()?;
Ok(output.contains(r#"USER is "SYSTEM""#))
}
}
}
}

View file

@ -310,6 +310,9 @@ async fn main() -> Result<()> {
DatabaseFamily::Sqlite => {
return Err(Report::msg("sqlite is not supported with `haze env`"))
}
DatabaseFamily::Oracle => {
return Err(Report::msg("oracle is not supported with `haze env`"))
}
DatabaseFamily::Mysql | DatabaseFamily::MariaDB => "mysql",
DatabaseFamily::Postgres => "postgresql",
};