-
Notifications
You must be signed in to change notification settings - Fork 879
docs: Add PHP recipes to cookbook #9644
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
docs/current_docs/cookbook/snippets/builds/cache/php/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "daggermodule/my-module", | ||
| "description": "", | ||
| "version": "1.0.0", | ||
| "minimum-stability": "dev", | ||
| "license": "proprietary", | ||
| "authors": [ | ||
| ], | ||
| "repositories": [ | ||
| { | ||
| "type": "path", | ||
| "url": "./sdk" | ||
| } | ||
| ], | ||
| "require": { | ||
| "php": "^8.1", | ||
| "dagger/dagger": "*@dev" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "DaggerModule\\": "src/" | ||
| } | ||
| }, | ||
| "config": { | ||
| "platform": { | ||
| "php": "8.3.7" | ||
| } | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
docs/current_docs/cookbook/snippets/builds/cache/php/dagger.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "my-module", | ||
| "engineVersion": "v0.15.3", | ||
| "sdk": "php" | ||
| } |
25 changes: 25 additions & 0 deletions
25
docs/current_docs/cookbook/snippets/builds/cache/php/entrypoint.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env php | ||
| <?php declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This is the entry point for the module, called from the dagger engine. | ||
| * Editing this file is highly discouraged and may stop your module from functioning entirely. | ||
| */ | ||
|
|
||
| use Symfony\Component\Console\Application; | ||
| use Dagger\Command\EntrypointCommand; | ||
|
|
||
| if (file_exists(__DIR__.'/../../autoload.php')) { | ||
| // The usual location, since this file will reside in vendor/bin | ||
| require __DIR__.'/../../autoload.php'; | ||
| } else { | ||
| // Useful when doing development on this package | ||
| require __DIR__.'/vendor/autoload.php'; | ||
| } | ||
|
|
||
| $console = new Application(); | ||
|
|
||
| $console->add(new EntrypointCommand()); | ||
| $console->setDefaultCommand('dagger:entrypoint'); | ||
|
|
||
| $console->run(); |
28 changes: 28 additions & 0 deletions
28
docs/current_docs/cookbook/snippets/builds/cache/php/src/MyModule.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DaggerModule; | ||
|
|
||
| use Dagger\Attribute\DaggerFunction; | ||
| use Dagger\Attribute\DaggerObject; | ||
| use Dagger\Directory; | ||
|
|
||
| use function Dagger\dag; | ||
|
|
||
| #[DaggerObject] | ||
| class MyModule | ||
| { | ||
| // Run a build with cache invalidation | ||
| #[DaggerFunction] | ||
| public function build(): string | ||
| { | ||
| return dag() | ||
| ->container() | ||
| ->from('alpine') | ||
| // comment out the line below to see the cached date output | ||
| ->withEnvVariable('CACHEBUSTER', date(DATE_RFC2822)) | ||
| ->withExec(['date']) | ||
| ->stdout(); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
docs/current_docs/cookbook/snippets/builds/dockerfile/php/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "daggermodule/my-module", | ||
| "description": "", | ||
| "version": "1.0.0", | ||
| "minimum-stability": "dev", | ||
| "license": "proprietary", | ||
| "authors": [ | ||
| ], | ||
| "repositories": [ | ||
| { | ||
| "type": "path", | ||
| "url": "./sdk" | ||
| } | ||
| ], | ||
| "require": { | ||
| "php": "^8.1", | ||
| "dagger/dagger": "*@dev" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "DaggerModule\\": "src/" | ||
| } | ||
| }, | ||
| "config": { | ||
| "platform": { | ||
| "php": "8.3.7" | ||
| } | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
docs/current_docs/cookbook/snippets/builds/dockerfile/php/dagger.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "my-module", | ||
| "engineVersion": "v0.15.3", | ||
| "sdk": "php" | ||
| } |
25 changes: 25 additions & 0 deletions
25
docs/current_docs/cookbook/snippets/builds/dockerfile/php/entrypoint.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env php | ||
| <?php declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This is the entry point for the module, called from the dagger engine. | ||
| * Editing this file is highly discouraged and may stop your module from functioning entirely. | ||
| */ | ||
|
|
||
| use Symfony\Component\Console\Application; | ||
| use Dagger\Command\EntrypointCommand; | ||
|
|
||
| if (file_exists(__DIR__.'/../../autoload.php')) { | ||
| // The usual location, since this file will reside in vendor/bin | ||
| require __DIR__.'/../../autoload.php'; | ||
| } else { | ||
| // Useful when doing development on this package | ||
| require __DIR__.'/vendor/autoload.php'; | ||
| } | ||
|
|
||
| $console = new Application(); | ||
|
|
||
| $console->add(new EntrypointCommand()); | ||
| $console->setDefaultCommand('dagger:entrypoint'); | ||
|
|
||
| $console->run(); |
27 changes: 27 additions & 0 deletions
27
docs/current_docs/cookbook/snippets/builds/dockerfile/php/src/MyModule.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DaggerModule; | ||
|
|
||
| use Dagger\Attribute\DaggerFunction; | ||
| use Dagger\Attribute\DaggerObject; | ||
| use Dagger\Directory; | ||
|
|
||
| use function Dagger\dag; | ||
|
|
||
| #[DaggerObject] | ||
| class MyModule | ||
| { | ||
| // Build and publish image from existing Dockerfile | ||
| #[DaggerFunction] | ||
| public function build( | ||
| // location of directory containing Dockerfile | ||
| Directory $src, | ||
| ): string { | ||
| $ref = $src | ||
| ->dockerBuild() // build from Dockerfile | ||
| ->publish('ttl.sh/hello-dagger'); | ||
| return $ref; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
docs/current_docs/cookbook/snippets/builds/matrix-build/php/composer.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "daggermodule/my-module", | ||
| "description": "", | ||
| "version": "1.0.0", | ||
| "minimum-stability": "dev", | ||
| "license": "proprietary", | ||
| "authors": [ | ||
| ], | ||
| "repositories": [ | ||
| { | ||
| "type": "path", | ||
| "url": "./sdk" | ||
| } | ||
| ], | ||
| "require": { | ||
| "php": "^8.1", | ||
| "dagger/dagger": "*@dev" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "DaggerModule\\": "src/" | ||
| } | ||
| }, | ||
| "config": { | ||
| "platform": { | ||
| "php": "8.3.7" | ||
| } | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
docs/current_docs/cookbook/snippets/builds/matrix-build/php/dagger.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "name": "my-module", | ||
| "engineVersion": "v0.15.3", | ||
| "sdk": "php" | ||
| } |
25 changes: 25 additions & 0 deletions
25
docs/current_docs/cookbook/snippets/builds/matrix-build/php/entrypoint.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env php | ||
| <?php declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This is the entry point for the module, called from the dagger engine. | ||
| * Editing this file is highly discouraged and may stop your module from functioning entirely. | ||
| */ | ||
|
|
||
| use Symfony\Component\Console\Application; | ||
| use Dagger\Command\EntrypointCommand; | ||
|
|
||
| if (file_exists(__DIR__.'/../../autoload.php')) { | ||
| // The usual location, since this file will reside in vendor/bin | ||
| require __DIR__.'/../../autoload.php'; | ||
| } else { | ||
| // Useful when doing development on this package | ||
| require __DIR__.'/vendor/autoload.php'; | ||
| } | ||
|
|
||
| $console = new Application(); | ||
|
|
||
| $console->add(new EntrypointCommand()); | ||
| $console->setDefaultCommand('dagger:entrypoint'); | ||
|
|
||
| $console->run(); |
51 changes: 51 additions & 0 deletions
51
docs/current_docs/cookbook/snippets/builds/matrix-build/php/src/MyModule.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DaggerModule; | ||
|
|
||
| use Dagger\Attribute\DaggerFunction; | ||
| use Dagger\Attribute\DaggerObject; | ||
| use Dagger\Directory; | ||
|
|
||
| use function Dagger\dag; | ||
|
|
||
| #[DaggerObject] | ||
| class MyModule | ||
| { | ||
| // define build matrix | ||
| const GOOSES = ['linux', 'darwin']; | ||
| const GOARCHES = ['amd64', 'arm64']; | ||
|
|
||
| // Build and return directory of go binaries | ||
| #[DaggerFunction] | ||
| public function build(Directory $src): Directory | ||
| { | ||
| // create empty directory to put build artifacts | ||
| $outputs = dag()->directory(); | ||
|
|
||
| $golang = dag() | ||
| ->container() | ||
| ->from('golang:latest') | ||
| ->withDirectory('/src', $src) | ||
| ->withWorkdir('/src'); | ||
|
|
||
| foreach (self::GOOSES as $goos) { | ||
| foreach (self::GOARCHES as $goarch) { | ||
| // create a directory for each OS and architecture | ||
| $path = "build/$goos/$goarch/"; | ||
|
|
||
| // build artifact | ||
| $build = $golang | ||
| ->withEnvVariable('GOOS', $goos) | ||
| ->withEnvVariable('GOARCH', $goarch) | ||
| ->withExec(['go', 'build', '-o', $path]); | ||
|
|
||
| // add build to outputs | ||
| $outputs = $outputs->withDirectory($path, $build->directory($path)); | ||
| } | ||
| } | ||
|
|
||
| return $outputs; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.