Jump to content

RockShell - a ProcessWire Commandline Companion ⌨️


bernhard
 Share

Recommended Posts

RockShell v2.0.0 is out.

It's been in development for quite a long time and I use it on a daily basis. 

This module is a little special, as it has to be placed in the PW root folder (not in /site/modules). From there you can then call the shell interface via "php RockShell/rockshell"

251757691-3858509e-5522-476c-acd0-dd3154

You can then use the "symlink" command to create a symlink in the root folder. After that you can call rockshell via "php rock" in the pw root folder.

I've made it as easy as possible to create custom commands - you only need one config() and one handle() method!

68747470733a2f2f692e696d6775722e636f6d2f

https://github.com/baumrock/RockShell/

  • Like 7
  • Thanks 3
Link to comment
Share on other sites

  • 1 month later...

v2.1.0 is out ??

 

Bug Fixes

  • command db:pull using old syntax (52f78e4)
  • install command not working for dotnetic (2a68b11)
  • rename rockshell to rock everywhere and update readme (2697bd6)

Features

  • add DbDownload command (2e91be7)
  • add warning if PHP version is too low (a8caca8)

We have a new db:download command and I created an alias for my laptop so that I can simply call "rockshell db:pull staging" instead of "ddev php rock db:pull staging" which is really nice if you use it often.

  • Like 2
Link to comment
Share on other sites

  • 3 months later...

Awesome stuff @bernhard I have incorperated rockshell to my workflow (together with ddev, thanks for that video, just found it). Togerther with RockMigrations they are a great improvement.

A thing I noticed it doesn't delete install file and folder (and also non-used site profile, though I'm not sure the default installation deletes these)

  • Thanks 1
Link to comment
Share on other sites

Yes, I have added rockshell alias, and a function to make it some less effort to get default setup.

function setup_spinbox_project() {
    # Convert project name to lowercase
    local project_name=$(echo "$1" | tr '[:upper:]' '[:lower:]')

    # Check if project name is provided
    if [[ -z "$project_name" ]]; then
        echo "Please provide a project name."
        return 1
    fi

    # Clone the repository and check for success
    git clone git@gitlab.com:#############################.git "$project_name"
    if [ $? -ne 0 ]; then
        echo "Failed to clone the repository. Check your access rights."
        return 1
    fi

    # Change to the project directory
    cd "$project_name" || return

    # Run ddev config
    ddev config

    # Automatically add phpMyAdmin to .ddev/config.yaml
    echo "services:" >> .ddev/config.yaml
    echo "  phpmyadmin:" >> .ddev/config.yaml
    echo "    type: phpmyadmin" >> .ddev/config.yaml
    echo "    port: 8036" >> .ddev/config.yaml

    # Start ddev
    ddev start

    # Run RockShell commands
    rockshell pw:download
    rockshell pw:install

    echo "Setup for $project_name complete."
}

 

  • Like 1
Link to comment
Share on other sites

Nice ? Why are you adding phpmyadmin? Isn't that a ddev default anyhow? 

45 minutes ago, Spinbox said:

A thing I noticed it doesn't delete install file and folder (and also non-used site profile, though I'm not sure the default installation deletes these)

And could you please give me some more details if there's something that should be fixed here?

Link to comment
Share on other sites

19 minutes ago, bernhard said:

Nice ? Why are you adding phpmyadmin? Isn't that a ddev default anyhow? 

1 hour ago, Spinbox said:

It isn't anymore. but the following code can be changed for ddev get ddev/ddev-phpmyadmin

  # Automatically add phpMyAdmin to .ddev/config.yaml
    echo "services:" >> .ddev/config.yaml
    echo "  phpmyadmin:" >> .ddev/config.yaml
    echo "    type: phpmyadmin" >> .ddev/config.yaml
    echo "    port: 8036" >> .ddev/config.yaml
  • When you have to choose Timezone you have to set an integer (god knows which), instead of for example Europe/Amsterdam
  • 19 minutes ago, bernhard said:

    And could you please give me some more details if there's something that should be fixed here?

    I will try to look into the specifics

  • Thanks 1
