Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setup): missing nginx's config and snippets directories #1822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion extensions/nginx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class NginxExtension extends Extension {
port: instance.config.get('server.port')
});

await this.ui.sudo(`mkdir -p ${nginxConfigPath}/sites-available ${nginxConfigPath}/sites-enabled`);
await this.template(instance, generatedConfig, 'nginx config', confFile, `${nginxConfigPath}/sites-available`);
await this.ui.sudo(`ln -sf ${nginxConfigPath}/sites-available/${confFile} ${nginxConfigPath}/sites-enabled/${confFile}`);
await this.restartNginx();
Expand Down Expand Up @@ -172,7 +173,10 @@ class NginxExtension extends Extension {
}, {
title: 'Generating Encryption Key (may take a few minutes)',
skip: () => fs.existsSync(dhparamFile),
task: errorWrapper(() => this.ui.sudo(`openssl dhparam -dsaparam -out ${dhparamFile} 2048`))
task: errorWrapper(async () => {
await this.ui.sudo(`mkdir -p ${nginxConfigPath}/snippets`);
await this.ui.sudo(`openssl dhparam -dsaparam -out ${dhparamFile} 2048`);
})
}, {
title: 'Generating SSL security headers',
skip: () => fs.existsSync(sslParamsFile),
Expand Down
18 changes: 12 additions & 6 deletions extensions/nginx/test/extension-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ describe('Unit: Extensions > Nginx', function () {

it('Generates the proper config', async function () {
const name = 'ghost.dev.conf';
const mkdirExp = new RegExp(`(?=^mkdir -p)(?=.*available)(?=.*enabled$)`);
const lnExp = new RegExp(`(?=^ln -sf)(?=.*available/${name})(?=.*enabled/${name}$)`);
const expectedConfig = {
url: 'ghost.dev',
Expand All @@ -236,8 +237,9 @@ describe('Unit: Extensions > Nginx', function () {
expect(templateStub.calledOnce).to.be.true;
expect(loadStub.calledOnce).to.be.true;
expect(loadStub.args[0][0]).to.deep.equal(expectedConfig);
expect(sudo.calledOnce).to.be.true;
expect(sudo.args[0][0]).to.match(lnExp);
expect(sudo.calledTwice).to.be.true;
expect(sudo.args[0][0]).to.match(mkdirExp);
expect(sudo.args[1][0]).to.match(lnExp);
expect(ext.restartNginx.calledOnce).to.be.true;

// Testing handling of subdirectory installations
Expand All @@ -253,6 +255,7 @@ describe('Unit: Extensions > Nginx', function () {

it('passes the error if it\'s already a CliError', async function () {
const name = 'ghost.dev.conf';
const mkdirExp = new RegExp(`(?=^mkdir -p)(?=.*available)(?=.*enabled$)`);
const lnExp = new RegExp(`(?=^ln -sf)(?=.*available/${name})(?=.*enabled/${name}$)`);
const loadStub = sinon.stub().returns('nginx config file');
const templateStub = sinon.stub().returns(loadStub);
Expand All @@ -276,8 +279,9 @@ describe('Unit: Extensions > Nginx', function () {
expect(error.message).to.be.equal('Did not restart');
expect(templateStub.calledOnce).to.be.true;
expect(loadStub.calledOnce).to.be.true;
expect(sudo.calledOnce).to.be.true;
expect(sudo.args[0][0]).to.match(lnExp);
expect(sudo.calledTwice).to.be.true;
expect(sudo.args[0][0]).to.match(mkdirExp);
expect(sudo.args[1][0]).to.match(lnExp);
expect(ext.restartNginx.calledOnce).to.be.true;
return;
}
Expand Down Expand Up @@ -427,15 +431,17 @@ describe('Unit: Extensions > Nginx', function () {
});

it('Uses OpenSSL (and skips if already exists)', function () {
const mkdirExp = new RegExp(`(?=^mkdir -p)(?=.*snippets$)`);
proxy['fs-extra'].existsSync = () => true;
const ext = proxyNginx(proxy);
const tasks = getTasks(ext);

expect(tasks[4].skip()).to.be.true;

return tasks[4].task().then(() => {
expect(ext.ui.sudo.calledOnce).to.be.true;
expect(ext.ui.sudo.args[0][0]).to.match(/openssl dhparam/);
expect(ext.ui.sudo.calledTwice).to.be.true;
expect(ext.ui.sudo.args[0][0]).to.match(mkdirExp);
expect(ext.ui.sudo.args[1][0]).to.match(/openssl dhparam/);
});
});

Expand Down