Skip to content

Devenv v2 docker image already working with services?Β #2590

Description

@pbek

Describe the bug

We are using a (private) GitLab CI to run database migration tests with devenv test.

Expand
# DB Migration Tests
devenv-test:
    rules:
        - if: $CI_PIPELINE_SOURCE != "schedule"
    stage: test
    image: ghcr.io/cachix/devenv/devenv:v2.0.2
    script: devenv test
    retry: 2

Our devenv.nix looks something like:

Expand
{
  pkgs,
  config,
  ...
}:

{
  # https://devenv.sh/supported-languages/php/
  languages.php = {
    enable = true;
    # We are using PHP 8.3 (and not 8.4), because of php-cs-fixer
    version = "8.3";
    ini = ''
      memory_limit = 256M
    '';
    extensions = [
      "ldap"
      "gd"
      "pdo_mysql" # For "devenv test"
      "soap"
      "ldap"
      "mbstring"
      "intl"
      "curl"
      "readline"
      "zip"
      "redis"
      "gmp"
      "sqlite3"
    ];
  };

  # https://devenv.sh/supported-services/mysql/
  services.mysql = {
    enable = true;
    initialDatabases = [
      { name = "db1"; }
      { name = "db2"; }
    ];
    ensureUsers = [
      {
        name = "db";
        password = "secret";
        ensurePermissions = {
          "db1.*" = "ALL PRIVILEGES";
          "db2.*" = "ALL PRIVILEGES";
        };
      }
    ];
  };

  # https://devenv.sh/integrations/dotenv/
  dotenv = {
    enable = true;
    filename = [
      # For the tests to run you need access to the SYMFONY_DECRYPTION_SECRET environment variable from .env.dev.local
      ".env.dev.local"
    ];
  };

  # https://devenv.sh/scripts/
  scripts = {
    db-clean.exec = ''
      echo "πŸ—‘οΈ Cleaning DB state"
      rm -rf .devenv/state/mysql/
    '';

    db-migrate.exec = ''
      echo "πŸ“₯ Running DB migrations"
      php bin/console dbp:relay:core:migrate --no-interaction
    '';
  };

  env.BIN_DIR = "${config.devenv.root}/bin";

  enterShell = ''
    echo "πŸ”¨ Middleware API shell"
    echo "🐘 PHP version: $(php --version | head -n 1)"
    echo "DEVENV_ROOT: $DEVENV_ROOT"

    echo "πŸ”— Updating PHP symlinks for PhpStorm in ''${BIN_DIR}..."
    ln -fs ${pkgs.php83}/bin/php "''${BIN_DIR}/php"
    ln -fs ${pkgs.php83}/bin/phpdbg "''${BIN_DIR}/phpdbg"
  '';

  # https://devenv.sh/tests/
  enterTest = ''
    wait_for_port 3306
    echo "πŸ”¨ Loading .env.devenv_test"
    set -a
    source .env.devenv_test
    set +a
    echo "πŸ”¨ Doing composer install"
    composer install
    echo "πŸ”¨ Running DB clean"
    db-clean
    echo "πŸ”¨ Running DB migrations"
    db-migrate
  '';

  # https://devenv.sh/packages/
  packages = with pkgs; [
    symfony-cli
    sshuttle # for dispatch / Vendo
    fzf # fuzzy finder
  ];

  # https://devenv.sh/git-hooks/
  git-hooks = {
    excludes = [
      "config/secrets"
      "vendor"
      "bin"
    ];
    hooks = {
      php-cs-fixer = {
        enable = true;
        args = [
          "--config"
          "./.php-cs-fixer.dist.php"
        ];
        excludes = [ "config/bundles.php" ];
        # Don't spam so many messages
        require_serial = true;
      };

      prettier.args = [
        "--tab-width"
        "4"
      ];
    };
  };

  # See full reference at https://devenv.sh/reference/options/
}

This worked great so far with the devenv v1 docker image, but now with devenv v2 we run into a timeout after spending the rest of an hour waiting after a log message Error reading stdout: stream did not contain valid UTF-8. Before we get that error message it is successfully setting up the database, doing migrations and so on. But after a bit over 4Β min we get that error message.

Last log lines:

