Skip to content

Commit

Permalink
Merge pull request #1329 from Automattic/replace-mailhog-with-mailpit
Browse files Browse the repository at this point in the history
feat(dev-env)!: Replace MailHog with Mailpit
  • Loading branch information
sjinks authored Apr 27, 2023
2 parents fac1f47 + c0eff03 commit 7852214
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 42 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
3 changes: 3 additions & 0 deletions src/bin/vip-dev-env-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
handleCLIException,
processBooleanOption,
validateDependencies,
handleDeprecatedOptions,
} from '../lib/dev-environment/dev-environment-cli';
import {
DEV_ENVIRONMENT_FULL_COMMAND,
Expand Down Expand Up @@ -96,6 +97,8 @@ cmd.argv( process.argv, async ( arg, opt ) => {

debug( 'Args: ', arg, 'Options: ', opt );

handleDeprecatedOptions( opt );

const trackingInfo = {
slug,
app: opt.app,
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
14 changes: 12 additions & 2 deletions src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import chalk from 'chalk';
import { trackEvent } from '../lib/tracker';
import command from '../lib/cli/command';
import { DEV_ENVIRONMENT_FULL_COMMAND, DEV_ENVIRONMENT_NOT_FOUND, DEV_ENVIRONMENT_PHP_VERSIONS } from '../lib/constants/dev-environment';
import { addDevEnvConfigurationOptions, getEnvTrackingInfo, getEnvironmentName, handleCLIException, promptForArguments, validateDependencies } from '../lib/dev-environment/dev-environment-cli';
import {
addDevEnvConfigurationOptions,
getEnvTrackingInfo,
getEnvironmentName,
handleCLIException,
handleDeprecatedOptions,
promptForArguments,
validateDependencies,
} from '../lib/dev-environment/dev-environment-cli';
import type { InstanceOptions } from '../lib/dev-environment/types';
import { doesEnvironmentExist, getEnvironmentPath, readEnvironmentData, updateEnvironment } from '../lib/dev-environment/dev-environment-core';
import { bootstrapLando } from '../lib/dev-environment/dev-environment-lando';
Expand All @@ -42,6 +50,8 @@ cmd.examples( examples );
cmd.argv( process.argv, async ( arg, opt ) => {
const slug = await getEnvironmentName( opt );

handleDeprecatedOptions( opt );

const lando = await bootstrapLando();
await validateDependencies( lando, slug );

Expand Down Expand Up @@ -77,7 +87,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
20 changes: 16 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( [ 'G', '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 Expand Up @@ -711,3 +712,14 @@ export function getEnvTrackingInfo( slug: string ): any {
};
}
}

export function handleDeprecatedOptions( opts: any ): void {
if ( opts.mailhog ) {
console.warn( chalk.yellow( 'Warning: --mailhog is deprecated and will be removed in a future release. Please use --mailpit instead.' ) );
if ( opts.mailpit === undefined ) {
opts.mailpit = opts.mailhog;
}

delete opts.mailhog;
}
}
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 @@ -130,7 +130,7 @@ export function mergeConfigurationFileOptions( preselectedOptions: InstanceOptio
phpmyadmin: configurationFileOptions.phpmyadmin,
xdebug: configurationFileOptions.xdebug,
xdebugConfig: configurationFileOptions[ 'xdebug-config' ],
mailhog: configurationFileOptions.mailhog,
mailpit: configurationFileOptions.mailpit ?? configurationFileOptions.mailhog,
};

const mergedOptions: InstanceOptions = {};
Expand Down
13 changes: 9 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,11 @@ export function readEnvironmentData( slug: string ): InstanceData {
instanceData.appCode = instanceData.clientCode;
}

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

return instanceData;
}

Expand Down
Loading

0 comments on commit 7852214

Please sign in to comment.