{"id":13593178,"url":"https://github.com/mvanholsteijn/docker-makefile","last_synced_at":"2026-01-25T00:49:27.738Z","repository":{"id":69279569,"uuid":"45705906","full_name":"mvanholsteijn/docker-makefile","owner":"mvanholsteijn","description":"Makefile for building docker repository releases","archived":false,"fork":false,"pushed_at":"2024-02-14T13:47:26.000Z","size":47,"stargazers_count":232,"open_issues_count":1,"forks_count":49,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-02T03:37:12.121Z","etag":null,"topics":["bash","docker","makefile","semantic-release","semantic-versioning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvanholsteijn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-06T20:33:01.000Z","updated_at":"2025-03-14T19:16:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"9667cf7d-fe45-4b3f-8e2f-91250683faa5","html_url":"https://github.com/mvanholsteijn/docker-makefile","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvanholsteijn%2Fdocker-makefile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvanholsteijn%2Fdocker-makefile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvanholsteijn%2Fdocker-makefile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvanholsteijn%2Fdocker-makefile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvanholsteijn","download_url":"https://codeload.github.com/mvanholsteijn/docker-makefile/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247965691,"owners_count":21025418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","docker","makefile","semantic-release","semantic-versioning"],"created_at":"2024-08-01T16:01:17.323Z","updated_at":"2026-01-25T00:49:27.732Z","avatar_url":"https://github.com/mvanholsteijn.png","language":"Python","funding_links":[],"categories":["Python","bash"],"sub_categories":[],"readme":"# Generic Docker Makefile\nWhen working with the Docker hub, two small things bothered me:\n\n1. Waiting for your build to start\n2. No easy control over the tags for the images.\n\nTo resolve these to issues, I created a generic Makefile that allows you to build and release docker images based upon git tags, whenever you want.\n\n## Makefile targets\n\nThe Makefile has the following targets:\n```\nbuild                -  builds a new version of your container image\nsnapshot             -  builds a new version of your container image, and pushes it to the registry\n\nshowver              -  shows the current release tag based on the workspace\nshowimage            -  shows the container image name based on the workspace\n\ntag-patch-release    -  increments the patch release level and create the tag without build\ntag-minor-release    -  increments the minor release level and create the tag without build\ntag-major-release    -  increments the major release level and create the tag without build\n\npatch-release        -  increments the patch release level, build and push to registry\nminor-release        -  increments the minor release level, build and push to registry\nmajor-release        -  increments the major release level, build and push to registry\n\ncheck-status         -  checks whether there are outstanding changes\ncheck-release        -  checks whether the workspace matches the tagged release in git\n\nhelp                 -  show this help.\n```\n\n\n## How to use it.\ncopy the Makefile and .make-release-support into your Docker git project:\n\n```bash\nwget -O Makefile.mk https://raw.githubusercontent.com/mvanholsteijn/docker-makefile/master/Makefile\nwget https://raw.githubusercontent.com/mvanholsteijn/docker-makefile/master/.make-release-support\n```\n\n## Change registry, user or image name\nBy default, the registry is set to docker.io and the user to the current user. To override this, include\nthe Makefile as Makefile.mk and set the variables REGISTRY_HOST, USERNAME and NAME.\n\n```Makefile\ninclude Makefile.mk\n\nREGISTRY_HOST=myregistry.io\nUSERNAME=mvanholsteijn\nNAME=awesome-image\n```\n\n## Building an image\nto build an image, add a Dockerfile to your directory and type make:\n\n```bash\nmake\n```\n\n##  Release\nTo make a release and tag it, commit add the changes and type:\n\n```bash\nmake\tpatch-release\n```\n\nThis will bump the patch-release number, build the image and push it to the registry. It will only\nrelease if there are no outstanding changes and the content of the directory equals the tagged content.\n\nAlternatively you can choose 'make minor-release' or 'make major-release' to bump the associated number.\n\n## Release number\nThe release of your docker image is kept in the file .release and uses the following format:\n\n\trelease=\u003cmajor\u003e.\u003cminor\u003e.\u003cpatch\u003e\n\nThe name of the git tag is kept in the same file, and by default will have the format:\n\n\ttag=\u003cdirectory-name\u003e.\u003cminor\u003e.\u003cpatch\u003e\n\nThis will allow you to have track and tag multiple images in a single Git repository.\n\nIf you want to use a different tag prefix, change it in the .release.\n\n## Image name and tag\nThe name of the image will be created as follows:\n\n```\n\t\u003cregistry-host\u003e/\u003cusername\u003e/\u003cdirectory name\u003e:\u003ctag\u003e\n```\n\nThe tag is has the following format:\n\n\u003ctable \u003e\n\u003ctr\u003e\u003cth\u003eformat\u003c/th\u003e\u003cth\u003ewhen\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd valign=top\u003e\u0026lt;release\u003e \u003c/td\u003e\u003ctd\u003e  the contents of the directory is equal to tagged content in git\n\n\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd valign=top\u003e \u0026lt;release\u003e-\u0026lt;commit\u003e \u003c/td\u003e\u003ctd\u003e  the contents of the directory is not equal to the tagged content\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\u003ctd valign=top\u003e \u0026lt;release\u003e-\u0026lt;commit\u003e-dirty \u003ctd\u003e the contents of the directory has uncommitted changes\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n## Multiple docker images in a single git repository.\n\nIf you want to maintain multiple docker images in a single git repository, you can use an alternate setup where the Makefile is located in a  silbing directory.\n\n```\n├── multiple-example\n│   ├── ...\n│   ├── image1\n│   │   ├── .release\n│   │   ├── Dockerfile\n│   │   └── Makefile\n│   ├── image2\n│   │   ├── .release\n│   │   ├── Dockerfile\n│   │   └── Makefile\n│   └── make\n│       ├── .make-release-support\n│       ├── Makefile\n```\n\nThe Makefile in the image directories will include the generic Makefile. In this Makefile you can alter the names and tailor the build by adding pre and post build targets.  Checkout the directory (multiple-example) for an example.\n\n\n## Dependencies between images in a single git repository\n\nYou can specify release dependencies between components in the repository using the variable `tag_on_changes_in` in the .release file.\n\nLet's say we have repository:\n\n\n\n```\n├── release-dependencies\n│   ├── ...\n│   ├── common\n│   │   ├── .release\n│   │   ├── Dockerfile\n│   │   └── Makefile\n│   ├── backend\n│   │   ├── .release\n│   │   ├── Dockerfile\n│   │   └── Makefile\n│   ├── frontend\n│   │   ├── .release\n│   │   ├── Dockerfile\n│   │   └── Makefile\n│   └── make\n│       ├── .make-release-support\n│       ├── Makefile\n```\n\nand the following dependencies between the releases:\n\n```\n  +--------------------------------+\n  |                                v\n+----------+     +---------+     +--------+\n| frontend | --\u003e | backend | --\u003e | common |\n+----------+     +---------+     +--------+\n```\n\nThe respective .release files will have the following configuration:\n\n```\nfrontend/.release\n=================\ntag_on_changes_in=. ../backend ../common\n\nbackend/.release\n=================\ntag_on_changes_in=. ../common\n\n```\ncheck-status, check-release and showver will detect that a new version is required if there are changes in either backend or common with respect to the last release tag. Checkout the directory [release-dependencies](./release-dependencies) for an example.\n\nNote that there are a number of caveats:\n\n- the script does not recurse, so you must specify all directories it depends on\n- the script does not order the release tagging, so you must release the components in order\n- the script does not detect cycles in the dependencies\n- the paths must be relative and point to directories in the same git repository\n\n\n### Create the generic make directory\n\nTo create the generic make directory, type:\n\n```bash\nmkdir make\ncd make\nwget  https://raw.githubusercontent.com/mvanholsteijn/docker-makefile/master/Makefile  \nwget  https://raw.githubusercontent.com/mvanholsteijn/docker-makefile/master/.make-release-support\n```\n\n### Create docker image directory\nFor each docker images, you create a sibling directory:\n\n```bash\nmkdir ../image1\ncd ../image1\n\ncat \u003e Makefile \u003c\u003c!\ninclude ../make/Makefile\n\nUSERNAME=mvanholsteijn\n\npre-build:\n\t@echo do some stuff before the docker build\n\npost-build:\n\t@echo do some stuff after the docker build\n!\n\n```\n\nNow you can use the make build and release instructions to build these images.\n\n### Changing the build context and Dockerfile path and name\n\nUse the `DOCKER_BUILD_CONTEXT`variable to set the path to the context. Set `DOCKER_FILE_PATH` to change the path to the Dockerfile (file name included) you want to use. Using this in conjuction with the `pre-build` and `post-build` targets and a `.dockerignore` file allows you to modify the build context.\n\n```\nDOCKER_BUILD_CONTEXT=../..\nDOCKER_FILE_PATH=$(DOCKER_BUILD_CONTEXT)/docker/$(NAME)/some.Dockerfile\n\npre-build: check-env-vars .dockerignore\n\tcp .dockerignore $(DOCKER_BUILD_CONTEXT)\n\npost-build:\n\trm $(DOCKER_BUILD_CONTEXT)/.dockerignore\n```\n\n### pre tag command\nIf you want add the current release to a source file, you can add the property `pre\\_tag\\_command` to the .release file. \nthis command is executed when the .release file is updated and before the tag is placed. In the command @@RELEASE@@ is\nreplaced with the current release before it is executed. For example:\n\n```\nrelease=0.1.0\ntag=v0.1.0\npre_tag_command=sed -i \"\" -e 's/^version=.*/version=\"@@RELEASE@@\"/' setup.py\n```\n\n### Adding --build-arg\nIf you want to add any command line options to the docker build command, specify the Make \nvariable `DOCKER_BUILD_ARGS`. \n\nThe following Makefile, specifies the build argument `TAG_VERSION` to be set to the current value.\n\n```\ninclude ../Makefile\nDOCKER_BUILD_ARGS=--build-arg TAG_VERSION=$(VERSION)\n```\n\ncheckout the example [Make-](./build-arg-example/Makefile) and [Dockerfile](./build-arg-example/Dockerfile).\n\n### control the :latest tag\nYou can now control the generation of the latest tag with the variable TAG_WITH_LATEST.\n\n| value | action | removes :latest tag? |\n|-------|--------|----------------------|\n| always | tag all images with `:latest` | no |\n| on-release | only tag clean images tag (eg. x.y.z) with `:latest` | yes, for no-release builds |\n| never | never tag with `:latest` | yes |\n\nCaveats:\n- when you build a image from an earlier release, it will also be tagged `latest` with `on-release` and `always`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvanholsteijn%2Fdocker-makefile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvanholsteijn%2Fdocker-makefile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvanholsteijn%2Fdocker-makefile/lists"}