Skip to content

Commit

Permalink
Merge pull request #902 from Automattic/delete_file_permissions
Browse files Browse the repository at this point in the history
[dev-env] Delete file permissions
  • Loading branch information
pschoffer authored Oct 28, 2021
2 parents de1258b + 6fb18bc commit e5a1b97
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 68 deletions.
18 changes: 4 additions & 14 deletions __tests__/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,32 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
} );
describe( 'processComponentOptionInput', () => {
it.each( [
{ // wordpress tag
{ // base tag
param: 5.6,
option: 'wordpress',
allowLocal: true,
expected: {
image: 'ghcr.io/automattic/vip-container-images/wordpress',
mode: 'image',
tag: '5.6',
},
},
{ // wordpress local is not allowed
{ // if local is not allowed
param: '/tmp/wp',
option: 'wordpress',
allowLocal: false,
expected: {
image: 'ghcr.io/automattic/vip-container-images/wordpress',
mode: 'image',
tag: '/tmp/wp',
},
},
{ // muPlugins - path
{ // if local is allowed
param: '~/path',
option: 'muPlugins',
allowLocal: true,
expected: {
mode: 'local',
dir: '~/path',
},
},
] )( 'should process options and use defaults', async input => {
const result = processComponentOptionInput( input.param, input.option, input.allowLocal );
const result = processComponentOptionInput( input.param, input.allowLocal );

expect( result ).toStrictEqual( input.expected );
} );
Expand Down Expand Up @@ -159,17 +154,13 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
mode: 'image',
expected: {
mode: 'image',
image: 'ghcr.io/automattic/vip-container-images/mu-plugins',
tag: 'latest',
},
},
{ // clientCode have just one tag
component: 'clientCode',
mode: 'image',
expected: {
mode: 'image',
image: 'ghcr.io/automattic/vip-container-images/skeleton',
tag: 'latest',
},
},
] )( 'should return correct component %p', async input => {
Expand All @@ -188,7 +179,6 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
tag: '5.6',
expected: {
mode: 'image',
image: 'ghcr.io/automattic/vip-container-images/wordpress',
tag: '5.6',
},
},
Expand Down
15 changes: 6 additions & 9 deletions assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
devtools:
type: compose
services:
image: ghcr.io/automattic/vip-container-images/dev-tools:0.7
image: ghcr.io/automattic/vip-container-images/dev-tools:0.8
command: sleep infinity
volumes:
- devtools:/dev-tools
Expand Down Expand Up @@ -49,9 +49,6 @@ services:
<% wpVolumes() %>
run:
- sh /dev-tools/setup.sh database root "http://<%= siteSlug %>.vipdev.lndo.site/" "<%= wpTitle %>" <% if ( multisite ) { %> <%= siteSlug %>.vipdev.lndo.site <% } %>
run_as_root:
- echo "Copying dev-env-plugin.php to mu-plugins"
- cp /dev-tools/dev-env-plugin.php /wp/wp-content/mu-plugins/

database:
type: compose
Expand Down Expand Up @@ -116,17 +113,17 @@ services:
wordpress:
type: compose
services:
image: <%= wordpress.image %>:<%= wordpress.tag %>
command: sh -c "rsync -a /wp/ /shared/; sleep infinity"
image: ghcr.io/automattic/vip-container-images/wordpress:<%= wordpress.tag %>
command: sh -c "rsync -a /wp/ /shared/; chown www-data -R /shared; sleep infinity"
volumes:
- ./wordpress:/shared

<% if ( muPlugins.mode == 'image' ) { %>
mu-plugins:
type: compose
services:
image: <%= muPlugins.image %>:<%= muPlugins.tag %>
command: sh -c 'rsync -a /mu-plugins/ /shared/; sh /autoupdate.sh /shared'
image: ghcr.io/automattic/vip-container-images/mu-plugins:0.1
command: sh /run.sh
volumes:
- mu-plugins:/shared
volumes:
Expand All @@ -137,7 +134,7 @@ services:
client-code:
type: compose
services:
image: <%= clientCode.image %>:<%= clientCode.tag %>
image: ghcr.io/automattic/vip-container-images/skeleton:latest
command: sleep infinity
volumes:
- clientcode_clientmuPlugins:/clientcode/client-mu-plugins
Expand Down
25 changes: 0 additions & 25 deletions src/lib/constants/dev-environment.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
export const DEV_ENVIRONMENT_SUBCOMMAND = 'dev-env';
export const DEV_ENVIRONMENT_FULL_COMMAND = `vip ${ DEV_ENVIRONMENT_SUBCOMMAND }`;

export const DEV_ENVIRONMENT_CONTAINER_IMAGES = {
wordpress: {
image: 'ghcr.io/automattic/vip-container-images/wordpress',
},
muPlugins: {
image: 'ghcr.io/automattic/vip-container-images/mu-plugins',
tag: 'latest',
},
clientCode: {
image: 'ghcr.io/automattic/vip-container-images/skeleton',
tag: 'latest',
},
};

export const DEV_ENVIRONMENT_DEFAULTS = {
title: 'VIP Dev',
multisite: false,
elasticsearchVersion: '7.10.1',
mariadbVersion: '10.3',
wordpress: {},
muPlugins: {},
clientCode: {},
};

[ 'muPlugins', 'clientCode' ].forEach( type => {
DEV_ENVIRONMENT_DEFAULTS[ type ] = {
mode: 'image',
image: DEV_ENVIRONMENT_CONTAINER_IMAGES[ type ].image,
tag: DEV_ENVIRONMENT_CONTAINER_IMAGES[ type ].tag,
};
} );

export const DEV_ENVIRONMENT_PROMPT_INTRO = 'This is a wizard to help you set up your local dev environment.\n\n' +
'Sensible default values were pre-selected for convenience. ' +
'You may also choose to create multiple environments with different settings using the --slug option.\n\n';
Expand Down
32 changes: 13 additions & 19 deletions src/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import os from 'os';
import {
DEV_ENVIRONMENT_FULL_COMMAND,
DEV_ENVIRONMENT_SUBCOMMAND,
DEV_ENVIRONMENT_CONTAINER_IMAGES,
DEV_ENVIRONMENT_DEFAULTS,
DEV_ENVIRONMENT_PROMPT_INTRO,
DEV_ENVIRONMENT_COMPONENTS,
Expand Down Expand Up @@ -96,7 +95,7 @@ type ComponentConfig = {
tag?: string,
}

export function processComponentOptionInput( passedParam: string, type: string, allowLocal: boolean ): ComponentConfig {
export function processComponentOptionInput( passedParam: string, allowLocal: boolean ): ComponentConfig {
// cast to string
const param = passedParam + '';
if ( allowLocal && param.includes( '/' ) ) {
Expand All @@ -108,7 +107,6 @@ export function processComponentOptionInput( passedParam: string, type: string,

return {
mode: 'image',
image: DEV_ENVIRONMENT_CONTAINER_IMAGES[ type ].image,
tag: param,
};
}
Expand Down Expand Up @@ -175,7 +173,7 @@ async function processComponent( component: string, option: string ) {

const allowLocal = component !== 'wordpress';
if ( option ) {
result = processComponentOptionInput( option, component, allowLocal );
result = processComponentOptionInput( option, allowLocal );
} else {
result = await promptForComponent( component, allowLocal );
}
Expand All @@ -192,7 +190,7 @@ async function processComponent( component: string, option: string ) {
} else {
const message = `Provided path "${ resolvedPath }" does not point to a valid or existing directory.`;
console.log( chalk.yellow( 'Warning:' ), message );
result = await promptForComponent( component );
result = await promptForComponent( component, allowLocal );
}
}

Expand Down Expand Up @@ -241,6 +239,7 @@ const componentDisplayNames = {
};

export async function promptForComponent( component: string, allowLocal: boolean ): Promise<ComponentConfig> {
debug( `Prompting for ${ component }` );
const componentDisplayName = componentDisplayNames[ component ] || component;
const choices = [];

Expand Down Expand Up @@ -288,29 +287,24 @@ export async function promptForComponent( component: string, allowLocal: boolean
}

// image
let tag = DEV_ENVIRONMENT_CONTAINER_IMAGES[ component ].tag;
const componentsWithPredefinedImageTag = [ 'muPlugins', 'clientCode' ];

if ( ! componentsWithPredefinedImageTag.includes( component ) ) {
if ( component === 'wordpress' ) {
const message = `${ messagePrefix }Which version would you like`;
const selectTag = new Select( {
message,
choices: getLatestImageTags( component ),
choices: getWordpressImageTags(),
} );
tag = await selectTag.run();
const tag = await selectTag.run();
return {
mode: modeResult,
tag,
};
}

return {
mode: modeResult,
image: DEV_ENVIRONMENT_CONTAINER_IMAGES[ component ].image,
tag,
};
}

function getLatestImageTags( component: string ): string[] {
if ( component === 'wordpress' ) {
return [ '5.8.1', '5.8', '5.7.3', '5.7.2' ];
}

return [];
function getWordpressImageTags(): string[] {
return [ '5.8.1', '5.8', '5.7.3', '5.7.2' ];
}
8 changes: 7 additions & 1 deletion src/lib/dev-environment/dev-environment-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ export async function destroyEnvironment( slug: string, removeFiles: boolean ) {
throw new Error( 'Environment not found.' );
}

await landoDestroy( instancePath );
const landoFilePath = path.join( instancePath, landoFileName );
if ( fs.existsSync( landoFilePath ) ) {
debug( 'Lando file exists, will lando destroy.' );
await landoDestroy( instancePath );
} else {
debug( "Lando file doesn't exist, skipping lando destroy." );
}

if ( removeFiles ) {
await fs.promises.rm( instancePath, { recursive: true } );
Expand Down

0 comments on commit e5a1b97

Please sign in to comment.