Skip to content

Commit

Permalink
feat(commands): support Lumen projects
Browse files Browse the repository at this point in the history
Add support for Lumen projects.

fix golevelup#8
  • Loading branch information
osiux committed Feb 27, 2020
1 parent 58505dd commit 781c803
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Unlike other tools in the ecosystem like Laradock and Vessel, the container imag
- [x] Automatically configures XDebug
- [x] Supports MySQL and Postgres environments
- [x] Automatically configures Laravel ENV to connect to services in the Docker network
- [x] Support both Laravel and Lumen projects

# CLI

Expand Down
2 changes: 1 addition & 1 deletion environment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
app:
build:
context: ./
dockerfile: environment/dockerfiles/app.dockerfile
dockerfile: environment/dockerfiles/laravel.dockerfile
args:
xdebug: "true"
tinker: "true"
Expand Down
38 changes: 38 additions & 0 deletions environment/resources/dockerfiles/lumen.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM php:7.3.6-fpm-stretch

ARG xdebug=false

WORKDIR /var/www

# These are considered sane defaults for the cloud deployments
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
PHP_OPCACHE_MAX_ACCELERATED_FILES="100000" \
PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10" \
PHP_XDEBUG_DEFAULT_ENABLE="0" \
PHP_XDEBUG_REMOTE_ENABLE="0"

RUN docker-php-ext-install opcache

# <DB_DRIVERS>

# Conditionally install the necessary components to allow XDebug
RUN if [ "$xdebug" = "true" ] ; then pecl install xdebug && docker-php-ext-enable xdebug ; else echo Running app without XDEBUG ; fi

COPY vendor/ ./vendor/
COPY artisan composer.json composer.lock ./

COPY app/ ./app/
COPY bootstrap/ ./bootstrap/
COPY database/ ./database/
COPY public/ ./public/
COPY resources/ ./resources/
COPY routes/ ./routes/
COPY storage/ ./storage/

COPY environment/config/php/conf.d/*.ini /usr/local/etc/php/conf.d/
COPY environment/config/fpm/*.conf /usr/local/etc/php-fpm.d/

RUN chmod -R 777 /var/www/storage
RUN chmod -R 777 /var/www/bootstrap

16 changes: 12 additions & 4 deletions src/actions/dockerfile-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { replaceFileContent } from "./utility";
import { join } from "path";
import { DB_DRIVER_REPLACE_STRING } from "../constants";

export const pSqlDriverInstall = async (projectPath: string) => {
type ProjectType = "lumen" | "laravel";

export const pSqlDriverInstall = async (
projectPath: string,
projectType: ProjectType
) => {
const srcAppDockerFile = join(
projectPath,
"environment/dockerfiles/app.dockerfile"
`environment/dockerfiles/${projectType}.dockerfile`
);
const replaceArgs = [
DB_DRIVER_REPLACE_STRING,
Expand All @@ -18,10 +23,13 @@ export const pSqlDriverInstall = async (projectPath: string) => {
await replaceFileContent(srcAppDockerFile, replaceArgs);
};

export const mysqlDriverInstall = async (projectPath: string) => {
export const mysqlDriverInstall = async (
projectPath: string,
projectType: ProjectType
) => {
const srcAppDockerFile = join(
projectPath,
"environment/dockerfiles/app.dockerfile"
`environment/dockerfiles/${projectType}.dockerfile`
);
const replaceArgs = [
DB_DRIVER_REPLACE_STRING,
Expand Down
15 changes: 14 additions & 1 deletion src/actions/prompt-environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as inquirer from "inquirer";
import { MYSQL, POSTGRES } from "../constants";
import { MYSQL, POSTGRES, LARAVEL, LUMEN } from "../constants";

type ThenArg<T> = T extends Promise<infer U> ? U : T;
export type PromptEnvironmentDef = ThenArg<
Expand All @@ -8,6 +8,19 @@ export type PromptEnvironmentDef = ThenArg<

export const promptEnvironment = async () => {
const dbPrompt = await inquirer.prompt([
{
name: "projectType",
message: "What type of project you want to create?",
type: "list",
choices: [
{
name: LARAVEL
},
{
name: LUMEN
}
]
},
{
name: "webPort",
message: "What port would you like the app to be hosted on locally?",
Expand Down
18 changes: 14 additions & 4 deletions src/actions/publish-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import * as jsyaml from "js-yaml";
import * as path from "path";
import * as shelljs from "shelljs";
import { PromptEnvironmentDef, readFileAsync, writeFileAsync } from ".";
import { POSTGRES } from "../constants";
import { POSTGRES, LARAVEL } from "../constants";
import {
DbServiceConfig,
makeMySqlService,
makePostgresService
} from "../services";
import { mysqlDriverInstall, pSqlDriverInstall } from "./dockerfile-config";
import { UpEnvironmentConfig } from "../types";
import { resolvePath } from "./utility";

export const publishEnvironment = async (
location: string,
Expand All @@ -22,7 +23,10 @@ export const publishEnvironment = async (
const sourceEnvPath = path.join(baseEnvPath, "resources");

const dockerComposeContents = await readFileAsync(srcDockerComposePath);
shelljs.cd(location);

const realLocation = resolvePath(location);

shelljs.cd(realLocation);

const fullProjectPath = shelljs.pwd().toString();

Expand All @@ -48,14 +52,20 @@ export const publishEnvironment = async (
switch (envConfig.engine) {
case POSTGRES:
dbService = makePostgresService(dbConfig);
await pSqlDriverInstall(location);
await pSqlDriverInstall(realLocation, envConfig.projectType);
break;
default:
dbService = makeMySqlService(dbConfig);
await mysqlDriverInstall(location);
await mysqlDriverInstall(realLocation, envConfig.projectType);
break;
}

if (envConfig.projectType !== LARAVEL) {
composeYaml["services"]["app"]["build"][
"dockerfile"
] = `environment/dockerfiles/${envConfig.projectType}.dockerfile`;
}

if (envConfig.webPort != 8080) {
composeYaml["services"]["web"]["ports"][0] = `${envConfig.webPort}:80`;
}
Expand Down
12 changes: 12 additions & 0 deletions src/actions/utility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from "chalk";
import * as fs from "fs";
import * as shelljs from "shelljs";
import * as os from "os";
import { promisify } from "util";

export const readFileAsync = promisify(fs.readFile);
Expand Down Expand Up @@ -34,3 +35,14 @@ export const replaceFileContent = async (
.replace(replaceArgs[0], replaceArgs[1]);
await writeFileAsync(filePath, newContent);
};

/**
* From https://stackoverflow.com/a/57243075/717643
*/
export const resolvePath = (filePath: string) => {
// '~/folder/path' or '~'
if (filePath[0] === "~" && (filePath[1] === "/" || filePath.length === 1)) {
return filePath.replace("~", os.homedir());
}
return filePath;
};
4 changes: 3 additions & 1 deletion src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default class New extends BaseCommand {
shelljs.exec(
`docker container run --rm ${
!this.config.windows ? "--user $(id -u):$(id -g)" : ""
} -v ${directory}:/app composer create-project --prefer-dist laravel/laravel ${projectName}`,
} -v ${directory}:/app composer create-project --prefer-dist laravel/${
dbPrompt.projectType
} ${projectName}`,
{ silent: !flags.verbose }
);

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const MARIA = "MariaDb";
export const DOCKER_DB_CONFIG_INJECT = "DOCKER_DB_CONFIG_INJECT";
export const VERBOSE_DESCRIPTION = "Include additional diagnostic logs";
export const DB_DRIVER_REPLACE_STRING = "# <DB_DRIVERS>";
export const LARAVEL = "laravel";
export const LUMEN = "lumen";

0 comments on commit 781c803

Please sign in to comment.