From 88e7d39ebd16e62676d0f686a53db795d7569ab6 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:08:59 -0400 Subject: [PATCH 01/15] build: add super linter --- .github/workflows/linter.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..83b054d --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,20 @@ +--- +name: Lint Code Base +on: push + +jobs: + build: + name: Lint Code Base + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Lint Code Base + uses: github/super-linter/slim@v4 + env: + VALIDATE_ALL_CODEBASE: true + DEFAULT_BRANCH: master + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c3554d5549c14c90413dbd074c18145cc8861d6d Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:11:08 -0400 Subject: [PATCH 02/15] docs: add badge to readme for linter --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 911fbb0..a768ecb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Sourcetoad Internal Development Tools (SIDT) +[![GitHub Super-Linter](https://github.com/sourcetoad/DevopsToolKit/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter) + Sourcetoad Internal Development Tools includes a growing collection of tutorials for managing IDEs, hooking up tools with Docker and any combination of those things. From a33f82dc638d7b6bf60c5c2b0016a29431b07a16 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:15:07 -0400 Subject: [PATCH 03/15] fix: bash linting fixes --- docker/data-source-services/network-creation.sh | 1 + scripts/db_migrate.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/data-source-services/network-creation.sh b/docker/data-source-services/network-creation.sh index 9664368..27c1862 100755 --- a/docker/data-source-services/network-creation.sh +++ b/docker/data-source-services/network-creation.sh @@ -1,2 +1,3 @@ +#!/usr/bin/env bash echo "Creating container networks:\n" docker network create st-internal diff --git a/scripts/db_migrate.sh b/scripts/db_migrate.sh index f7f5892..bb58135 100755 --- a/scripts/db_migrate.sh +++ b/scripts/db_migrate.sh @@ -35,7 +35,7 @@ case $DB_MODE in fi echo -n "Copying...! $NEWLINE" - mysqldump $DB_EXPORT_FLAGS --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --port="${DB_PORT}" "${DB_NAME}" | mysql $DB_IMPORT_FLAGS --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --port="${DB_TO_PORT}" "${DB_TO_NAME}" + mysqldump "$DB_EXPORT_FLAGS" --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --port="${DB_PORT}" "${DB_NAME}" | mysql "$DB_IMPORT_FLAGS" --user="${DB_USER}" --password="${DB_PASS}" --host="${DB_HOST}" --port="${DB_TO_PORT}" "${DB_TO_NAME}" echo -n "Copied...! $NEWLINE" ;; From 0974888d20cc065d759b87ede670d5517aa9c0ee Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:34:13 -0400 Subject: [PATCH 04/15] build: add linter configuration flags --- .hadolint.yaml | 3 +++ .markdown-lint.yml | 1 + 2 files changed, 4 insertions(+) create mode 100644 .hadolint.yaml create mode 100644 .markdown-lint.yml diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 0000000..047d737 --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,3 @@ +ignored: + - DL3008 + - DL3059 diff --git a/.markdown-lint.yml b/.markdown-lint.yml new file mode 100644 index 0000000..7244343 --- /dev/null +++ b/.markdown-lint.yml @@ -0,0 +1 @@ +MD025: false From 734b1c9f87aa117600d110e79e30d5a8411aaa5e Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:34:21 -0400 Subject: [PATCH 05/15] fix: markdown linting fixes --- CHANGELOG.md | 36 +++++----- DOCKER_TIPS.md | 8 ++- README.md | 26 ++++---- docs/nginx-proxy/README.md | 7 +- docs/phpstorm-docker/README.md | 117 +++++++++++++++------------------ docs/yii2/yii-shell.md | 23 ++++--- 6 files changed, 104 insertions(+), 113 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4ef61..d658762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,29 +1,29 @@ # v1.3.0 (November 9, 2020) - * Retire non `st-internal` network names (not yet removed). - * Remove outdated python and upsource documentation. - * Move yii2-shell docs into /docs - * Add `./scripts/db_migrate` for moving databases between versions of database. - * Update docker templates for latest php74 packages/versions. +* Retire non `st-internal` network names (not yet removed). +* Remove outdated python and upsource documentation. +* Move yii2-shell docs into /docs +* Add `./scripts/db_migrate` for moving databases between versions of database. +* Update docker templates for latest php74 packages/versions. # v1.2.1 (June 9, 2020) - * Added PostgreSQL v9.4 +* Added PostgreSQL v9.4 # v1.2.0 (March 6, 2020) - * Removed mysql56 - * Deprecated networks that aren't "st-internal" - * Added MariaDB10.3 - * Added MariaDB10.4 - * Added optional phpMyAdmin +* Removed mysql56 +* Deprecated networks that aren't "st-internal" +* Added MariaDB10.3 +* Added MariaDB10.4 +* Added optional phpMyAdmin # v1.1.1 (August 16, 2019) - * Removed d4m guide. - * Updated Laravel docker container to Node10 (previously Node8) - * Updated Yii2/Laravel scripts to leverage "st-internal" network - * Removed all unchanged php.ini files for both Yii2/Laravel +* Removed d4m guide. +* Updated Laravel docker container to Node10 (previously Node8) +* Updated Yii2/Laravel scripts to leverage "st-internal" network +* Removed all unchanged php.ini files for both Yii2/Laravel # v1.1.0 (Oct 1, 2018) - * [Breaking] Removed MariaDB10.1 - * Added MariaDB10.2 +* [Breaking] Removed MariaDB10.1 +* Added MariaDB10.2 # v1.0.0 (July 5, 2018) - * Initial release +* Initial release diff --git a/DOCKER_TIPS.md b/DOCKER_TIPS.md index a81b1b1..d2c931f 100644 --- a/DOCKER_TIPS.md +++ b/DOCKER_TIPS.md @@ -1,3 +1,5 @@ +# Docker Tips + ## Typical Docker Commands ### Start all environments services > docker-compose up --build @@ -27,12 +29,12 @@ > password: mariadb_pass -## Running Xdebug with PHPStorm alongside Docker. +## Running Xdebug with PHPStorm alongside Docker From Docker versions 18.03 and above, Docker creates a special DNS name that resolves to the internal IP address used by the host. -Old logic (that has not updated to special DNS name) will need to point to the IP of `10.254.254.254`. +* Old logic (that has not updated to special DNS name) will need to point to the IP of `10.254.254.254`. -``` +```bash sudo ifconfig lo0 alias 10.254.254.254 ``` diff --git a/README.md b/README.md index a768ecb..973c0dd 100644 --- a/README.md +++ b/README.md @@ -27,22 +27,22 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d ``` #### Specific Setup - Windows - * Kill, and optionally disable, the `World Wide Web Publishing Service` - * Run `set COMPOSE_CONVERT_WINDOWS_PATHS=1` in your CMD or PowerShell terminal - * Optionally, [read](https://github.com/docker/compose/issues/4303#issuecomment-379563170) this bug report. +* Kill, and optionally disable, the `World Wide Web Publishing Service` +* Run `set COMPOSE_CONVERT_WINDOWS_PATHS=1` in your CMD or PowerShell terminal +* Optionally, [read](https://github.com/docker/compose/issues/4303#issuecomment-379563170) this bug report. ### Optional: Data Source Tools * Optionally included is the following tools: - * phpMyAdmin + - phpMyAdmin * `cd ./devop-tools/docker/data-source-tools && docker-compose up --build -d` ## phpMyAdmin If the optional tools are launched, you can find phpMyAdmin at: localhost:8080 - * It supports the following databases... - * mariadb102 (deprecated) - * mariadb103 - * mariadb104 - * mariadb105 +* It supports the following databases... + - mariadb102 (deprecated) + - mariadb103 + - mariadb104 + - mariadb105 ## Examples Inside the `examples` folder you will find example Docker configurations for @@ -54,9 +54,9 @@ already added to the `/etc/hosts` file. You can edit to add `127.0.0.1 domain.do ## Scripts Inside the `scripts` folder you will find one-off scripts to help with tasks. - * `db_migrate.sh` - Helps migrate databases between versions of mysql. +* `db_migrate.sh` - Helps migrate databases between versions of mysql. ## Docs - * [Setting up Nginx-Proxy](docs/nginx-proxy/README.md) - * [Setting up PHP Testing in PHPStorm](docs/phpstorm-docker/README.md) - * [Leveraging Yii2 Shell](docs/yii2/yii-shell.md) +* [Setting up Nginx-Proxy](docs/nginx-proxy/README.md) +* [Setting up PHP Testing in PHPStorm](docs/phpstorm-docker/README.md) +* [Leveraging Yii2 Shell](docs/yii2/yii-shell.md) diff --git a/docs/nginx-proxy/README.md b/docs/nginx-proxy/README.md index 6029252..c8ffbeb 100644 --- a/docs/nginx-proxy/README.md +++ b/docs/nginx-proxy/README.md @@ -7,10 +7,9 @@ In order for nginx-proxy to operate, you must follow the following steps. ## Setup hosts file 1. Choose a virtual host for your project. RFC-6761 recommends against using a .dev TLD, and instead using a .localhost TLD. Therefore, your domain might be mysite.localhost 2. Edit your hosts file and add this domain to your loopback address (127.0.0.1) using your preferred text editor. *make sure to use sudo* -``` +```bash sudo nano /etc/hosts -add: 127.0.0.1 mysite.localhost ``` @@ -18,11 +17,11 @@ add: 1. In order for nginx-proxy to detect and proxy to the correct virtual host, you must first identify the container that is running the "web server." In a php project, this would be the nginx container, for example. 2. You will then add an environment variable of `VIRTUAL_HOST=mysite.localhost` to this service, place that service on the nginx-proxy network, and import that nginx-proxy network to the project. See the below snippet: -``` +```text version: '2' services: [APP_NAME]_nginx: image: nginx:latest environment: - VIRTUAL_HOST=mysite.localhost -``` \ No newline at end of file +``` diff --git a/docs/phpstorm-docker/README.md b/docs/phpstorm-docker/README.md index 61a75fc..a59891d 100644 --- a/docs/phpstorm-docker/README.md +++ b/docs/phpstorm-docker/README.md @@ -1,7 +1,7 @@ # PHPStorm & Docker -The goal for this tutorial is to help containerize an application -to leverage the tools within PHPStorm (Test Suite, Coverage, etc). +The goal for this tutorial is to help containerize an application to leverage the tools within PHPStorm (Test Suite, +Coverage, etc). To do this the following things need to happen: @@ -16,21 +16,21 @@ We are assuming the following things: 2) The project is already running via (docker-compose up --build) 3) Some small knowledge of Docker -### Setup Docker for Mac in PHPStorm +## Setup Docker for Mac in PHPStorm -Head to Preferences and go to `Build, Execution, Deployment -> Docker`. Create a -an item called "Docker" using the daemon option "Docker for Mac". +Head to Preferences and go to `Build, Execution, Deployment -> Docker`. Create an item called "Docker" +using the daemon option "Docker for Mac". -![](./assets/docker-phpstorm.png) +![docker-phpstorm-overview](./assets/docker-phpstorm.png) ### Creating an isolated docker-compose for testing. -In order for PHPStorm to run tests without affecting containers. You need to -create a new container that matches whatever container your code works on. +In order for PHPStorm to run tests without affecting containers. You need to create a new container that matches +whatever container your code works on. For example, here a random PHP project `docker-compose-phpstorm.yml` file. -``` +```text version: '2' services: project-test: @@ -42,77 +42,64 @@ services: - st-internal ``` -As you can see, it is a subset of the compose file. It only includes a clone of -the PHP container, keeping intact the networks, mounts and env file. This allows -the new container to have access to databases and files which may be needed in -the test suite. You can use multiple compose files if you need one for an -acceptance test container. +As you can see, it is a subset of the compose file. It only includes a clone of the PHP container, keeping intact the +networks, mounts and env file. This allows the new container to have access to databases and files which may be needed +in the test suite. You can use multiple compose files if you need one for an acceptance test container. -If your project requires multiple containers in the testing aspect. Recommend -creating descriptive container names, like `project-codeception` so you could -additionally have `project-behat` if needed. +If your project requires multiple containers in the testing aspect. Recommend creating descriptive container names, +like `project-codeception` so you could additionally have `project-behat` if needed. ### Setup Docker Container for PHP Language -Head to Preferences and go to `Languages & Frameworks > PHP`. From here we are -going to click the "..." next to the CLI Interpreter option in order to create a -new "Docker Compose" interpreter. Using the file we created above, we will -select that one. Once selected, you need to select the container to use. This -will more than likely be auto-selected for you. +Head to Preferences and go to `Languages & Frameworks > PHP`. From here we are going to click the "..." next to the CLI +Interpreter option in order to create a new "Docker Compose" interpreter. Using the file we created above, we will +select that one. Once selected, you need to select the container to use. This will more than likely be auto-selected for +you. -![](./assets/docker-findphp.png) +![phpstorm-finding-php-interpreter](./assets/docker-findphp.png) ### Setup Docker Container for PHP Test Framework -Head to Preferences and go to `Languages & Framework > PHP > Test Frameworks`. -Once here, click the "+" icon in top right to create a new test environment. You -will more than likely select one of the following: +Head to Preferences and go to `Languages & Framework > PHP > Test Frameworks`. Once here, click the "+" icon in top +right to create a new test environment. You will more than likely select one of the following: + +* PHPUnit by Remote Interpreter +* Codeception by Remote Interpreter +* Behat by Remote Interpreter +* PHPSpec by Remote Interpreter + +Once you select one, you will need to select the container to run this tool at. You already created the container and +loaded it in the previous steps. So just select the container that works. Once loaded, you need to put in the file path +to that binary. In the screenshot below, we are using Codeception so looking for `/code/vendor/bin/codecept`. +The `/code` is what we use to mount our code into the container. This pattern may be different depending on lots of +factors. + +Finally, for this step you need to make sure you specify the configuration file for the test framework. The default +location may be wrong, in the photo below I gave the direct path to the configuration like: `/code/codeception.yml`. + +![phpstorm-setting-up-codecept](./assets/docker-codecept.png) - * PHPUnit by Remote Interpreter - * Codeception by Remote Interpreter - * Behat by Remote Interpreter - * PHPSpec by Remote Interpreter - -Once you select one, you will need to select the container to run this tool at. -You already created the container and loaded it in the previous steps. So just -select the container that works. Once loaded, you need to put in the file path -to that binary. In the screenshot below, we are using Codeception so looking -for `/code/vendor/bin/codecept`. The `/code` is what we use to mount our code -into the container. This pattern may be different depending on lots of factors. - -Finally, for this step you need to make sure you specify the configuration file -for the test framework. The default location may be wrong, in the photo below I -gave the direct path to the configuration like: `/code/codeception.yml`. - -![](./assets/docker-codecept.png) - ### Setup Test Case to run in IDE - -Head "Run -> Edit Configurations". Now you need to select the test framework -that matches the test framework you attached into the container. Since, we used -Codeception, we will continue to use Codeception for this demo. - -Our goal is to select the "Defined in the Configuration File". No matter the -tool, if you configured it correctly, we can just use those values and inherit. - -This demo has made an additional change and requested Codeception to only run -the "unit" test suite. - -![](./assets/docker-unittest.png) -### Run the Test Suite +Head "Run -> Edit Configurations". Now you need to select the test framework that matches the test framework you +attached into the container. Since, we used Codeception, we will continue to use Codeception for this demo. + +Our goal is to select the "Defined in the Configuration File". No matter the tool, if you configured it correctly, we +can just use those values and inherit. + +This demo has made an additional change and requested Codeception to only run the "unit" test suite. -Now we should be able to the launch the test suite. Our docker-compose file will -execute, spawning a new "test" container based off our main language container. +![phpstorm-setting-up-unittest](./assets/docker-unittest.png) -This will then proceed to execute the test framework we specified, collecting -the results and parsing them into the UI. +### Run the Test Suite -This can be shown below: +Now we should be able to the launch the test suite. Our docker-compose file will execute, spawning a new "test" +container based off our main language container. -![](./assets/docker-testpass.png) +This will then proceed to execute the test framework we specified, collecting the results and parsing them into the UI. -With that you have successfully hooked the test suites, while keeping Docker -inside PHPStorm. +This can be shown below: +![phpstorm-seeing-green-test](./assets/docker-testpass.png) +With that you have successfully hooked the test suites, while keeping Docker inside PHPStorm. diff --git a/docs/yii2/yii-shell.md b/docs/yii2/yii-shell.md index 2ceebe0..d79ba21 100644 --- a/docs/yii2/yii-shell.md +++ b/docs/yii2/yii-shell.md @@ -7,16 +7,17 @@ This is provided by the YiiSoft [yii2-shell](https://github.com/yiisoft/yii2-she ## Usage -The shell is available via the Yii CLI with `console/yii shell`. This will provide a prompt that evaluates PHP code in the context of a -fully bootstrapped application. -In common usage, it is likely preferable to access this via one of the Docker containers like `docker exec -it sourcetoad_core_php console/yii shell`. -This allows for Docker based routing to the database container and the Station/Satellite pair. +The shell is available via the Yii CLI with `console/yii shell`. This will provide a prompt that evaluates PHP code in +the context of a fully bootstrapped application. +In common usage, it is likely preferable to access this via one of the Docker containers +like `docker exec -it sourcetoad_core_php console/yii shell`. This allows for Docker based routing to the database +container and the Station/Satellite pair. ## Features ### Shell Specific Commands -The shell makes available a number of specific commands. +The shell makes available a number of specific commands. ![help](./assets/help.png) `dump` provides a well organized and readable dump. @@ -27,12 +28,14 @@ An input history is kept locally and can be navigated via the arrow keys, simila ## Caveats While classes are autoloaded they must be referenced via full namespaces. If working in a particular namespace this can -be assigned. - -`$asset = new common\modules\media\models\Asset()` - +be assigned. + +```php +$asset = new common\modules\media\models\Asset() +``` + versus - + ```php namespace common\modules\media; $asset = new models\Asset(); From 1f925e8e421dee94527a81f79a005773506e3374 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:34:28 -0400 Subject: [PATCH 06/15] fix: dockerfile linting fixes --- examples/laravel/Dockerfile | 4 ++-- examples/yii2/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/laravel/Dockerfile b/examples/laravel/Dockerfile index 73bd48a..3df33b1 100644 --- a/examples/laravel/Dockerfile +++ b/examples/laravel/Dockerfile @@ -1,7 +1,7 @@ FROM php:8.0-fpm # System dependencies needed -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install --no-install-recommends -y \ git \ vim \ openssl \ @@ -44,7 +44,7 @@ COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # Node: We should use another container for this, since we are mixing PHP and Node RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \ - && apt-get install -y nodejs + && apt-get install --no-install-recommends -y nodejs # Yarn: Installing RUN curl -o- -L https://yarnpkg.com/install.sh | bash diff --git a/examples/yii2/Dockerfile b/examples/yii2/Dockerfile index 1a7b0d8..072386a 100644 --- a/examples/yii2/Dockerfile +++ b/examples/yii2/Dockerfile @@ -1,7 +1,7 @@ FROM php:7.0-fpm # System dependencies needed -RUN apt-get update && apt-get install -y \ +RUN apt-get update && apt-get install --no-install-recommends -y \ git \ vim \ openssl \ From 9a823cadeb766d19f6cce4960fef31c51be8f6b9 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:42:59 -0400 Subject: [PATCH 07/15] fix: lint docker-compose files --- examples/laravel/docker-compose.yml | 23 ++++++++++++----------- examples/yii2/docker-compose.yml | 17 +++++++++-------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/examples/laravel/docker-compose.yml b/examples/laravel/docker-compose.yml index 4df0fa4..e22176e 100644 --- a/examples/laravel/docker-compose.yml +++ b/examples/laravel/docker-compose.yml @@ -1,14 +1,15 @@ +--- version: '2' services: # Web Container (talks to nginx-proxy) # The virtual host environment line allows nginx-proxy to know which domain # to proxy to which container. # Additionally, other networks can be registered (databases needed) - [PROJECT_NAME]-web: + ProjectName-web: image: nginx:latest - container_name: sourcetoad_[PROJECT_NAME]_web + container_name: sourcetoad_ProjectName_web environment: - - VIRTUAL_HOST=[WEBSITE.DOCKER] + - VIRTUAL_HOST=ProjectName.docker volumes: - ../:/code - ./config/vhost.conf:/etc/nginx/conf.d/vhost.conf @@ -16,13 +17,13 @@ services: - st-internal # PHP Container # The environment variables allow Xdebug to work properly. - # Networks much like above can be registered depending on what the application + # Networks much like above can be registered depending on what the app # requires. In this case, redis and MariaDB. - [PROJECT_NAME]-php: - container_name: sourcetoad_[PROJECT_NAME]_php + ProjectName-php: + container_name: sourcetoad_ProjectName_php environment: - XDEBUG_CONFIG: "remote_host=host.docker.internal" - PHP_IDE_CONFIG: "serverName=docker" + - XDEBUG_CONFIG="remote_host=host.docker.internal" + - PHP_IDE_CONFIG="serverName=docker" build: . volumes: - ../:/code @@ -31,6 +32,6 @@ services: # These are networks that you are leveraging from outside (external) locations. # The dev-ops repo is already running, so that network (st-internal) exists. networks: - st-internal: - external: - name: st-internal + st-internal: + external: + name: st-internal diff --git a/examples/yii2/docker-compose.yml b/examples/yii2/docker-compose.yml index 1d4a43a..b1bf689 100644 --- a/examples/yii2/docker-compose.yml +++ b/examples/yii2/docker-compose.yml @@ -1,14 +1,15 @@ +--- version: '2' services: # Web Container (talks to nginx-proxy) # The virtual host environment line allows nginx-proxy to know which domain # to proxy to which container. # Additionally, other networks can be registered (databases needed) - [PROJECT_NAME]-web: + ProjectName-web: image: nginx:latest - container_name: sourcetoad_[PROJECT_NAME]_web + container_name: sourcetoad_ProjectName_web environment: - - VIRTUAL_HOST=[WEBSITE.DOCKER] + - VIRTUAL_HOST=ProjectName.docker volumes: - ../:/code - ./config/vhost.conf:/etc/nginx/conf.d/vhost.conf @@ -16,14 +17,14 @@ services: - st-internal # PHP Container # The environment variables allow Xdebug to work properly. - # Networks much like above can be registered depending on what the application + # Networks much like above can be registered depending on what the app # requires. In this case, redis and MariaDB. - [PROJECT_NAME]-php: - container_name: sourcetoad_[PROJECT_NAME]_php + ProjectName-php: + container_name: sourcetoad_ProjectName_php build: . environment: - XDEBUG_CONFIG: "remote_host=host.docker.internal" - PHP_IDE_CONFIG: "serverName=docker" + - XDEBUG_CONFIG="remote_host=host.docker.internal" + - PHP_IDE_CONFIG="serverName=docker" volumes: - ../:/code networks: From e2a34f28e1040cd9a2b0bb795d9fe43e22bca12e Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 09:59:19 -0400 Subject: [PATCH 08/15] fix: move linter configs to proper location --- .hadolint.yaml => .github/linters/.hadolint.yaml | 0 .markdown-lint.yml => .github/linters/.markdown-lint.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .hadolint.yaml => .github/linters/.hadolint.yaml (100%) rename .markdown-lint.yml => .github/linters/.markdown-lint.yml (100%) diff --git a/.hadolint.yaml b/.github/linters/.hadolint.yaml similarity index 100% rename from .hadolint.yaml rename to .github/linters/.hadolint.yaml diff --git a/.markdown-lint.yml b/.github/linters/.markdown-lint.yml similarity index 100% rename from .markdown-lint.yml rename to .github/linters/.markdown-lint.yml From c5bf1c8bd157e330fb03b7b969c81a29eb9fd907 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 10:01:55 -0400 Subject: [PATCH 09/15] fix: correct linting warning --- docker/data-source-services/network-creation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/data-source-services/network-creation.sh b/docker/data-source-services/network-creation.sh index 27c1862..22296e0 100755 --- a/docker/data-source-services/network-creation.sh +++ b/docker/data-source-services/network-creation.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -echo "Creating container networks:\n" +echo "Creating container networks:" docker network create st-internal From 23382bbd6136bd24a141f3404f1953fa90d87019 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 10:51:48 -0400 Subject: [PATCH 10/15] fix: adapt linters --- .github/linters/.hadolint.yaml | 1 + .github/linters/.markdown-lint.yml | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/.github/linters/.hadolint.yaml b/.github/linters/.hadolint.yaml index 047d737..ca9ea11 100644 --- a/.github/linters/.hadolint.yaml +++ b/.github/linters/.hadolint.yaml @@ -1,3 +1,4 @@ ignored: + - DL3022 - DL3008 - DL3059 diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml index 7244343..7636c41 100644 --- a/.github/linters/.markdown-lint.yml +++ b/.github/linters/.markdown-lint.yml @@ -1 +1,12 @@ +# Hard wrap to 120, not 80 +MD013: + line_length: 120 + +# Allow no new lines between h1 tags (Changelog) +MD022: false + +# Allow multiple h1 tags (Changelog) MD025: false + +# Allow no new lines between lists (Changelog) +MD032: false From 28c4942f6a649ab6e9b6d2509e137b28c35d101f Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 10:52:08 -0400 Subject: [PATCH 11/15] style: correct linting errors in Dockerfile --- examples/laravel/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/laravel/Dockerfile b/examples/laravel/Dockerfile index 3df33b1..753de7b 100644 --- a/examples/laravel/Dockerfile +++ b/examples/laravel/Dockerfile @@ -34,7 +34,7 @@ RUN pecl install xdebug RUN docker-php-ext-enable xdebug # Copy the config/php.ini into the container -COPY ./config/php.ini /usr/local/etc/php/ +#COPY ./config/php.ini /usr/local/etc/php/ # Set the working directory to /code WORKDIR /code @@ -43,11 +43,11 @@ WORKDIR /code COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # Node: We should use another container for this, since we are mixing PHP and Node -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \ +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -o pipefail - \ && apt-get install --no-install-recommends -y nodejs # Yarn: Installing -RUN curl -o- -L https://yarnpkg.com/install.sh | bash +RUN curl -o- -L https://yarnpkg.com/install.sh | bash -o pipefail # Change settings for the fpm pool RUN sed -i -e "s/pm.max_children\s*=\s*[0-9]*/pm.max_children = 30/g" /usr/local/etc/php-fpm.d/www.conf From b6fd1d913d240920b2eb1aa4ce04abbb7730fd77 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 10:55:46 -0400 Subject: [PATCH 12/15] style: correct linting errors in markdown files --- docs/nginx-proxy/README.md | 5 +++-- docs/phpstorm-docker/README.md | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/nginx-proxy/README.md b/docs/nginx-proxy/README.md index c8ffbeb..0c64ce4 100644 --- a/docs/nginx-proxy/README.md +++ b/docs/nginx-proxy/README.md @@ -6,7 +6,8 @@ In order for nginx-proxy to operate, you must follow the following steps. ## Setup hosts file 1. Choose a virtual host for your project. RFC-6761 recommends against using a .dev TLD, and instead using a .localhost TLD. Therefore, your domain might be mysite.localhost -2. Edit your hosts file and add this domain to your loopback address (127.0.0.1) using your preferred text editor. *make sure to use sudo* +2. Edit your hosts file and add this domain to your loopback address (127.0.0.1) using your preferred text editor. + ```bash sudo nano /etc/hosts @@ -17,7 +18,7 @@ sudo nano /etc/hosts 1. In order for nginx-proxy to detect and proxy to the correct virtual host, you must first identify the container that is running the "web server." In a php project, this would be the nginx container, for example. 2. You will then add an environment variable of `VIRTUAL_HOST=mysite.localhost` to this service, place that service on the nginx-proxy network, and import that nginx-proxy network to the project. See the below snippet: -```text +```bash version: '2' services: [APP_NAME]_nginx: diff --git a/docs/phpstorm-docker/README.md b/docs/phpstorm-docker/README.md index a59891d..1773250 100644 --- a/docs/phpstorm-docker/README.md +++ b/docs/phpstorm-docker/README.md @@ -23,14 +23,14 @@ using the daemon option "Docker for Mac". ![docker-phpstorm-overview](./assets/docker-phpstorm.png) -### Creating an isolated docker-compose for testing. +### Creating an isolated docker-compose for testing In order for PHPStorm to run tests without affecting containers. You need to create a new container that matches whatever container your code works on. For example, here a random PHP project `docker-compose-phpstorm.yml` file. -```text +```bash version: '2' services: project-test: @@ -86,7 +86,7 @@ attached into the container. Since, we used Codeception, we will continue to use Our goal is to select the "Defined in the Configuration File". No matter the tool, if you configured it correctly, we can just use those values and inherit. - + This demo has made an additional change and requested Codeception to only run the "unit" test suite. ![phpstorm-setting-up-unittest](./assets/docker-unittest.png) From 1b1899603fb0d974b9dba1458cbca4de3c2e8739 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 11:03:21 -0400 Subject: [PATCH 13/15] fix: ignore 4006 rule (docker-compose lint) --- .github/linters/.hadolint.yaml | 1 + examples/laravel/Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/linters/.hadolint.yaml b/.github/linters/.hadolint.yaml index ca9ea11..5be8d7c 100644 --- a/.github/linters/.hadolint.yaml +++ b/.github/linters/.hadolint.yaml @@ -2,3 +2,4 @@ ignored: - DL3022 - DL3008 - DL3059 + - DL4006 diff --git a/examples/laravel/Dockerfile b/examples/laravel/Dockerfile index 753de7b..d261da4 100644 --- a/examples/laravel/Dockerfile +++ b/examples/laravel/Dockerfile @@ -43,11 +43,11 @@ WORKDIR /code COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer # Node: We should use another container for this, since we are mixing PHP and Node -RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -o pipefail - \ +RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - \ && apt-get install --no-install-recommends -y nodejs # Yarn: Installing -RUN curl -o- -L https://yarnpkg.com/install.sh | bash -o pipefail +RUN curl -o- -L https://yarnpkg.com/install.sh | bash # Change settings for the fpm pool RUN sed -i -e "s/pm.max_children\s*=\s*[0-9]*/pm.max_children = 30/g" /usr/local/etc/php-fpm.d/www.conf From 8a762fefc0d4150a8a3e5b0b70c37b0c0c590216 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 12:26:29 -0400 Subject: [PATCH 14/15] style: continued markdown fixes --- DOCKER_TIPS.md | 41 ++++++++++++++++++++------------------ README.md | 10 +++++----- docs/nginx-proxy/README.md | 13 ++++++++---- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/DOCKER_TIPS.md b/DOCKER_TIPS.md index d2c931f..22636e0 100644 --- a/DOCKER_TIPS.md +++ b/DOCKER_TIPS.md @@ -1,33 +1,36 @@ # Docker Tips ## Typical Docker Commands - ### Start all environments services - > docker-compose up --build - ### Restart a specific container - > docker restart [service name] +```bash +# Start all environments services +docker-compose up --build - ### List all containers - > docker ps -a +# Restart a specific container +docker restart [service name] - ### List running containers - > docker ps +# List all containers +docker ps -a - ### See used space - > docker system df +# List running containers +docker ps - ### Remove un-used data - > docker system prune +# See used space +docker system df -## Passwords - ### PostgreSQL - > username: postgres_user - > password: postgres_pass +# Remove un-used data +docker system prune +``` - ### MariaDB - > username: mariadb_user - > password: mariadb_pass +## Passwords + +* PostgreSQL + - `username: postgres_user` + - `password: postgres_pass` +* MariaDB + - `username: mariadb_user` + - `password: mariadb_pass` ## Running Xdebug with PHPStorm alongside Docker From Docker versions 18.03 and above, Docker creates a special DNS name that resolves diff --git a/README.md b/README.md index 973c0dd..4bda0a7 100644 --- a/README.md +++ b/README.md @@ -33,16 +33,16 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d ### Optional: Data Source Tools * Optionally included is the following tools: - - phpMyAdmin + * phpMyAdmin * `cd ./devop-tools/docker/data-source-tools && docker-compose up --build -d` ## phpMyAdmin If the optional tools are launched, you can find phpMyAdmin at: localhost:8080 * It supports the following databases... - - mariadb102 (deprecated) - - mariadb103 - - mariadb104 - - mariadb105 + * mariadb102 (deprecated) + * mariadb103 + * mariadb104 + * mariadb105 ## Examples Inside the `examples` folder you will find example Docker configurations for diff --git a/docs/nginx-proxy/README.md b/docs/nginx-proxy/README.md index 0c64ce4..8a1087a 100644 --- a/docs/nginx-proxy/README.md +++ b/docs/nginx-proxy/README.md @@ -1,11 +1,14 @@ # nginx-proxy -The data source services includes an application called nginx-proxy. This allows you to run multiple projects at the same time on different virtual hosts without port conflicts. You do not need to expose the webserver to the host machine through a port map. +The data source services includes an application called nginx-proxy. This allows you to run multiple projects at the +same time on different virtual hosts without port conflicts. You do not need to expose the webserver to the host machine +through a port map. In order for nginx-proxy to operate, you must follow the following steps. ## Setup hosts file -1. Choose a virtual host for your project. RFC-6761 recommends against using a .dev TLD, and instead using a .localhost TLD. Therefore, your domain might be mysite.localhost +1. Choose a virtual host for your project. RFC-6761 recommends against using a .dev TLD, and instead using a .localhost + TLD. Therefore, your domain might be mysite.localhost 2. Edit your hosts file and add this domain to your loopback address (127.0.0.1) using your preferred text editor. ```bash @@ -15,8 +18,10 @@ sudo nano /etc/hosts ``` ## Setup docker-compose for project -1. In order for nginx-proxy to detect and proxy to the correct virtual host, you must first identify the container that is running the "web server." In a php project, this would be the nginx container, for example. -2. You will then add an environment variable of `VIRTUAL_HOST=mysite.localhost` to this service, place that service on the nginx-proxy network, and import that nginx-proxy network to the project. See the below snippet: +1. In order for nginx-proxy to detect and proxy to the correct virtual host, you must first identify the container that + is running the "web server." In a php project, this would be the nginx container, for example. +2. You will then add an environment variable of `VIRTUAL_HOST=mysite.localhost` to this service, place that service on + the nginx-proxy network, and import that nginx-proxy network to the project. See the below snippet: ```bash version: '2' From 2da76236ce8dc2b9ba2ef26c6be34d9eca2cc904 Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 2 Nov 2021 12:35:56 -0400 Subject: [PATCH 15/15] style: continued markdown fixes --- DOCKER_TIPS.md | 9 ++++----- README.md | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/DOCKER_TIPS.md b/DOCKER_TIPS.md index 22636e0..feff587 100644 --- a/DOCKER_TIPS.md +++ b/DOCKER_TIPS.md @@ -22,15 +22,14 @@ docker system df docker system prune ``` - ## Passwords * PostgreSQL - - `username: postgres_user` - - `password: postgres_pass` + * `username: postgres_user` + * `password: postgres_pass` * MariaDB - - `username: mariadb_user` - - `password: mariadb_pass` + * `username: mariadb_user` + * `password: mariadb_pass` ## Running Xdebug with PHPStorm alongside Docker From Docker versions 18.03 and above, Docker creates a special DNS name that resolves diff --git a/README.md b/README.md index 4bda0a7..50ce528 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cd ./devop-tools/docker/data-source-services && docker-compose up --build -d ### Optional: Data Source Tools * Optionally included is the following tools: - * phpMyAdmin + * phpMyAdmin * `cd ./devop-tools/docker/data-source-tools && docker-compose up --build -d` ## phpMyAdmin