<![CDATA[Quality Addict]]>https://qualityaddict.com/https://qualityaddict.com/favicon.pngQuality Addicthttps://qualityaddict.com/Ghost 5.47Sun, 10 Mar 2024 21:58:27 GMT60<![CDATA[Buildkite: Conditional Block Step]]>In my current project, I start testing a task by deploying the related branch to the staging environment after its code review phase is done. Deploying the branch takes almost an hour because of the complexity of our application. We did not want to trigger the deployment for each commit

]]>
https://qualityaddict.com/buildkite/65ee1521f1099505b3e35dfdSun, 10 Mar 2024 21:28:06 GMTIn my current project, I start testing a task by deploying the related branch to the staging environment after its code review phase is done. Deploying the branch takes almost an hour because of the complexity of our application. We did not want to trigger the deployment for each commit since it is a costly process. So we put a block step for the deployment part in the pull request pipeline. However, developers sometimes forgot to unblock this step when the task was ready for testing. It means I will have to wait for an hour to start testing when a branch is not deployed but ready for testing. I know it is not the best solution and it does not solve all the problems completely but I came up with a quick improvement:

We use the id of the related Jira task while naming a branch. I wrote a small script to send an API request to Jira with the branch name and checked the status of the task. If the task is not in the "Ready for QA" or "In QA" sections, then I added the block step. As a result, when the task is in the testing phase, the deployment to the test environments initiates automatically.

 - label: "Deploy to staging if the task is in the testing phase"
    key: "auto-deploy"
    command: python check_jira_status.py
    soft_fail: true

  - wait: ~

  - command : |
      if [ $$(buildkite-agent step get "outcome" --step "auto-deploy") == "soft_failed" ]; then
        cat <<- YAML | buildkite-agent pipeline upload
        steps:
          - block: ":rocket: Deploy it!"
      YAML
      fi
  
  - wait: ~

Thus, I was able to add a conditional block step and save the time we lost when we forgot to unblock the deployment step. This was especially great for the commits made during the testing phase. As I said before, it does not solve all the problems; if the task is moved to the testing phase after a commit, I still need to unblock the step manually. I am also planning to trigger the deployment when the task status is changed by using Jira webhooks. However, I didn't have time to do that, so I applied the quickest solution for now. I also wanted to share this with you because the conditional blocking step is not clearly explained in the Buildkite documentation. I hope it helps for you too.

]]>
<![CDATA[How to change the admin password of your local Ghost Blog setup]]>It's been almost two years since I purchased the domain qualityaddict.com and set up a Ghost blogging platform on my local machine. During this time, I've drafted several blog posts, but I didn't feel they are ready for publication, so I put off

]]>
https://qualityaddict.com/how-to-reset/65d67aefef91bb0f6189115fWed, 21 Feb 2024 23:41:00 GMTIt's been almost two years since I purchased the domain qualityaddict.com and set up a Ghost blogging platform on my local machine. During this time, I've drafted several blog posts, but I didn't feel they are ready for publication, so I put off on launching my website until now.

However, today was the day I finally decided to publish QualityAddict.com. Excitedly, I attempted to log in to the local admin dashboard, only to hit a major roadblock—I couldn't remember my password! Despite trying every possible combination, I couldn't sign into the dashboard. Of course, I hadn't configured an SMTP server for my local setup, which meant I couldn't utilize the forgot password flow.

There was only one option left: updating the password directly from the database! Let me explain step by step so if I forget again in the future I would be able to reset it quickly!

Download the password.js file from their repository: https://github.com/TryGhost/Utils/blob/main/packages/security/lib/password.js

Fortunately, they don't store passwords as plain teTherefore, we need to hash the new password string just as they do. Their code look like as below, but it's crucial to ensure that you're using the most updated version.

const Promise = require('bluebird');

module.exports.hash = function hash(plainPassword) {
    const bcrypt = require('bcryptjs');
    const bcryptGenSalt = Promise.promisify(bcrypt.genSalt);
    const bcryptHash = Promise.promisify(bcrypt.hash);

    return bcryptGenSalt().then(function (salt) {
        return bcryptHash(plainPassword, salt);
    });
};

module.exports.compare = function compare(plainPassword, hashedPassword) {
    const bcrypt = require('bcryptjs');
    const bcryptCompare = Promise.promisify(bcrypt.compare);

    return bcryptCompare(plainPassword, hashedPassword);
};

Currently, we need to install the following dependencies to run the code above:

npm install bluebird
npm install bcryptjs

Then create a file named generatePassword.js

require('./password').hash(process.argv[2]).then(console.log);
Password.js and generatePassword.js should be located in the same directory.

We can hash strings right now, for example:

node generatePassword.js "test123"

You will see the hashed version of the string in the console.

We need to replace the password field with the new one in the database record, but the question arises: where is the database located?

Let's check the config.development.json file:

  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/home/..../ghost-local.db"
    }
  }

As you can see, it uses a local database solution named sqlite3 and we can easily connect it:

sqlite3 /home/..../ghost-local.db

Finally, we can replace the password by running the following query:

UPDATE users
  SET
    password = 'NEW_PASSWORD_HASH'
  WHERE id = 1;

So we can sign into the dasboard with your new password!

]]>