Link to comment
Share on other sites

It's probably easier to use Adminer (since I also use tracy). I have been using phpmyadmin for so long that I didn't think about alternatives ? 

I have tried to get the pw:install command working. It looks like the stepAdmin data isn't being saved (url, user credentials,) or executed properly, the install files don't get deleted either.
owever, this does work when I use them as options --name=Name etc. Not sure why that is.


After some more testing I found out I actually didn't delete the previous databases these tries. My bad.

Edited by Spinbox
Link to comment
Share on other sites

  • 1 month later...

Ho,

is it possible to config that (for example) the db:pull command will use a ssh-key file and the place would be configurable via the $config options? I mean, i know it can't use my ssh-agent on the host, but it would help in a team env, where you add the keys of the dev's in the authorization file on the server.

 

Never mind, the answer is to load the .ssh in the ddev container... (from the ddev manual)

  • If you use SSH inside the container and want to use your .ssh/config, consider mkdir -p ~/.ddev/homeadditions/.ssh && ln -s ~/.ssh/config ~/.ddev/homeadditions/.ssh/config. Some people will be able to symlink their entire .ssh directory, ln -s ~/.ssh ~/.ddev/homeadditions/.ssh. If you provide your own .ssh/config though, please make sure it includes these lines:

UserKnownHostsFile=/home/.ssh-agent/known_hosts
StrictHostKeyChecking=accept-new

 

The option can set global, like above in ~/.ddev or per project projectFolder/.ddev

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