Expand
[2026-03-09T14:16:52.746008+00:00] app.INFO: ++ migrating Dbp\Relay\AuthorizationBundle\Migrations\Version20251111142100 (create the authorization_group_resource_members table) {"version_name":"Dbp\\Relay\\AuthorizationBundle\\Migrations\\Version20251111142100 (create the authorization_group_resource_members table)"} []
[2026-03-09T14:16:52.746069+00:00] app.DEBUG: CREATE TABLE authorization_group_resource_members (identifier BINARY(16) NOT NULL COMMENT '(DC2Type:uuid_binary)', group_authorization_resource_identifier BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid_binary)', member_authorization_resource_identifier BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid_binary)', PRIMARY KEY (identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB  {"query":"CREATE TABLE authorization_group_resource_members (identifier BINARY(16) NOT NULL COMMENT '(DC2Type:uuid_binary)', group_authorization_resource_identifier BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid_binary)', member_authorization_resource_identifier BINARY(16) DEFAULT NULL COMMENT '(DC2Type:uuid_binary)', PRIMARY KEY (identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB","params":""} []
[2026-03-09T14:16:52.752496+00:00] app.DEBUG: ALTER TABLE authorization_group_resource_members ADD CONSTRAINT FK_5C8C8E3E213E78E1 FOREIGN KEY (group_authorization_resource_identifier) REFERENCES authorization_resources (identifier) ON DELETE CASCADE  {"query":"ALTER TABLE authorization_group_resource_members ADD CONSTRAINT FK_5C8C8E3E213E78E1 FOREIGN KEY (group_authorization_resource_identifier) REFERENCES authorization_resources (identifier) ON DELETE CASCADE","params":""} []
[2026-03-09T14:16:52.768617+00:00] app.DEBUG: ALTER TABLE authorization_group_resource_members ADD CONSTRAINT FK_5C8C8E3E6F5DFD0B FOREIGN KEY (member_authorization_resource_identifier) REFERENCES authorization_resources (identifier) ON DELETE CASCADE  {"query":"ALTER TABLE authorization_group_resource_members ADD CONSTRAINT FK_5C8C8E3E6F5DFD0B FOREIGN KEY (member_authorization_resource_identifier) REFERENCES authorization_resources (identifier) ON DELETE CASCADE","params":""} []
[2026-03-09T14:16:52.789194+00:00] app.INFO: Migration Dbp\Relay\AuthorizationBundle\Migrations\Version20251111142100 migrated (took 43.2ms, used 40.5M memory) {"version":"Dbp\\Relay\\AuthorizationBundle\\Migrations\\Version20251111142100","time":43.19999999999999,"memory":"40.5M","direction":"migrated"} []
[2026-03-09T14:16:52.790500+00:00] app.INFO: ++ migrating Dbp\Relay\AuthorizationBundle\Migrations\Version20251112093200 (create the tables authorization_available_resource_class_actions and authorization_available_resource_class_action_names and populate them with the group actions) {"version_name":"Dbp\\Relay\\AuthorizationBundle\\Migrations\\Version20251112093200 (create the tables authorization_available_resource_class_actions and authorization_available_resource_class_action_names and populate them with the group actions)"} []
[2026-03-09T14:16:52.790689+00:00] app.DEBUG: CREATE TABLE authorization_available_resource_class_actions (identifier BINARY(16) NOT NULL, resource_class varchar(40) NOT NULL, action varchar(40) NOT NULL, action_type tinyint(1), PRIMARY KEY (identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB  {"query":"CREATE TABLE authorization_available_resource_class_actions (identifier BINARY(16) NOT NULL, resource_class varchar(40) NOT NULL, action varchar(40) NOT NULL, action_type tinyint(1), PRIMARY KEY (identifier)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB","params":""} []
[2026-03-09T14:16:52.797542+00:00] app.DEBUG: ALTER TABLE authorization_available_resource_class_actions ADD CONSTRAINT unique_resource_class_action UNIQUE (resource_class, action, action_type)  {"query":"ALTER TABLE authorization_available_resource_class_actions ADD CONSTRAINT unique_resource_class_action UNIQUE (resource_class, action, action_type)","params":""} []
[2026-03-09T14:16:52.811078+00:00] app.DEBUG: CREATE TABLE authorization_available_resource_class_action_names (available_resource_class_action_identifier BINARY(16) NOT NULL, language_tag VARCHAR(2) NOT NULL, name VARCHAR(64) NOT NULL, PRIMARY KEY(available_resource_class_action_identifier, language_tag), FOREIGN KEY(available_resource_class_action_identifier) REFERENCES authorization_available_resource_class_actions(identifier) ON DELETE CASCADE)  {"query":"CREATE TABLE authorization_available_resource_class_action_names (available_resource_class_action_identifier BINARY(16) NOT NULL, language_tag VARCHAR(2) NOT NULL, name VARCHAR(64) NOT NULL, PRIMARY KEY(available_resource_class_action_identifier, language_tag), FOREIGN KEY(available_resource_class_action_identifier) REFERENCES authorization_available_resource_class_actions(identifier) ON DELETE CASCADE)","params":""} []
Error reading stdout: stream did not contain valid UTF-8
WARNING: step_script could not run to completion because the timeout was exceeded. For more control over job and script timeouts see: https://docs.gitlab.com/ci/runners/configure_runners/#set-script-and-after_script-timeouts
ERROR: Job failed: execution took longer than 1h0m0s seconds

Locally on my NixOS box I can run devenv test just fine with devenv v2!

To reproduce

Disclaimer: Will be hard to reproduce, since I can't share the full infrastructure. 😬 I was just hoping something rings a bell why the docker image is not working the same still.

Running docker run --rm -e DEVENV_HOME=/tmp/.devenv-home -v "$PWD":/work -w /work ghcr.io/cachix/devenv/devenv:v1.11.1 bash -lc 'devenv test' (or with ghcr.io/cachix/devenv/devenv:v1.11.1 in GitLab CI) did work.

Running docker run --rm -e DEVENV_HOME=/tmp/.devenv-home -v "$PWD":/work -w /work ghcr.io/cachix/devenv/devenv:v2.0.2 bash -lc 'devenv test' ran into a timeout after not outputting anything else after an error message Error reading stdout: stream did not contain valid UTF-8.

Version

devenv 2.0.1 (x86_64-linux)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions