Semantic Versioning for PHP projects

Posted on Updated on

Download the gist

Creates a VERSION file if it doesn’t exist in current directory.
Version should be in the format. {Major.Minor.Patch}
Patch has a suffix -dev for non-release versions

This script can be used for automating the release process of a php project using something like Jenkins.

Usage:
php bumpversion.php [options]

  • options:
    • --version [part] (required)
      • part = part of the version to increase, e.g. minor, major, patch, release
        if part = release, then -dev is removed from the current version
        Note: prints current version number if part is not specified
    • --dryrun
      outputs the outcome but doesn’t update the version file
    • --commit
      commits the updated version file
    • -f|--force
      forcefully commit file
    • --tag
      creates a tag on release

 

Advertisements

When does ECS update docker Image on EC2 instances

Posted on

Scenario:
Created ECS Service using a task definition taskdef:1 which uses docker image 057052237742.dkr.ecr.ap-southeast-2.amazonaws.com/foo/bar:latest. Now
If I push new version of the the docker image ​057052237742.dkr.ecr.ap-southeast-2.amazonaws.com/foo/bar:latest using same tag latest, will the service automatically use the updated latest docker image?

The answer is Yes.

Detailed Answer:

Every time you start a task (either through the StartTask and RunTask API calls or that is started automatically as part of a Service), the ECS Agent will perform a docker pull of the image you specify in your task definition. If you use the same image name (including tag) each time you push to your registry, you should be able to have the new image run by running a new task. Note that if Docker cannot reach the registry for any reason (e.g., network issues or authentication issues), the ECS Agent will attempt to use a cached image; if you want to avoid cached images from being used when you update your image, you’ll want to push a different tag to your registry each time and update your task definition correspondingly before running the new task.

You can find more details in the agent log files which are usually in /var/log/ecs

Ref: https://stackoverflow.com/a/34844812/2427167

Create redundant large file in linux

Posted on

dd if=/dev/zero of=file.txt count=1024 bs=1024
This command will create a file of size count*bs bytes, which in this case will be 1Mb.

dd if=/dev/zero of=file.txt count=1024 bs=1048576
Usage for 1Gb file.

Python Script to load or dump data into redis

Posted on

Download this gist

Install the following requirements into your virtual environemnt
pip install click redis

Usage:
To load data into redis
python redis_dump.py load [filepath]

To dump data into redis
python redis_dump.py dump [filepath] --search '*txt'

Python: return value from constructor

Posted on Updated on

If you want to return something other than the class instance while creating an instance of a class, use python’s __new__ method.

__new__ is the first step of instance creation. It’s called first, and is responsible for returning a new instance of your class. In contrast, __init__doesn’t return anything; it’s only responsible for initializing the instance after it’s been created.

class MyClass(object):
    def __init__(self):
        pass
    def __new__(cls):
        if i_want_to_return_something_else:
            return something_other_than_object_instance
        else:
            # this should be written else the new instance will never be returned when this class is instanciated
            return super(MyClass, cls).__new__(cls)

Pip install mysqlclient on Amazon linux gives OSError: mysql_config not found

Posted on Updated on

As suggested by https://github.com/PyMySQL/mysqlclient-python
You need to install 2 packages on you amazon linux ec2 instance:
sudo yum install python-devel mysql-devel

Name of the packages are more specific in amazon linux.
yum list | grep python3
shows you a list of python-devel packages
Install the package that meets your requirement.

sudo yum list | grep mysql
shows you a list of mysql-devel packages
Install the package that meets your requirement

In my case
sudo yum install python36-devel
yum install mysql57-devel
did the job.

Hope that helps.
Thankx for reading. Cheers!!!

Linux Command Cheatsheet

Posted on Updated on

View and Follow the End of Text Files

tail example.txt -f
# filter with grep 
tail -F test.log | grep "foo" 

Set environment variables for executing a command

var1=foo1 var2=foo2 python run.py