Skip to content

Commit

Permalink
feat(dev-env)!: Replace MailHog with Mailpit
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Apr 10, 2023
1 parent e20535e commit f45a098
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/devenv-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Preload Docker images
run: |
vip dev-env create --app-code image --php 8.0 --mu-plugins image -e false -p true --mailhog true && \
vip dev-env create --app-code image --php 8.0 --mu-plugins image -e false -p true --mailpit true && \
vip dev-env start -w && \
vip dev-env destroy
Expand Down
10 changes: 5 additions & 5 deletions __tests__/devenv-e2e/001-create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe( 'vip dev-env create', () => {
const expectedElasticsearch = false;
const expectedPhpMyAdmin = false;
const expectedXDebug = false;
const expectedMailHog = false;
const expectedMailpit = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -91,7 +91,7 @@ describe( 'vip dev-env create', () => {
wordpress: expect.objectContaining( { mode: 'image', tag: expect.any( String ) } ),
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );
} );

Expand All @@ -104,7 +104,7 @@ describe( 'vip dev-env create', () => {
const expectedElasticsearch = true;
const expectedPhpMyAdmin = true;
const expectedXDebug = true;
const expectedMailHog = true;
const expectedMailpit = true;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -121,7 +121,7 @@ describe( 'vip dev-env create', () => {
'-e', `${ expectedElasticsearch }`,
'-p', `${ expectedPhpMyAdmin }`,
'-x', `${ expectedXDebug }`,
'--mailhog', `${ expectedMailHog }`,
'-A', `${ expectedMailpit }`,
], { env }, true );
expect( result.rc ).toBe( 0 );
expect( await checkEnvExists( slug ) ).toBe( true );
Expand All @@ -140,7 +140,7 @@ describe( 'vip dev-env create', () => {
wordpress: expect.objectContaining( { mode: 'image', tag: expectedWordPressVersion } ),
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );
} );
} );
14 changes: 7 additions & 7 deletions __tests__/devenv-e2e/005-update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe( 'vip dev-env update', () => {
const expectedElasticsearch = false;
const expectedPhpMyAdmin = false;
const expectedXDebug = false;
const expectedMailHog = false;
const expectedMailpit = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -82,7 +82,7 @@ describe( 'vip dev-env update', () => {
elasticsearch: expectedElasticsearch,
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );

result = await cliTest.spawn( [
Expand All @@ -91,7 +91,7 @@ describe( 'vip dev-env update', () => {
'-e', `${ ! expectedElasticsearch }`,
'-p', `${ ! expectedPhpMyAdmin }`,
'-x', `${ ! expectedXDebug }`,
'--mailhog', `${ ! expectedMailHog }`,
'-A', `${ ! expectedMailpit }`,
], { env }, true );
expect( result.rc ).toBe( 0 );
expect( await checkEnvExists( slug ) ).toBe( true );
Expand All @@ -102,7 +102,7 @@ describe( 'vip dev-env update', () => {
elasticsearch: ! expectedElasticsearch,
phpmyadmin: ! expectedPhpMyAdmin,
xdebug: ! expectedXDebug,
mailhog: ! expectedMailHog,
mailpit: ! expectedMailpit,
} );
} );

Expand Down Expand Up @@ -166,19 +166,19 @@ describe( 'vip dev-env update', () => {
const result = await cliTest.spawn( [
process.argv[ 0 ], vipDevEnvUpdate,
'--slug', slug,
'--mailhog', 'true',
'--mailpit', 'true',
], { env }, true );
expect( result.rc ).toBe( 0 );

const dataAfter = readEnvironmentData( slug );
expect( dataAfter ).toMatchObject( {
mariadb: expect.any( String ),
mailhog: true,
mailpit: true,
} );

const landofile = await readFile( dst[ 1 ], 'utf8' );
expect( landofile ).not.toContain( 'image: mysql:' );
expect( landofile ).toContain( 'image: mariadb:' );
expect( landofile ).toContain( 'mailhog:' );
expect( landofile ).toContain( 'mailpit:' );
} );
} );
16 changes: 8 additions & 8 deletions __tests__/devenv-e2e/011-configuration-file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe( 'vip dev-env configuration file', () => {
const expectedElasticsearch = true;
const expectedPhpMyAdmin = true;
const expectedXDebug = true;
const expectedMailHog = true;
const expectedMailpit = true;

expect( await checkEnvExists( expectedSlug ) ).toBe( false );

Expand All @@ -123,7 +123,7 @@ describe( 'vip dev-env configuration file', () => {
elasticsearch: expectedElasticsearch,
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
'mu-plugins': 'image',
'app-code': 'image',
} );
Expand Down Expand Up @@ -152,7 +152,7 @@ describe( 'vip dev-env configuration file', () => {
wordpress: expect.objectContaining( { mode: 'image', tag: expectedWordPressVersion } ),
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );

return expect( checkEnvExists( expectedSlug ) ).resolves.toBe( true );
Expand All @@ -163,7 +163,7 @@ describe( 'vip dev-env configuration file', () => {
const expectedElasticsearch = false;
const expectedPhpMyAdmin = false;
const expectedXDebug = false;
const expectedMailHog = false;
const expectedMailpit = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -174,7 +174,7 @@ describe( 'vip dev-env configuration file', () => {
elasticsearch: expectedElasticsearch,
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );

const spawnOptions = {
Expand All @@ -192,7 +192,7 @@ describe( 'vip dev-env configuration file', () => {
elasticsearch: expectedElasticsearch,
phpmyadmin: expectedPhpMyAdmin,
xdebug: expectedXDebug,
mailhog: expectedMailHog,
mailpit: expectedMailpit,
} );

// Update environment from changed configuration file
Expand All @@ -202,7 +202,7 @@ describe( 'vip dev-env configuration file', () => {
elasticsearch: ! expectedElasticsearch,
phpmyadmin: ! expectedPhpMyAdmin,
xdebug: ! expectedXDebug,
mailhog: ! expectedMailHog,
mailpit: ! expectedMailpit,
} );

result = await cliTest.spawn( [ process.argv[ 0 ], vipDevEnvUpdate ], spawnOptions, true );
Expand All @@ -215,7 +215,7 @@ describe( 'vip dev-env configuration file', () => {
elasticsearch: ! expectedElasticsearch,
phpmyadmin: ! expectedPhpMyAdmin,
xdebug: ! expectedXDebug,
mailhog: ! expectedMailHog,
mailpit: ! expectedMailpit,
} );
} );
} );
2 changes: 1 addition & 1 deletion __tests__/e2e_test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rem dev-env tests

echo "== Creating dev-env"

call vip dev-env create --app-code image --title Test --multisite false --php 8.0 --wordpress 6.0 --mu-plugins image -e false -p false -x false --mailhog false
call vip dev-env create --app-code image --title Test --multisite false --php 8.0 --wordpress 6.0 --mu-plugins image -e false -p false -x false --mailpit false

if NOT %errorlevel% == 0 (
echo "== Failed to create dev-env"
Expand Down
18 changes: 15 additions & 3 deletions assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ proxy:
<% } %>
phpmyadmin:
- <%= siteSlug %>-pma.vipdev.lndo.site
mailpit:
- <%= siteSlug %>-mailpit.vipdev.lndo.site:8025

services:
devtools:
Expand Down Expand Up @@ -197,9 +199,19 @@ services:
clientcode_vipconfig: {}
<% } %>

<% if ( mailhog ) { %>
mailhog:
type: mailhog
<% if ( mailpit ) { %>
mailpit:
type: compose
services:
image: axllent/mailpit:latest
command: /mailpit
ports:
- ":1025"
- ":8025"
environment:
LANDO_NO_USER_PERMS: 1
LANDO_NO_SCRIPTS: 1
LANDO_NEEDS_EXEC: 1
<% } %>

tooling:
Expand Down
1 change: 1 addition & 0 deletions src/bin/vip-dev-env-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const userMap = {
elasticsearch: 'elasticsearch',
phpmyadmin: 'www-data',
mailhog: 'mailhog',
mailpit: 'root',
};

const examples = [
Expand Down
2 changes: 1 addition & 1 deletion src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ cmd.argv( process.argv, async ( arg, opt ) => {
mariadb: currentInstanceData.mariadb,
phpmyadmin: currentInstanceData.phpmyadmin,
xdebug: currentInstanceData.xdebug,
mailhog: currentInstanceData.mailhog,
mailpit: currentInstanceData.mailpit ?? currentInstanceData.mailhog,
mediaRedirectDomain: currentInstanceData.mediaRedirectDomain,
multisite: false,
title: '',
Expand Down
9 changes: 5 additions & 4 deletions src/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ export async function promptForArguments( preselectedOptions: InstanceOptions, d
xdebug: false,
xdebugConfig: preselectedOptions.xdebugConfig,
siteSlug: '',
mailhog: false,
mailpit: false,
};

const promptLabels = {
xdebug: 'XDebug',
phpmyadmin: 'phpMyAdmin',
mailhog: 'MailHog',
mailpit: 'Mailpit',
};

if ( ! instanceData.mediaRedirectDomain && defaultOptions.mediaRedirectDomain ) {
Expand Down Expand Up @@ -354,7 +354,7 @@ export async function promptForArguments( preselectedOptions: InstanceOptions, d
instanceData.elasticsearch = await promptForBoolean( 'Enable Elasticsearch (needed by Enterprise Search)?', !! defaultOptions.elasticsearch );
}

for ( const service of [ 'phpmyadmin', 'xdebug', 'mailhog' ] ) {
for ( const service of [ 'phpmyadmin', 'xdebug', 'mailpit' ] ) {
if ( service in instanceData ) {
if ( service in preselectedOptions ) {
instanceData[ service ] = preselectedOptions[ service ];
Expand Down Expand Up @@ -639,7 +639,8 @@ export function addDevEnvConfigurationOptions( command: Command ): any {
.option( 'elasticsearch', 'Enable Elasticsearch (needed by Enterprise Search)', undefined, processBooleanOption )
.option( [ 'r', 'media-redirect-domain' ], 'Domain to redirect for missing media files. This can be used to still have images without the need to import them locally.' )
.option( 'php', 'Explicitly choose PHP version to use', undefined, processVersionOption )
.option( [ 'A', 'mailhog' ], 'Enable MailHog. By default it is disabled', undefined, processBooleanOption );
.option( [ 'A', 'mailhog' ], 'Enable Mailpit. By default it is disabled (deprecated option, please use --mailpit instead)', undefined, processBooleanOption )
.option( [ 'A', 'mailpit' ], 'Enable Mailpit. By default it is disabled', undefined, processBooleanOption );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/dev-environment/dev-environment-configuration-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function sanitizeConfiguration( configuration: Object ): Promise<Configura
elasticsearch: stringToBooleanIfDefined( configuration.elasticsearch ),
phpmyadmin: stringToBooleanIfDefined( configuration.phpmyadmin ),
xdebug: stringToBooleanIfDefined( configuration.xdebug ),
mailhog: stringToBooleanIfDefined( configuration.mailhog ),
mailpit: stringToBooleanIfDefined( configuration.mailpit ?? configuration.mailhog ),
};

// Remove undefined values
Expand All @@ -129,7 +129,7 @@ export function mergeConfigurationFileOptions( preselectedOptions: InstanceOptio
elasticsearch: configurationFileOptions.elasticsearch,
phpmyadmin: configurationFileOptions.phpmyadmin,
xdebug: configurationFileOptions.xdebug,
mailhog: configurationFileOptions.mailhog,
mailpit: configurationFileOptions.mailpit ?? configurationFileOptions.mailhog,
};

const mergedOptions: InstanceOptions = {};
Expand Down
12 changes: 8 additions & 4 deletions src/lib/dev-environment/dev-environment-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData {
newInstanceData.phpmyadmin = false;
}

// Mailhog migration
if ( ! newInstanceData.mailhog ) {
newInstanceData.mailhog = false;
// Mailpit migration
if ( ! newInstanceData.mailpit ) {
newInstanceData.mailpit = newInstanceData.mailhog ?? false;
}

// MariaDB migration
Expand Down Expand Up @@ -261,7 +261,7 @@ export async function showLogs( lando: Lando, slug: string, options: any = {} ):
debug( 'Instance path for', slug, 'is:', instancePath );

if ( options.service ) {
const appInfo = await landoInfo( lando, instancePath );
const appInfo = await landoInfo( lando, instancePath, false );
if ( ! appInfo.services.includes( options.service ) ) {
throw new UserError( `Service '${ options.service }' not found. Please choose from one: ${ appInfo.services }` );
}
Expand Down Expand Up @@ -350,6 +350,10 @@ export function readEnvironmentData( slug: string ): InstanceData {
instanceData.appCode = instanceData.clientCode;
}

if ( instanceData.mailhog ) {
instanceData.mailpit = instanceData.mailhog;
}

return instanceData;
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/dev-environment/dev-environment-lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async function getLandoConfig() {
],
disablePlugins: [
'@lando/argv',
'@lando/mailhog',
],
proxyName: 'vip-dev-env-proxy',
userConfRoot: landoDir,
Expand Down Expand Up @@ -360,6 +361,10 @@ const extraServiceDisplayConfiguration = [
name: 'mailhog',
skip: true,
},
{
name: 'mailpit',
skip: true,
},
];

async function getExtraServicesConnections( lando: Lando, app: App ): Promise<Record<string, string>> {
Expand Down
13 changes: 8 additions & 5 deletions src/lib/dev-environment/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ export interface InstanceOptions {
muPlugins?: string;
appCode?: string;
elasticsearch?: boolean;
mariadb?: string;
mariadb?: string; // Legacy
php?: string;
mediaRedirectDomain?: string;
phpmyadmin?: boolean;
xdebug?: boolean;
xdebugConfig?: string;
mailhog?: boolean;
mailhog?: boolean; // Legacy
mailpit?: boolean;

[index: string]: string | boolean;
}
Expand Down Expand Up @@ -65,7 +66,8 @@ export type ConfigurationFileOptions = {
elasticsearch?: boolean;
phpmyadmin?: boolean;
xdebug?: boolean;
mailhog?: boolean;
mailhog?: boolean; // Legacy
mailpit?: boolean;
}

export interface InstanceData {
Expand All @@ -79,10 +81,11 @@ export interface InstanceData {
phpmyadmin: boolean;
xdebug: boolean;
xdebugConfig?: string;
mariadb?: string;
mariadb?: string; // Legacy
php: string;
elasticsearch?: string | boolean;
mailhog: boolean;
mailhog?: boolean; // Legacy
mailpit: boolean;
pullAfter?: number;

[index: string]: WordPressConfig | ComponentConfig | string | boolean;
Expand Down

0 comments on commit f45a098

Please sign in to comment.