From bb8f209c916d97d7e7f71dae59b474a53c9d7cde Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 12:54:01 +0100 Subject: [PATCH 1/8] Create a test PHP project and test the roadrunner workflow --- .gitignore | 1 - molecule/default/converge.yml | 5 ++++ molecule/default/verify.yml | 47 ++++++++++++++++++++++++++++++++--- molecule/files/app.php | 23 +++++++++++++++++ 4 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 molecule/files/app.php diff --git a/.gitignore b/.gitignore index 9e8b6b1..9ab76a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .DS_Store *.pyc __pycache__ -files/ diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 146ce07..4888dd6 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -4,6 +4,11 @@ environment: GITHUB_ACTIONS: "maybe" vars: + php: + install_composer: yes + roadrunner: + config: + main: system: features: proserver_user: yes diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index a5cfa75..f330ee8 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -5,6 +5,47 @@ hosts: all gather_facts: false tasks: - - name: Example assertion - ansible.builtin.assert: - that: true + - name: Create the current_release folder + ansible.builtin.file: + dest: "{{ item }}" + state: "directory" + owner: proserver + mode: "0755" + loop: + - "{{ roadrunner.prefix.current_release }}" + - "{{ roadrunner.prefix.current_release }}/public" + + - name: Copy the example PHP script + ansible.builtin.copy: + src: "molecule/files/app.php" + dest: "{{ roadrunner.prefix.current_release }}/app.php" + + - name: Initialize the composer project + community.general.composer: + command: create-project + arguments: "punktde/roadrunner-test {{ roadrunner.prefix.current_release }} ~1.0" + working_dir: "{{ roadrunner.prefix.current_release }}" + prefer_dist: true + + - name: Install PHP dependencies + community.general.composer: + command: require + arguments: "{{ item }}" + working_dir: "{{ roadrunner.prefix.current_release }}" + loop: + - "nyholm/psr7" + - "spiral/roadrunner" + - "spiral/roadrunner-http" + + - name: Enable and start the roadrunner-main service + community.general.supervisorctl: + name: "roadrunner-main" + state: "present" + stop_before_removing: yes + + - name: Check that a page returns successfully but fail if the word AWESOME is not in the page contents + ansible.builtin.uri: + url: http://{{ roadrunner.defaults.http.address }} + return_content: true + register: this + failed_when: this is failed or "'Hello world' not in this.content" diff --git a/molecule/files/app.php b/molecule/files/app.php new file mode 100644 index 0000000..b6fadfe --- /dev/null +++ b/molecule/files/app.php @@ -0,0 +1,23 @@ +waitRequest()) { + try { + $rsp = new Psr7\Response(); + $rsp->getBody()->write('Hello world!'); + + $worker->respond($rsp); + } catch (\Throwable $e) { + $worker->getWorker()->error((string)$e); + } +} +?> From 31cfc5a7ee3fd4dd1fc03538b28dda10fa0c6274 Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 13:00:16 +0100 Subject: [PATCH 2/8] Disable idempotence checks for the roadrunner systemd path unit --- tasks/config-Debian.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tasks/config-Debian.yml b/tasks/config-Debian.yml index ca981d2..035c5ce 100644 --- a/tasks/config-Debian.yml +++ b/tasks/config-Debian.yml @@ -29,6 +29,8 @@ dest: "/etc/systemd/system/roadrunner@{{ roadrunner_config.key }}.service" - name: Start and enable roadrunner@{{ roadrunner_config.key }}.path + tags: + - molecule-idempotence-notest ansible.builtin.service: daemon_reload: yes name: roadrunner@{{ roadrunner_config.key }}.service From 37e14504db39303512635b1a2f1dcd350d7c783f Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 13:06:25 +0100 Subject: [PATCH 3/8] Replace variables with hardcoded values in the verify stage --- molecule/default/verify.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index f330ee8..7304cf9 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -12,26 +12,26 @@ owner: proserver mode: "0755" loop: - - "{{ roadrunner.prefix.current_release }}" - - "{{ roadrunner.prefix.current_release }}/public" + - "/var/www/current" + - "/var/www/current/public" - name: Copy the example PHP script ansible.builtin.copy: src: "molecule/files/app.php" - dest: "{{ roadrunner.prefix.current_release }}/app.php" + dest: "/var/www/current/app.php" - name: Initialize the composer project community.general.composer: command: create-project - arguments: "punktde/roadrunner-test {{ roadrunner.prefix.current_release }} ~1.0" - working_dir: "{{ roadrunner.prefix.current_release }}" + arguments: "punktde/roadrunner-test /var/www/current ~1.0" + working_dir: "/var/www/current" prefer_dist: true - name: Install PHP dependencies community.general.composer: command: require arguments: "{{ item }}" - working_dir: "{{ roadrunner.prefix.current_release }}" + working_dir: "/var/www/current" loop: - "nyholm/psr7" - "spiral/roadrunner" @@ -45,7 +45,7 @@ - name: Check that a page returns successfully but fail if the word AWESOME is not in the page contents ansible.builtin.uri: - url: http://{{ roadrunner.defaults.http.address }} + url: http://localhost:8080 return_content: true register: this failed_when: this is failed or "'Hello world' not in this.content" From 499dddd024caf1b4870d82706ccd84fe97725e14 Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 13:12:10 +0100 Subject: [PATCH 4/8] Fixup --- molecule/{ => default}/files/app.php | 0 molecule/default/verify.yml | 4 +++- 2 files changed, 3 insertions(+), 1 deletion(-) rename molecule/{ => default}/files/app.php (100%) diff --git a/molecule/files/app.php b/molecule/default/files/app.php similarity index 100% rename from molecule/files/app.php rename to molecule/default/files/app.php diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 7304cf9..4d09164 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -17,7 +17,9 @@ - name: Copy the example PHP script ansible.builtin.copy: - src: "molecule/files/app.php" + owner: proserver + mode: "0644" + src: "app.php" dest: "/var/www/current/app.php" - name: Initialize the composer project From 2e88472054989df83352a5fe33177e813bfad89b Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 13:16:54 +0100 Subject: [PATCH 5/8] Fixup --- molecule/default/verify.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 4d09164..04e9206 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,5 +1,3 @@ ---- -# This is an example playbook to execute Ansible tests. - name: Verify hosts: all @@ -13,14 +11,6 @@ mode: "0755" loop: - "/var/www/current" - - "/var/www/current/public" - - - name: Copy the example PHP script - ansible.builtin.copy: - owner: proserver - mode: "0644" - src: "app.php" - dest: "/var/www/current/app.php" - name: Initialize the composer project community.general.composer: @@ -29,6 +19,7 @@ working_dir: "/var/www/current" prefer_dist: true + - name: Install PHP dependencies community.general.composer: command: require @@ -39,6 +30,22 @@ - "spiral/roadrunner" - "spiral/roadrunner-http" + - name: Create the current_release folder + ansible.builtin.file: + dest: "{{ item }}" + state: "directory" + owner: proserver + mode: "0755" + loop: + - "/var/www/current/public" + + - name: Copy the example PHP script + ansible.builtin.copy: + owner: proserver + mode: "0644" + src: "app.php" + dest: "/var/www/current/app.php" + - name: Enable and start the roadrunner-main service community.general.supervisorctl: name: "roadrunner-main" From 44a70287892537b47682da4aa049e24eaf633fd2 Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 16:31:42 +0100 Subject: [PATCH 6/8] Fixup --- molecule/default/verify.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 04e9206..5c6f5e6 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -14,11 +14,15 @@ - name: Initialize the composer project community.general.composer: - command: create-project - arguments: "punktde/roadrunner-test /var/www/current ~1.0" + command: init + arguments: >- + --name punktde/roadrunner-test + --description= + --type=project + --author= + --homepage= + --no-interaction working_dir: "/var/www/current" - prefer_dist: true - - name: Install PHP dependencies community.general.composer: @@ -30,7 +34,7 @@ - "spiral/roadrunner" - "spiral/roadrunner-http" - - name: Create the current_release folder + - name: Create the current_release public folder ansible.builtin.file: dest: "{{ item }}" state: "directory" @@ -52,7 +56,7 @@ state: "present" stop_before_removing: yes - - name: Check that a page returns successfully but fail if the word AWESOME is not in the page contents + - name: Check that a page returns successfully but fail if the word "Hello world" is not in the page contents ansible.builtin.uri: url: http://localhost:8080 return_content: true From ca2fe5d70c6e8f8409a472f8fcd3a29b188118e2 Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 16:37:33 +0100 Subject: [PATCH 7/8] Fixup --- molecule/default/verify.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 5c6f5e6..fd0e884 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,4 +1,4 @@ - +--- - name: Verify hosts: all gather_facts: false @@ -50,13 +50,13 @@ src: "app.php" dest: "/var/www/current/app.php" - - name: Enable and start the roadrunner-main service - community.general.supervisorctl: - name: "roadrunner-main" - state: "present" - stop_before_removing: yes + - name: Start the roadrunner-main service + ansible.builtin.service: + name: "roadrunner@main" + state: "started" + enabled: yes - - name: Check that a page returns successfully but fail if the word "Hello world" is not in the page contents + - name: Check that a page returns successfully but fail if the word 'Hello world' is not in the page contents ansible.builtin.uri: url: http://localhost:8080 return_content: true From 78865497be8230b7c3ad72bc876eadda26ae3dae Mon Sep 17 00:00:00 2001 From: Wolfgang Date: Fri, 26 Jan 2024 16:46:42 +0100 Subject: [PATCH 8/8] Fixup --- molecule/default/verify.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index fd0e884..919d990 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -61,4 +61,9 @@ url: http://localhost:8080 return_content: true register: this - failed_when: this is failed or "'Hello world' not in this.content" + retries: 3 + delay: 3 + until: not this.failed + failed_when: + - this is failed + - "'Hello world!' not in this.content"