Categorygithub.com/Bocmah/phpdocker-gen
module
0.0.0-20210205234250-13057ba107ef
Repository: https://github.com/bocmah/phpdocker-gen.git
Documentation: pkg.go.dev

# README

Build Status codecov Go Report Card

Docker config generator for PHP projects

This tool abstracts away a tedious task of writing docker configuration files for PHP projects. It generates ready-to-use docker config from high-level YAML file.

The input YAML file

This tool consumes a YAML file, which contains a description of services, which are needed for your PHP application and some information about your project.

The following variables can/should be specified at the top indentation level:

NameTypeRequiredDefault valueDescription
appNamestringyes-The name of your application. Can be anything.
projectRootstringyes-Path to your project root.
outputPathstringno.docker folder inside projectRootPath to folder where resulting configuration will be stored.

Example:

appName: awesome-app
projectRoot: /home/user/projects/awesome-project
outputPath: /home/user/awesome-project/custom-folder

You should also specify a list of services services, which will be discussed in the section below.

Services

Services list is the core of the input YAML file. Each service you describe will be mapped to a single docker container.

Currently supported services:

php - maps to a container with php-fpm.

Keys:

NameTypeRequiredDefault valueDescription
versionnumericno7.4PHP version
extensionslistno[mbstring, zip, exif, pcntl, gd]PHP extensions

Note: extensions key is experimental. Not all extensions may install correctly.

Example:

php:
  version: 7.4
  extensions:
    - redis
    - xdebug

nginx - maps to a container with nginx.

Keys:

NameTypeRequiredDefault valueDescription
httpPortintegerno80nginx will use this port for listening for HTTP requests
httpsPortintegerno443nginx will use this port for listening for HTTPS requests
serverNamestringyes-The hostname. The app will be navigable through the web using the value of server name followed by .test
fastCGI.passPortintegerno9000This port will be used for connecting nginx and php-fpm
fastCGI.readTimeoutSecondsintegerno60How long nginx will wait for response from php-fpm before timing out with 504 error
nginx:
  httpPort: 81
  serverName: awesome-app
  fastCGI:
    passPort: 9001
    readTimeoutSeconds: 30

nodejs - maps to a container with Node.js.

Keys:

NameTypeRequiredDefault valueDescription
versionnumeric|stringnolatestNode.js version

Example:

nodejs:
  version: 10

database - maps to a container with database.

Keys:

NameTypeRequiredDefault valueDescription
systemenum(mysql|postgresql)yes-Database system in use
versionnumericno8.0 for mysql 12.3 for postgresqlDatabase version
namestringno-If specified, database with name will be created on image startup
portintegerno3306 for mysql 5432 for postgresqlDatabase port
usernamestringno-If specified, user with username will be created with superuser power
passwordstringrequired for postgresql-Sets the superuser password if system in use is postgresql or a password for username if system is mysql
rootPasswordstringrequired for mysql-Sets the superuser password if system in use is mysql

Example:

database:
  system: mysql
  version: 5.7
  name: test-db
  port: 3306
  username: joe
  password: test
  rootPassword: testRoot

Sometimes you may wish to use a service but all keys are optional, and you want to leave default values. In this case you should specify a service as an empty object:

nodejs: {}

Full example file

appName: awesome-app
projectRoot: /home/user/joe/projects/awesome-app
outputPath: /home/user/joe/projects/awesome-app/docker-config
services:
  php:
    version: 7.4
    extensions:
      - redis
      - xdebug
  nginx:
    httpPort: 81
    serverName: 
    fastCGI:
      passPort: 9001
      readTimeoutSeconds: 30
  nodejs:
    version: 10
  database:
    system: mysql
    version: 5.7
    name: test-db
    port: 3306
    username: bocmah
    password: test
    rootPassword: testRoot

Using the above file the tool will create a set of Docker configuration files inside /home/user/joe/projects/awesome-app/docker-config. Final configuration will consist of four docker containers:

  1. Php-fpm container with PHP 7.4
  2. Nginx container listening on ports 81 and 9001 for HTTP and HTTPS ports respectively.
  3. Container with Node.js v10.
  4. MySQL container.

Prerequisites

To run the tool, you should have Go 1.15+ installed. You will also need Docker and Docker Compose for running output configuration.

Installation

The following command will download and install the code as a binary.

$ go get github.com/Bocmah/phpdocker-gen/...

Note: The location of Go binaries depends on Go environment variables GOPATH and GOBIN. If you want to use the binary without specifying its fullpath, you should export the location of Go binaries to your PATH. If you've just installed Go and didn't make any changes to Go env variables this command should work:

$ export PATH=$PATH:$(go env GOPATH)/bin

Usage

$ phpdocker-gen -file <path_to_input_file>

You can use either an absolute path to input file or a path relative to current working directory.

# Packages

No description provided by the author
No description provided by the author