Skip to content

Commit

Permalink
Merge branch 'main' into tm/docker-install
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed May 5, 2024
2 parents 9aa200e + 0bc07ac commit a8a6e9a
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 107 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,11 @@ jobs:
tests:
strategy:
matrix:
os: [Ubuntu, Windows, macOS]
php: [8.0, 8.1]
# php: [7.2, 7.3, 7.4, 8.0]

include:
- os: Ubuntu
os-version: ubuntu-latest

- os: Windows
os-version: windows-latest

- os: macOS
os-version: macos-latest

- os: macOS-11
os-version: macos-11.0
php: 8.0

- os: macOS-11
os-version: macos-11.0
php: 8.1

os: [ubuntu-latest, windows-latest, macos-latest]
php: [8.1, 8.2, 8.3]
name: ${{ matrix.os }} - PHP ${{ matrix.php }}

runs-on: ${{ matrix.os-version }}
runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ Now, if you run `takeout list`, you'll see both services running at the same tim
+--------------+----------------+---------------+-----------------------------------+
```

## Network Details

Takeout containers are automatically added to a Docker network named `takeout`. This allows you to use the same aliasing and base aliasing that is used for the other containers.

Each container is given two aliases on this network:
- A base_alias based on the core dependency name (e.g. mysql, postgres)
- A full_alias combining the base alias and version (e.g. mysql8.0, postgres13)

Other containers on the takeout network can access Takeout containers by their aliases. [Check this article on how you can use sail and takeout together](https://mattstauffer.com/blog/how-to-use-takeout-to-add-new-services-to-laravel-sail-and-save-ram/)

## FAQs

<details>
Expand Down
45 changes: 45 additions & 0 deletions app/Services/Buggregator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Services;

use App\Shell\GitHubDockerTags;

class Buggregator extends BaseService
{
protected static $category = Category::TOOLS;

protected $dockerTagsClass = GitHubDockerTags::class;
protected $organization = 'ghcr.io';
protected $imageName = 'buggregator/server';
protected $tag = 'latest';
protected $defaultPort = 8000;
protected $prompts = [
[
'shortname' => 'smtp_port',
'prompt' => 'What is the SMTP port?',
'default' => '1025',
],
[
'shortname' => 'var_dumper_port',
'prompt' => 'What is the VarDumper server port?',
'default' => '9912',
],
[
'shortname' => 'monolog_port',
'prompt' => 'What is the Monolog port?',
'default' => '9913',
],
[
'shortname' => 'network_alias',
'prompt' => 'What network alias to you want to assign to this container? This alias can be used by other services on the same network.',
'default' => 'buggregator',
],
];

protected $dockerRunTemplate = '-p "${:port}":8000 \
-p "${:smtp_port}":1025 \
-p "${:var_dumper_port}":9912 \
-p "${:monolog_port}":9913 \
--network-alias "${:network_alias}" \
"${:organization}"/"${:image_name}":"${:tag}"';
}
12 changes: 0 additions & 12 deletions app/Services/MailDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ class MailDev extends BaseService
protected $organization = 'maildev';
protected $imageName = 'maildev';
protected $defaultPort = 1025;
protected $defaultPrompts = [
[
'shortname' => 'port',
'prompt' => 'Which host port would you like %s to use?',
// Default is set in the constructor
],
[
'shortname' => 'tag',
'prompt' => 'Which tag (version) of %s would you like to use?',
'default' => '2.0.5',
],
];
protected $prompts = [
[
'shortname' => 'web_port',
Expand Down
18 changes: 5 additions & 13 deletions app/Services/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class MySql extends BaseService
{
protected static $category = Category::DATABASE;

protected $organization = 'mysql';
protected $imageName = 'mysql-server';
protected $imageName = 'mysql';

protected $defaultPort = 3306;

protected $prompts = [
[
'shortname' => 'volume',
Expand All @@ -24,19 +25,10 @@ class MySql extends BaseService

protected $dockerRunTemplate = '-p "${:port}":3306 \
-e MYSQL_ROOT_PASSWORD="${:root_password}" \
-e MYSQL_ALLOW_EMPTY_PASSWORD="${:allow_empty_password}" \
-e MYSQL_ALLOW_EMPTY_PASSWORD="1" \
-e MYSQL_ROOT_HOST="%" \
-v "${:volume}":/var/lib/mysql \
"${:organization}"/"${:image_name}":"${:tag}" --default-authentication-plugin=mysql_native_password';
"${:organization}"/"${:image_name}":"${:tag}"';

protected static $displayName = 'MySQL';

protected function buildParameters(): array
{
$parameters = parent::buildParameters();

$parameters['allow_empty_password'] = $parameters['root_password'] === '' ? '1' : '0';

return $parameters;
}
}
49 changes: 49 additions & 0 deletions app/Services/Timescale.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace App\Services;

use App\Shell\Docker;
use App\Shell\Environment;
use App\Shell\Shell;

class Timescale extends BaseService
{
protected static $category = Category::DATABASE;

protected $organization = 'timescale';
protected $imageName = 'timescaledb';
protected $tag = 'latest-pg16';
protected $defaultPort = 5432;
protected $prompts = [
[
'shortname' => 'volume',
'prompt' => 'What is the Docker volume name?',
'default' => 'timescale_data',
],
[
'shortname' => 'root_password',
'prompt' => 'What will the password for the `postgres` user be?',
'default' => 'password',
],
];

protected $dockerRunTemplate = '-p "${:port}":5432 \
-e POSTGRES_PASSWORD="${:root_password}" \
-v "${:volume}":/var/lib/postgresql/data \
"${:organization}"/"${:image_name}":"${:tag}"';

protected static $displayName = 'Timescale';

public function __construct(Shell $shell, Environment $environment, Docker $docker)
{
parent::__construct($shell, $environment, $docker);

$this->defaultPrompts = array_map(function ($prompt) {
if ($prompt['shortname'] === 'tag') {
$prompt['default'] = $this->tag;
}

return $prompt;
}, $this->defaultPrompts);
}
}
32 changes: 32 additions & 0 deletions app/Services/Typesense.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Services;

class Typesense extends BaseService
{
protected static $category = Category::SEARCH;

protected $organization = 'typesense';
protected $imageName = 'typesense';
protected $defaultPort = 8108;
protected $prompts = [
[
'shortname' => 'volume',
'prompt' => 'What is the Docker volume name?',
'default' => 'typesense_data',
],
[
'shortname' => 'admin_key',
'prompt' => 'What will the admin API key be?',
'default' => 'typesenseadmin',
],
];

protected $dockerRunTemplate = '-p "${:port}":8108 \
-v "${:volume}":/data \
"${:organization}"/"${:image_name}":"${:tag}" \
--data-dir /data \
--api-key="${:admin_key}"';

protected static $displayName = 'Typesense';
}
57 changes: 26 additions & 31 deletions app/Shell/DockerTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DockerTags
{
protected $guzzle;
protected $service;
protected $armArchitectures = ['arm64', 'aarch64'];

public function __construct(Client $guzzle, BaseService $service)
{
Expand All @@ -29,8 +30,8 @@ public function resolveTag($tag): string

public function getLatestTag(): string
{
$numericTags = $this->getTags()->reject(function ($tag) {
return ! is_numeric($tag[0]);
$numericTags = $this->getTags()->filter(function ($tag) {
return preg_match('/^v?\d/', $tag);
});

if ($numericTags->isEmpty()) {
Expand All @@ -46,33 +47,27 @@ public function getTags(): Collection

$platform = $this->platform();

[$numericTags, $alphaTags] = collect($response['results'])
->when($this->isArm($platform), $this->onlyArmImagesFilter(), $this->onlyNonArmImagesFilter())
return collect($response['results'])
->when(in_array($platform, $this->armArchitectures, true), $this->onlyArmImagesFilter())
->when(! in_array($platform, $this->armArchitectures, true), $this->onlyNonArmImagesFilter())
->pluck('name')
->partition(function ($tag) {
return is_numeric($tag[0]);
});

$sortedTags = $alphaTags->sortDesc(SORT_NATURAL)
->concat($numericTags->sortDesc(SORT_NATURAL));

if ($sortedTags->contains('latest')) {
$sortedTags->splice($sortedTags->search('latest'), 1);
$sortedTags->prepend('latest');
}

return $sortedTags->values()->filter();
->sort(new VersionComparator)
->values();
}

protected function onlyArmImagesFilter()
{
return function ($tags) {
return $tags->filter(function ($tag) {
return collect($tag['images'])
->pluck('architecture')
->first(function (string $platform) {
return $this->isArm($platform);
});
$supportedArchs = collect($tag['images'])->pluck('architecture');

foreach ($this->armArchitectures as $arch) {
if ($supportedArchs->contains($arch)) {
return true;
}
}

return false;
});
};
}
Expand All @@ -81,11 +76,16 @@ protected function onlyNonArmImagesFilter()
{
return function ($tags) {
return $tags->filter(function ($tag) {
return collect($tag['images'])
$supportedArchitectures = collect($tag['images'])
->pluck('architecture')
->first(function (string $platform) {
return ! $this->isArm($platform);
});
->unique()
->values();

// When removing the arm64 option from the list, there should
// still be other options in the supported architectures
// so we can consider that the tag is not arm-only.

return $supportedArchitectures->diff($this->armArchitectures)->count() > 0;
});
};
}
Expand All @@ -95,11 +95,6 @@ protected function platform(): string
return php_uname('m');
}

protected function isArm(string $platform): bool
{
return in_array($platform, ['arm64', 'aarch64']);
}

protected function getTagsResponse(): StreamInterface
{
return $this->guzzle
Expand Down
7 changes: 6 additions & 1 deletion app/Shell/ElasticDockerTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ public function getTags(): Collection
->reverse()
->filter(function ($tag) {
return ! Str::contains($tag, 'SNAPSHOT');
});
})
->filter(function ($tag) {
return ! Str::startsWith($tag, 'sha256-');
})
->sort(new VersionComparator)
->values();
}

protected function getAuthResponse(): StreamInterface
Expand Down
Loading

0 comments on commit a8a6e9a

Please sign in to comment.