Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
chore: Migrate from Make to Task (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink committed May 6, 2021
1 parent 331f2d3 commit 20b1a0b
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 160 deletions.
1 change: 0 additions & 1 deletion .github/hooks/post-merge

This file was deleted.

1 change: 0 additions & 1 deletion .github/hooks/pre-commit

This file was deleted.

20 changes: 11 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/public/hot
/public/storage
/storage
/vendor
.env
.phpunit.result.cache
artifacts/
junit.xml
docker-compose.override.yml
/public/hot/**
/public/storage/**
/storage/**
/vendor/**
/.env
/.phpunit.result.cache
/artifacts/**
/junit.xml
/docker-compose.override.yml

!/**/.gitkeep
96 changes: 0 additions & 96 deletions Makefile

This file was deleted.

30 changes: 12 additions & 18 deletions README-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ Description of the project here...
The application is built as a Docker image defined in
[`Dockerfile`][dockerfile]. Docker Compose provides application orchestration
during development, as defined in [`docker-compose.yml`][dc-config]. Developers
should only interact with the project through the container(s). A number of
commands are included to aide with this workflow — provided by `make`.
should only interact with the project through the container(s): a number of
helpful tasks are included to aide with this workflow using [Task][taskfile].

```console
dev:~$ make
dev:~$ task start
»» Launched application at http://localhost:8094
```

A full list of supported commands is available in [`Makefile`](Makefile)
including `check`, `shell`, `logs`, `upgrade`, `build` and more.
[Modern Make][mmake] is recommended to gain a dynamic command list using
`make help`.
A full list of supported commands is available using `task`
including `check`, `shell`, `logs`, `release` and more.

```console
dev:~$ task
task: Available tasks for this project: [...]
```

### Quality

Expand All @@ -27,19 +30,10 @@ suites, performs static analysis and validates compliance with
[PSR-12: Extended Coding Style][psr-12].

```console
dev:~$ make check
```

### Hooks

A pre-commit Git Hook is included for ensuring compliance with code
requirements on commit, enable the Git Hook by running the following command:

```console
dev:~$ git config core.hooksPath .github/hooks
dev:~$ task check
```

[dockerfile]: Dockerfile
[dc-config]: docker-compose.yml
[mmake]: https://github.com/tj/mmake
[psr-12]: https://www.php-fig.org/psr/psr-12/
[taskfile]: https://taskfile.dev/
59 changes: 27 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ install designed for building high quality containerised Laravel applications.
* Continuous Delivery using [GitHub Actions][workflows] and the GitHub Container
Registry
* [Development Environment](#development-environment) using Docker Compose
* [`Makefile`](Makefile) with helpful development lifecycle commands
* [`Taskfile`<sup>&neArr;</sup>][task] with helpful development lifecycle
commands

:thought_balloon: **Laravel Strict is intended for projects with strict code
quality requirements**, it was created for use in regulated environments where
Expand Down Expand Up @@ -45,7 +46,7 @@ built and pushed to the GitHub Container Registry by the

```console
dev:~$ git clone https://github.com/example/my-strict-application.git
dev:~$ make
dev:~$ task start
»» Launched application at http://localhost:8094
```

Expand Down Expand Up @@ -101,21 +102,17 @@ including paths required by the application. Learn more about this approach in

## Development Environment

### `make`
### `task`

[`Makefile`](Makefile) includes a full suite of commands for use during the
development lifecycle. [Modern Make][modern-make] is recommended to provide a
dynamic command list.
[Task][task] is a cross-platform task runner, which is used to provide a full
suite of commands for use during the development lifecycle.

```console
dev:~$ make help
build Build the application's Docker image | TAG!
check Run the application's code checks
launch Launch development environment (default)
logs Listen to the service logs
shell Log in to the application container
test Run the application's tests
... +14 more
dev:~$ task
task: Available tasks for this project:
* check: Run application checks (code quality, tests)
* start: Start the local application environment
* .....: + more
```

### Environment Variables
Expand All @@ -126,28 +123,27 @@ provided in production environments. A developer can use
[`docker-compose.override.yml`][dc-override] to provide values unique to their
local environment.

### Volume `vendor`
### Volumes `vendor` + `storage`

By default the `vendor` directory is a mounted volume to maximise performance,
however if you wish for developers to be able to access the contents of the
`vendor` directory you can modify [`docker-compose.yml`][dc-config] like so:
The `vendor` and `storage` directories are **volume** mounts to maximise
performance, however this means by default the host machine cannot access the
volume contents.

```diff
volumes:
- - vendor:/srv/vendor
+ - ./vendor:/srv/vendor
```

This will require an additional dependency install as part of the `launch` step
in the `Makefile`, i.e:
Developers can **bind** mount these volumes instead to gain access to the volume
contents by overriding the volume configuration in their
`docker-compose.override.yml`.

```diff
launch: run
+ make install
+services:
+ app:
+ volumes:
+ - .:/srv
+ - ./storage:/srv/storage
+ - ./vendor:/srv/vendor
```

:warning: volume mounting dependencies in this way will reduce application
performance in development by ~10x
:warning: bind mounting volumes in this way may reduce application performance
in development by up to 10x

[laravel]: https://laravel.com
[laravel-8]: https://laravel.com/docs/8.x
Expand All @@ -160,7 +156,6 @@ performance in development by ~10x
[readme-project]: README-project.md
[edit/composer.json]: edit/main/composer.json
[docker/name]: https://github.com/moby/moby/blob/19.03/daemon/names/names.go#L6
[hooks]: README-project.md#hooks
[ghcr-pat]: https://docs.github.com/en/packages/getting-started-with-github-container-registry/migrating-to-github-container-registry-for-docker-images#authenticating-with-the-container-registry
[secrets]: settings/secrets
[dc-config]: docker-compose.yml
Expand All @@ -171,7 +166,7 @@ performance in development by ~10x
[bootstrap]: bootstrap/app.php
[phpdotenv]: https://github.com/vlucas/phpdotenv
[generate-new]: generate
[task]: https://taskfile.dev
[create-readme]: edit/main/README-project.md?filename=README.md
[modern-make]: https://github.com/tj/mmake
[docker-healthcheck]: https://docs.docker.com/engine/reference/builder/#healthcheck
[conductor-laravel]: https://github.com/shrink/conductor-laravel
104 changes: 104 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
version: '3'

silent: true

dotenv: ['.env', '.env.example']

tasks:
default:
cmds:
- task --list
start:
desc: Start the local application environment
cmds:
- task: up
- task: install
- echo "Launched application at http://localhost:$APP_PORT"
suspend:
desc: Suspend the local application environment to maintain state for later
cmds:
- docker compose down
stop:
desc: Stop the local application environment and clean all state
cmds:
- docker compose down --volumes --rmi all --remove-orphans
logs:
desc: Stream local environment container output
cmds:
- docker compose logs -f
shell:
desc: Launch interactive shell for application container
cmds:
- task: exec
vars: {COMMAND: 'sh'}
check:
desc: Run application checks (code quality, tests)
cmds:
- task: composer
vars: {SCRIPT: "check"}
test:
desc: Run application tests
cmds:
- task: composer
vars: {SCRIPT: "test"}
install:
desc: Install php dependencies
cmds:
- task: composer
vars: {SCRIPT: "install"}
release:
desc: Tag new version of the application
summary: |
Tag a new version of the application against the current HEAD
VERSION is a required parameter which should be an un-prefixed Semantic
Version, e.g: 0.1.0.
To overwrite an existing tag on the local and remote, pass through the
`-f` flag to the underlying git command:
VERSION=0.1.0 task release -- -f
preconditions:
- sh: test $VERSION
msg: A VERSION parameter is required to create a new release
vars:
VERSION: '{{default "0.1.0" .VERSION}}'
cmds:
- git show --oneline -s
- |
git tag -sam ":tada: Version {{.VERSION}}" v{{.VERSION}} {{.CLI_ARGS}}
- git push origin v{{.VERSION}} {{.CLI_ARGS}}
up:
summary: |
Start local application environment
note: This is a command fragment for Taskfile composition.
cmds:
- docker compose up -d
composer:
summary: |
Run composer script on service
note: This is a command fragment for Taskfile composition.
vars:
SCRIPT: '{{default "" .SCRIPT}}'
cmds:
- task: exec
vars: {COMMAND: "composer {{.SCRIPT}}"}
exec:
summary: |
Run arbitrary command on service
TTY controls pseudo-tty allocation using for scripted execution of tasks.
note: This is a command fragment for Taskfile composition.
vars:
SERVICE: '{{default "app" .SERVICE}}'
COMMAND: '{{default "echo \"Hello, World!\"" .COMMAND}}'
TTY: '{{default "true" .TTY}}'
cmds:
- task: up
- |
docker compose exec \
{{if ne .TTY "true"}}-T{{end}} \
{{.SERVICE}} {{.COMMAND}}
Loading

0 comments on commit 20b1a0b

Please sign in to comment.