Skip to content

Commit

Permalink
Merge v2.1.6 - upgrade-MySQLContainerConfig
Browse files Browse the repository at this point in the history
 - `PostgreSQLContainerConfig`, `MySQLContainerConfig`, `ApacheHttpdContainerConfig`, `NginxContainerConfig`:
   - Constructor: expose `version` parameter.

 - `MySQLContainerConfig`:
   - Fix `_buildImageArgs` for version `8.4.0`+.

 - swiss_knife: ^3.2.0
 - mercury_client: ^2.2.2
 - apollovm: ^0.0.53
 - version: ^3.0.2
 - test: ^1.25.5
 - path: ^1.9.0
  • Loading branch information
gmpassos authored May 18, 2024
2 parents 3071186 + d632230 commit c0a4208
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 2.1.6

- `PostgreSQLContainerConfig`, `MySQLContainerConfig`, `ApacheHttpdContainerConfig`, `NginxContainerConfig`:
- Constructor: expose `version` parameter.

- `MySQLContainerConfig`:
- Fix `_buildImageArgs` for version `8.4.0`+.

- swiss_knife: ^3.2.0
- mercury_client: ^2.2.2
- apollovm: ^0.0.53
- version: ^3.0.2
- test: ^1.25.5
- path: ^1.9.0

## 2.1.5

