Package: determine-docker-tags
determine-docker-tagsA python program used to determine which docker tags should be applied to a docker image depending on various factors. This is mainly intended to be used together with Drone CI to automatically figure out version tags before building a container image.InstallationAs this is mainly intended to be used with Drone CI there is a ready to go docker image onDocker Hub. You can also find the source for the docker imagehere.If you're not interested in a docker image you can also find it onPyPiand it can easily be installed with:pip install determine-docker-tagsOptionsHere is a list of the options available. You can find more detailed usage instructions below.ENV VarDefaultDescriptionVERSION_TYPE""How the program should find the version number. Can be "docker_env", "docker_from", "date" or "".APP_NAME""The name of the application whose version number you want to use to generate tags.DOCKERFILE_PATH"Dockerfile"The path to the Dockerfile you want to run the program onAPP_ENV""A static string to add to the end of every tag with a "-" added inbetween the tag and the string. The string will not be added to any tags defined in CUSTOM_TAGS.CUSTOM_TAGS""Any extra static tags you want to add to the image, for example "latest". You can provide a list in the form of a comma separated string to specify multiple tags. For example "latest,prod,example"INCLUDE_MAJOR"yes"If the major version number should be a tag. This setting will be ignored if the major version number is 0. Can be "yes" or "no".INCLUDE_SUFFIX"yes"If the suffix that you find after the version number in many docker image tags should be kept and added to every tag. Can be "yes" or "no"UsageThe program is configured through environment variables. You can see the different options below. The program automatically figures out the version numbers to use as tags from a Dockerfile. The tags are put into a .tags file in the current workspace to be picked up by the drone docker plugin. This program is mainly intended to handle SemVer and may or may not work well with other versioning styles.Version typeTo use the program you first need to figure out whichVERSION_TYPEyou want to use. There are four options to choose from. The default or an empty string requiresCUSTOM_TAGSto be set and just creates a .tags file with the contents ofCUSTOM_TAGS.dateIfVERSION_TYPEis set todatea tag will be created corresponding to the current date in formatYEARMONTHDAYfor example20210101. IfAPP_ENVis set it will currently be ignored using thisVERSION_TYPE.docker_envIfVERSION_TYPEis set todocker_envthenAPP_NAMEis also required. Whendocker_envis used the program looks for theAPP_NAMEversion number set as an ENV var in the Dockerfile. The required formating to use in the Dockerfile is:ENV APP_NAME_VERSION VERSION_NUMBERSo lets say the "APP_NAME" we are looking for is Nginx, then we would set "APP_NAME" to "NGINX" and the ENV var in the Dockerfile would look like this:ENV NGINX_VERSION 1.18.0This would generate the following tags:1,1.18,1.18.0docker_fromIfVERSION_TYPEis set todocker_fromthenAPP_NAMEis also required. When using thisVERSION_TYPEthe version number is taken from aFROMinstruction in the provided Dockerfile. Let's say we had the followingFROMinstruction in our Dockerfile:FROM nginx:1.18.0We then setAPP_NAMEtonginxand the generated tags would be:1,1.18,1.18.0APP ENVAPP_ENVis a static string that will be added to the end of dynamically created tag, so not the ones defined inCUSTOM_TAGS. A-is added between the generated tag and the contents ofAPP_ENV. Let's say we had the version number1.18.0andAPP_ENVwas set toprodthen we would get the following tags:1-prod,1.18-prod,1.18.0-prodINCLUDE_MAJORINCLUDE_MAJORdetermine whether or not the major version number should have a tag of its own. The default for this option isyesIf the major version number is0this option will be ignored and a tag with only the major version number won't be created. Let's say we had the version number1.18.0andINCLUDE_MAJORis set tonothen we would get the following tags:1.18,1.18.0INCLUDE_SUFFIXINCLUDE_SUFFIXis mainly intended to be used with thedocker_fromversion type. It determines whether or not the suffix should be included in the generated tags. The default for this option isyes. Let's say we had the followingFROMinstruction in our Dockerfile:FROM nginx:1.18.0-alpineWith the default ofyesthat would generated the following tags:1-alpine,1.18-alpine,1.18.0-alpineAnd if set tonothe following tags would be generated:1,1.18,1.18.0LicenseThis program is licensed under the GPLv3 or later.