-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from WeareJH/wp-fixes
fix: prevent name collision when re-using the php service for WP
- Loading branch information
Showing
10 changed files
with
283 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::context::Context; | ||
use crate::dc_service::DcService; | ||
use crate::services::{Service, Services}; | ||
|
||
use wp_cli::WpCliService; | ||
use wp_db::WpDbService; | ||
use wp_nginx::WpNginxService; | ||
use wp_php::WpPhpService; | ||
use wp_php_debug::WpPhpDebugService; | ||
|
||
pub mod wp_cli; | ||
pub mod wp_db; | ||
pub mod wp_nginx; | ||
pub mod wp_php; | ||
pub mod wp_php_debug; | ||
|
||
pub struct WpServices { | ||
pub services: Vec<DcService>, | ||
} | ||
|
||
impl WpServices { | ||
pub const ROOT: &'static str = "/var/www"; | ||
|
||
pub fn from_ctx(ctx: &Context) -> Self { | ||
let services = vec![ | ||
(WpNginxService).dc_service(ctx, &()), | ||
(WpPhpService).dc_service(ctx, &()), | ||
(WpPhpDebugService).dc_service(ctx, &()), | ||
(WpCliService).dc_service(ctx, &()), | ||
(WpDbService).dc_service(ctx, &()), | ||
]; | ||
|
||
Self { services } | ||
} | ||
} | ||
impl Services for WpServices { | ||
fn dc_services(&self) -> Vec<DcService> { | ||
self.services.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::context::Context; | ||
use crate::dc_service::DcService; | ||
use crate::recipes::wp::services::wp_db::WpDbService; | ||
use crate::recipes::wp::services::wp_php::WpPhpService; | ||
use crate::recipes::wp::services::WpServices; | ||
use crate::services::Service; | ||
|
||
pub struct WpCliService; | ||
|
||
impl Service for WpCliService { | ||
const NAME: &'static str = "wp-cli"; | ||
const IMAGE: &'static str = "wordpress:cli"; | ||
|
||
fn dc_service(&self, ctx: &Context, _vars: &()) -> DcService { | ||
DcService::new(ctx.name(), Self::NAME, Self::IMAGE) | ||
.set_working_dir(WpServices::ROOT) | ||
.set_init(true) | ||
.set_depends_on(vec![WpPhpService::NAME]) | ||
.set_volumes(vec![format!("{}:{}", ctx.cwd.display(), WpServices::ROOT)]) | ||
// .set_volumes(vec![WpServices::PHP]) | ||
.set_environment(vec![&format!("DB_HOST={}", WpDbService::NAME)]) | ||
.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::context::Context; | ||
use crate::dc_service::DcService; | ||
use crate::recipes::wp::volumes::WpVolumes; | ||
use crate::services::Service; | ||
|
||
pub struct WpDbService; | ||
|
||
impl Service for WpDbService { | ||
const NAME: &'static str = "db"; | ||
const IMAGE: &'static str = "mysql:5.7"; | ||
|
||
fn dc_service(&self, ctx: &Context, _vars: &()) -> DcService { | ||
DcService::new(ctx.name(), Self::NAME, Self::IMAGE) | ||
.set_volumes(vec![format!("{}:/var/lib/mysql", WpVolumes::DB)]) | ||
.set_environment(vec![ | ||
"MYSQL_DATABASE=docker", | ||
"MYSQL_USER=docker", | ||
"MYSQL_PASSWORD=docker", | ||
"MYSQL_ROOT_PASSWORD=docker", | ||
]) | ||
.set_ports(vec!["3307:3306"]) | ||
.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::context::Context; | ||
use crate::dc_service::DcService; | ||
use crate::recipes::wp::services::wp_php::WpPhpService; | ||
use crate::recipes::wp::services::WpServices; | ||
use crate::recipes::wp::volumes::WpVolumeMounts; | ||
use crate::recipes::wp::WpRecipe; | ||
use crate::services::Service; | ||
|
||
pub struct WpNginxService; | ||
|
||
impl Service for WpNginxService { | ||
const NAME: &'static str = "nginx"; | ||
const IMAGE: &'static str = "wearejh/nginx:stable-m2"; | ||
|
||
fn dc_service(&self, ctx: &Context, _vars: &()) -> DcService { | ||
let host_port = WpRecipe::ctx_port(&ctx); | ||
DcService::new(ctx.name(), Self::NAME, Self::IMAGE) | ||
.set_depends_on(vec![WpPhpService::NAME]) | ||
.set_volumes(vec![ | ||
format!("{}:{}", ctx.cwd.display(), WpServices::ROOT), | ||
format!( | ||
"{}:{}", | ||
ctx.output_file_path(WpVolumeMounts::NGINX_CONF).display(), | ||
WpVolumeMounts::NGINX_CONF_REMOTE | ||
), | ||
format!( | ||
"{}:{}", | ||
ctx.output_file_path(WpVolumeMounts::NGINX_DEFAULT_HOST) | ||
.display(), | ||
WpVolumeMounts::NGINX_DEFAULT_REMOTE | ||
), | ||
]) | ||
.set_working_dir(WpServices::ROOT) | ||
.set_ports(vec![format!("{}:80", host_port)]) | ||
.finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use crate::context::Context; | ||
use crate::dc_service::DcService; | ||
use crate::recipes::m2::services::php::PhpService; | ||
use crate::recipes::wp::services::wp_db::WpDbService; | ||
use crate::recipes::wp::services::WpServices; | ||
use crate::recipes::wp::WpRecipe; | ||
use crate::services::Service; | ||
|
||
pub struct WpPhpService; | ||
|
||
impl Service for WpPhpService { | ||
const NAME: &'static str = "php"; | ||
const IMAGE: &'static str = PhpService::IMAGE_7_3; | ||
|
||
fn dc_service(&self, ctx: &Context, _vars: &()) -> DcService { | ||
let domain = WpRecipe::ctx_domain(&ctx); | ||
let php_image = (PhpService).select_image(&ctx); | ||
DcService::new(ctx.name(), Self::NAME, php_image) | ||
.set_volumes(vec![format!("{}:{}", ctx.cwd.display(), WpServices::ROOT)]) | ||
.set_depends_on(vec![WpDbService::NAME]) | ||
.set_working_dir(WpServices::ROOT) | ||
.set_environment(vec![ | ||
"XDEBUG_CONFIG=remote_host=host.docker.internal", | ||
&format!("PHP_IDE_CONFIG=serverName={}", domain), | ||
&format!("PHP_MEMORY_LIMIT=\"{}\"", "2G"), | ||
// | ||
// this one is here to prevent needing to modify/change the | ||
// default bedrock setup. | ||
// | ||
&format!("DB_HOST={}", WpDbService::NAME), | ||
]) | ||
.finish() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::dc_service::DcService; | ||
|
||
use crate::php::PHP; | ||
|
||
#[test] | ||
fn test_wp_php_service() { | ||
let ctx = Context::default(); | ||
let actual_dc = (WpPhpService).dc_service(&ctx, &()); | ||
let expected = r#" | ||
name: php | ||
container_name: wf2__wf2_default__php | ||
image: "wearejh/php:7.3-m2" | ||
volumes: | ||
- ".:/var/www" | ||
depends_on: | ||
- db | ||
working_dir: /var/www | ||
environment: | ||
- XDEBUG_CONFIG=remote_host=host.docker.internal | ||
- "PHP_IDE_CONFIG=serverName=localhost:8080" | ||
- "PHP_MEMORY_LIMIT=\"2G\"" | ||
- DB_HOST=db | ||
"#; | ||
let expected_dc: DcService = serde_yaml::from_str(expected).expect("test yaml"); | ||
assert_eq!(actual_dc, expected_dc); | ||
} | ||
|
||
#[test] | ||
fn test_wp_php_with_version_service() { | ||
let ctx = Context { | ||
php_version: PHP::SevenTwo, | ||
..Context::default() | ||
}; | ||
let actual_dc = (WpPhpService).dc_service(&ctx, &()); | ||
let expected = r#" | ||
name: php | ||
container_name: wf2__wf2_default__php | ||
image: "wearejh/php:7.2-m2" | ||
volumes: | ||
- ".:/var/www" | ||
depends_on: | ||
- db | ||
working_dir: /var/www | ||
environment: | ||
- XDEBUG_CONFIG=remote_host=host.docker.internal | ||
- "PHP_IDE_CONFIG=serverName=localhost:8080" | ||
- "PHP_MEMORY_LIMIT=\"2G\"" | ||
- DB_HOST=db | ||
"#; | ||
let expected_dc: DcService = serde_yaml::from_str(expected).expect("test yaml"); | ||
assert_eq!(actual_dc, expected_dc); | ||
} | ||
} |
Oops, something went wrong.