- apollovm: ^0.0.45
Expand Down
2 changes: 1 addition & 1 deletion lib/src/docker_commander_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'docker_commander_host.dart';
class DockerCommander extends DockerCMDExecutor {
/// The current version of `docker_commander` package.
// ignore: non_constant_identifier_names
static final String VERSION = '2.1.5';
static final String VERSION = '2.1.6';

/// Docker machine host.
final DockerHost dockerHost;
Expand Down
37 changes: 29 additions & 8 deletions lib/src/docker_commander_containers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:swiss_knife/swiss_knife.dart';
import 'package:version/version.dart';

import 'docker_commander_base.dart';
import 'docker_commander_host.dart';
Expand Down Expand Up @@ -147,13 +148,13 @@ class PostgreSQLContainerConfig
String pgDatabase;

PostgreSQLContainerConfig(
{this.pgUser = 'postgres',
{super.version = 'latest',
this.pgUser = 'postgres',
this.pgPassword = 'postgres',
this.pgDatabase = 'postgres',
int? hostPort})
: super(
'postgres',
version: 'latest',
hostPorts: hostPort != null ? [hostPort] : null,
containerPorts: [5432],
environment: {
Expand Down Expand Up @@ -271,6 +272,7 @@ class MySQLContainerConfig extends DockerContainerConfig<MySQLContainer> {
String dbName;

MySQLContainerConfig({
super.version = 'latest',
this.dbUser = 'myuser',
this.dbPassword = 'mypass',
this.dbName = 'mydb',
Expand All @@ -279,11 +281,10 @@ class MySQLContainerConfig extends DockerContainerConfig<MySQLContainer> {
List<String>? daemonArguments,
}) : super(
'mysql',
version: 'latest',
hostPorts: hostPort != null ? [hostPort] : null,
containerPorts: [3306],
imageArgs: _buildImageArgs(
forceNativePasswordAuthentication, daemonArguments),
version, forceNativePasswordAuthentication, daemonArguments),
environment: {
'MYSQL_USER': dbUser,
'MYSQL_PASSWORD': dbPassword,
Expand Down Expand Up @@ -312,12 +313,16 @@ class MySQLContainerConfig extends DockerContainerConfig<MySQLContainer> {
}
}

static List<String>? _buildImageArgs(
static List<String>? _buildImageArgs(String? version,
bool forceNativePasswordAuthentication, List<String>? daemonArguments) {
var args = <String>[];

if (forceNativePasswordAuthentication) {
args.add('--default-authentication-plugin=mysql_native_password');
if (_isVersionGreaterThan_8_4_0(version)) {
args.add('--mysql-native-password=ON');
} else {
args.add('--default-authentication-plugin=mysql_native_password');
}
}

if (daemonArguments != null) {
Expand All @@ -327,6 +332,23 @@ class MySQLContainerConfig extends DockerContainerConfig<MySQLContainer> {
return args.isNotEmpty ? args : null;
}

static bool _isVersionGreaterThan_8_4_0(String? version) {
version = version?.trim();

if (version == null ||
version.isEmpty ||
version.toLowerCase() == 'latest') {
return true;
}

try {
var ver = Version.parse(version);
return ver >= Version(8, 4, 0);
} catch (_) {
return false;
}
}

@override
MySQLContainer? instantiateDockerContainer(DockerRunner runner) =>
MySQLContainer(this, runner);
Expand Down Expand Up @@ -398,10 +420,9 @@ class MySQLContainer extends DockerContainer {
/// Apache HTTPD pre-configured container.
class ApacheHttpdContainerConfig
extends DockerContainerConfig<DockerContainer> {
ApacheHttpdContainerConfig({int? hostPort})
ApacheHttpdContainerConfig({super.version = 'latest', int? hostPort})
: super(
'httpd',
version: 'latest',
hostPorts: hostPort != null ? [hostPort] : null,
containerPorts: [80],
outputAsLines: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/docker_commander_nginx.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class NginxContainerConfig extends DockerContainerConfig<DockerContainerNginx> {

final String configPath;

NginxContainerConfig(this.config, {int? hostPort, String? configPath})
NginxContainerConfig(this.config,
{super.version = 'latest', int? hostPort, String? configPath})
: configPath = configPath ?? '/etc/nginx/nginx.conf',
super(
'nginx',
version: 'latest',
hostPorts: hostPort != null ? [hostPort] : null,
containerPorts: [80],
outputAsLines: true,
Expand Down
13 changes: 7 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: docker_commander
description: A Docker manager for local and remote host machines. Works with personalized containers and pre-configured popular containers, like PostgreSQL, Apache HTTPD and NGINX.
version: 2.1.5
version: 2.1.6
homepage: https://github.com/gmpassos/docker_commander

environment:
Expand All @@ -11,18 +11,19 @@ executables:
docker_commander_console:

dependencies:
swiss_knife: ^3.1.5
mercury_client: ^2.2.0
swiss_knife: ^3.2.0
mercury_client: ^2.2.2
logging: ^1.2.0
collection: ^1.18.0
apollovm: ^0.0.45
apollovm: ^0.0.53
version: ^3.0.2

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
test: ^1.25.5
dependency_validator: ^3.2.3
pubspec: ^2.3.0
path: ^1.8.3
path: ^1.9.0

#dependency_overrides:
# swiss_knife:
Expand Down
13 changes: 10 additions & 3 deletions test/docker_commander_containers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ Future<void> main() async {
expect(exitCode == 0 || exitCode == 137, isTrue);
});

test('MySQL', () async {
testMySQL({bool forceNativePasswordAuthentication = false}) async {
var freeListenPort =
await getFreeListenPort(startPort: 3106, endPort: 3206);

var config = MySQLContainerConfig(hostPort: freeListenPort);
var config = MySQLContainerConfig(
hostPort: freeListenPort,
forceNativePasswordAuthentication: forceNativePasswordAuthentication);
var dockerContainer = await config.run(dockerCommander);

_log.info(dockerContainer);
Expand Down Expand Up @@ -184,7 +186,12 @@ Future<void> main() async {
_log.info('exitCode: $exitCode');

expect(exitCode == 0, isTrue);
});
}

test('MySQL', () async => testMySQL());

test('MySQL',
() async => testMySQL(forceNativePasswordAuthentication: true));

test('Apache Httpd', () async {
var freeListenPort =
Expand Down

0 comments on commit c0a4208

Please sign in to comment.