From the Rock Monthly newsletter:

 RockShell v3.0.0

  • Folders are now protected from direct access via .htaccess thx to  a PR from @netcarver (but I don't think it was a security risk before)
  • @netcarver also suggested to change the folder structure. This might break some commands, so I bumped the version to 3.0 (it might work without any changes though!)
  • Made wget quiet in pw:install command as requested by @netcarver
  • Like 2
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...

@bernhard Can pw:install be completely unattended if I execute it with all the required options on the command line (which I'm guessing is not possible for database info) or does it require "stepping" through given that it's built with BrowserKit?

Note: I'm not using ddev if that matters.

  • Like 1
Link to comment
Share on other sites

On 8/13/2024 at 10:14 PM, Jonathan Lahijani said:

@bernhard Can pw:install be completely unattended if I execute it with all the required options on the command line (which I'm guessing is not possible for database info) or does it require "stepping" through given that it's built with BrowserKit?

Note: I'm not using ddev if that matters.

Wire-cli can do that (as a successor to Wireframe). I use it to script PW installation together with RockMigrations.

I've written to @ryan about PW cli installation out of the box. Asked him if he would be interested to implement it. He didn't decide to work on this task yet, but he gave me this advice. I think he wouldn't mind if I repost it here:

Quote

The way you describe it [all the steps needed to create an installation would be abstracted in a class, that could be included both in web installer script and a cli installer script] makes sense to me, having a class that contains it all. It already does, but of course that class contains both the interactive and install code, rather than just the install code. The main purpose of the installer really is just the interactive portion of it. Technically you could clone a just-installed copy to another location, dump the DB to a db.sql file and that would leave you with just these steps:

1. Import the DB from the shell: mysql -uuser -ppass -hhost dbName < db.sql

2. Update the /site/config.php (dbName, dbUser, dbPass, dbHost, httpHosts, userAuthHash)

3. Boot PW include('./index.php') so you can $users->get('admin')->setAndSave('pass', 'hello123'); 

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hi @bernhard , I made a script which dumps the ProcessWire database via RockShell, syncs all my local files to the production server via rsync, connects via SSH to the remote server and then restores the database via RockShell on the remote server. With ddev auth ssh before, the whole script now runs without interaction, except php RockShell/rock db:restore. This command always asks if I am sure to restore the database and trying the parameter -n doesn't help, because the default option ist to abort the command.

Would it be possible that you would switch the default of db:restore from abort to import, or add a parameter which overrides the default? Then in combination with -n the deployment script could run without interaction ... That would be great!

Link to comment
Share on other sites

Hey @nurkka that sounds great!

Could you please be more specific about the problem? If I look into the code I see this:

    // confirm
    if(!$this->option("y") AND
      !$this->confirm("Do you really want to restore the db from file $file?")) {
      $this->write("Aborting...");
      return self::SUCCESS;
    }

Is that what you are talking about? If so, then adding -y should be all you need?

Or are you talking about something else?

PS: Are you willing to share your command? It sounds really nice.

  • Thanks 1
Link to comment
Share on other sites

Thank you @bernhard , the parameter -y did the trick! Now db:restore also runs the migrations, but I don't mind that. Does -y always answer all interactive questions with "yes" or only in this case? I didn't find it in the RockShell help and docs. If I didn't miss it somehow, it would be great if it could be added to the help/docs sometime.

4 hours ago, bernhard said:

PS: Are you willing to share your command? It sounds really nice.

No problem 🙂 I created a file named ddsync.sh in my local webroot with the following contents:

#!/bin/bash

# Step 1: Dump the database
php RockShell/rock db:dump

# Step 2: Sync files with rsync
rsync -avz --exclude-from='rsync-exclude.txt' . username@remote_server:~/path/to/webroot

# Step 3: SSH into the remote server and restore the database
ssh username@remote_server "cd ~/path/to/webroot && php RockShell/rock db:restore -y -vv"

Given you started DDEV and did `ddev auth ssh` before, you can now start the script with `ddev exec ./ddsync.sh`

Of course one could modify the -vv or -y parameters, but I wanted it to run verbose and without any user interaction.

My `rsync-exclude.txt` contains exclusions for all files and folders I do not want to be uploaded to the production server, e.g. `config-local.php` or 'ddsync.sh` itself. You can find details here: https://linuxize.com/post/how-to-exclude-files-and-directories-with-rsync/#exclude-multiple-files-or-directories

As rsync only uploads changed files, this is very fast, but my current project has only a handful of pages and a small database. So I don't have insights regarding the upload speed with bigger websites yet.

I'm workig with Windows, WSL2, Docker Desktop and DDEV running under Windows, so one may have to make some modifications to run that on a Mac.

Link to comment
Share on other sites

4 hours ago, nurkka said:

Does -y always answer all interactive questions with "yes" or only in this case?

It's not a general convention, but you'll likely also find it in other commands, as "yes" is something commonly needed and the "-n" flag is reserved for "no interaction"

4 hours ago, nurkka said:

No problem 🙂 I created a file named ddsync.sh in my local webroot with the following contents:

Ok thx. I thought you made a rockshell command that might also be useful for others 🙂 You can have a look at https://www.baumrock.com/en/processwire/modules/rockshell/docs/custom/ if you want. I think adding commands as rockshell commands is really great and has a lot of benefits over creating bash scripts. You can create interactive commands in no time and you get all available commands listed when typing "rockshell" without any arguments. This is great when coming back to an old project, but not only then. And you can use PW api in those commands via $this->wire()->...

Link to comment
Share on other sites

Thanks @bernhard , I will definitely have a look at the custom scripts possibility of RockShell. For now, I have to stick to the bash script.

Regarding RPB and RF I have another question: Did I understand it correctly that if I am _not_ uploading my SCSS and JS source files to production, RockFrontend will (on the production server) still include the already bundled files from /site/templates/bundle/ in the <head>? I didn't find that detail in the docs and just wanted to make sure, that my approach is basically correct.

 

Link to comment
Share on other sites

3 minutes ago, nurkka said:

Regarding RPB and RF I have another question: Did I understand it correctly that if I am _not_ uploading my SCSS and JS source files to production, RockFrontend will (on the production server) still include the already bundled files from /site/templates/bundle/ ? I didn't find that in the docs and just wanted to make sure, that my approach is basically correct.

This is a very good question, but not for the RockShell thread. I'll write you a PM.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...