diff --git a/pyproject.toml b/.bumpversion.toml similarity index 79% rename from pyproject.toml rename to .bumpversion.toml index 88e817b3a15ef49b01fb4280698296379fb0ff8f..f20b76e108d0200068fb84dcad728dc41fd1f520 100644 --- a/pyproject.toml +++ b/.bumpversion.toml @@ -1,7 +1,6 @@ [tool.bumpversion] commit = true -config-file = "pyproject.toml" -current_version = "0.2.1" +current_version = "0.3.0" parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)" replace = "{new_version}" search = "{current_version}" @@ -22,5 +21,3 @@ search = """## [Unreleased] [[tool.bumpversion.files]] allow-dirty = true filename = "README.md" -replace = "{new_version}" -search = "{current_version}" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5e4e2d701721f06afcdcab9dda424c6a9070ba0e..cf90aff3e20d5095c08faa4cbaaadf3aa4e2e611 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,2 @@ include: - - project: 'swepy/cicd-templates/release-by-changelog' - ref: '0.4.3' - file: 'templates/release-by-changelog.yml' + - component: $CI_SERVER_FQDN/swepy/cicd-templates/release-by-changelog/release-by-changelog@1.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2a52e443de147c25f7d9e3bb95930f8ee121f164 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +--- +default_stages: [pre-commit] + +repos: + # https://pre-commit.com/hooks.html + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-case-conflict # blocking + - id: check-merge-conflict # blocking + - id: detect-private-key # blocking + - id: fix-byte-order-marker # auto-fix + - id: trailing-whitespace # auto-fix + + # force respect of Conventional Commits formatting: https://www.conventionalcommits.org/en/v1.0.0/ + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v3.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + args: [feat, fix, ci, doc, chore, test] # optional: list of Conventional Commits types to allow e.g. [feat, fix, ci, chore, test] diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dbde2571b4672cc0efd0103ce8030be03433a9f..cee48ad0cb5b301ea7fb550a4caea1e37d541480 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.3.0] - 2025-03-01 + +### Added + +* Support [inputs](https://docs.gitlab.com/ci/yaml/inputs/): + * stage: Stage of the job + * image_id: Image name and tag of the built image + * context_path: Path to the build context, usually the project + * dockerfile_name: Name of the dockerfile + * docker_host: Docker daemon host URL + * docker_driver: Storage driver used by Docker + * kaniko_options: Additional options to pass to Kaniko for image building + * kaniko_tag: Version tag of the Kaniko executor image +* Variables: + * DOCKERFILE_NAME + * KANIKO_TAG + +### Changed + +* Variables: + * TARGET_IMAGE -> IMAGE_ID + * PROJECT_PATH -> CONTEXT_PATH + ## [0.2.1] - 2024-07-16 * Update CICD diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8ca5cd4615dd0447c2e032408fe0c259b650fd19..5b7660bc9879e9e2157914b8c33580d345e19467 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,8 +11,7 @@ with. To set up your environment and install all necessary dependencies: ```sh -pip install --upgrade pip -pip install bump-my-version +pip install --upgrade pip bump-my-version pre-commit ``` ### Bump version @@ -30,3 +29,17 @@ bump-my-version bump minor ```sh bump-my-version bump patch ``` + +## Pre-commit + +### install + +```shell +pre-commit install +``` + +### test on all files + +```shell +pre-commit run --all-files +``` diff --git a/LICENSE b/LICENSE index 42a9f4e44f9d257e9ead0f7ec13e06d36a018af1..03bf7aebb367384887891a93b22b53b5db6e8402 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Dorian Turba +Copyright (c) 2024-2025 Dorian Turba Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a1dc91582584500ad149a5180ddd022c7f033e4c..055c465f2a69a8e77421b607d547b1f45bf95ca3 100644 --- a/README.md +++ b/README.md @@ -8,51 +8,53 @@ Build a Docker image and push it to the GitLab registry. ## How to use it -### Include the component/template +### Include the component Add the following to your `.gitlab-ci.yml` file. -As a remote Template (recommended): - ```yaml include: - - remote: 'https://gitlab.com/swepy/cicd-templates/docker-build/-/raw/0.2.1/templates/docker-build.yml' + - component: $CI_SERVER_FQDN/swepy/cicd-templates/docker-build/docker-build@0.3.0 ``` -As a local Template (if the template is local to the instance): - -```yaml -include: - - project: 'swepy/cicd-templates/docker-build' - ref: '0.2.1' - file: 'templates/docker-build.yml' -``` +[](https://gitlab.com) +[](https://froggit.fr/) -As a Component ([beta](https://gitlab.com/gitlab-org/gitlab/-/issues/407556) and if the -component is local to the instance): +### Inputs -```yaml -include: - - component: $CI_SERVER_FQDN/swepy/cicd-templates/docker-build/docker-build@0.2.1 -``` +You can customize the job by overriding specific inputs. -### Customize job +| Name | Description | Default | +|-------------------|----------------------------------------------------------|-------------------------------------| +| `stage` | Stage of the job. | `test` | +| `image_id` | Image name and tag of the built image. | `$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA` | +| `context_path` | Path to the build context, usually the project. | `.` | +| `dockerfile_name` | Name of the dockerfile. | `Dockerfile` | +| `docker_host` | Docker daemon host URL. | `tcp://docker:2375/` | +| `docker_driver` | Storage driver used by Docker. | `overlay2` | +| `kaniko_options` | Additional options to pass to Kaniko for image building. | `""` | +| `kaniko_tag` | Version tag of the Kaniko executor image. | `v1.23.2-debug` | -You can customize the job by overriding specific keys. For example: +For example: -```yaml -docker-build: - stage: build_img +```yml +include: + - component: $CI_SERVER_FQDN/swepy/cicd-templates/docker-build/docker-build@0.3.0 + inputs: + stage: docker_build + context_path: ./project ``` ## Variables You can customize the job by overriding the following variables: -| Name | Description | Default | -|------------------|---------------------------------------|-------------------------------------| -| `DOCKER_HOST` | The path to the Docker Host | `tcp://docker:2375/` | -| `DOCKER_DRIVER` | The name of the Docker driver. | `overlay2` | -| `TARGET_IMAGE` | The nmae and tag of the target image. | `$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA` | -| `PROJECT_PATH` | The tag to apply to the image. | `.` | -| `KANIKO_OPTIONS` | The Kaniko options. | `""` | +| Name | Description | Default | +|-------------------|----------------------------------------------------------|---------------------------------| +| `IMAGE_ID` | Image name and tag of the built image. | `$[[ inputs.image_id ]]` | +| `CONTEXT_PATH` | Path to the build context, usually the project. | `$[[ inputs.context_path ]]` | +| `DOCKERFILE_NAME` | Name of the dockerfile. | `$[[ inputs.dockerfile_name ]]` | +| `DOCKER_HOST` | Docker daemon host URL. | `$[[ inputs.docker_host ]]` | +| `DOCKER_DRIVER` | Storage driver used by Docker. | `$[[ inputs.docker_driver ]]` | +| `KANIKO_OPTIONS` | Additional options to pass to Kaniko for image building. | `$[[ inputs.kaniko_options ]]` | +| `KANIKO_TAG` | Version tag of the Kaniko executor image. | `$[[ inputs.kaniko_tag ]]` | diff --git a/templates/docker-build.yml b/templates/docker-build.yml index 08ab97eefc6c7a3055a8a410d75a3a8625164097..d8c5f7712550bd8a2f104f659da3ef0508569707 100644 --- a/templates/docker-build.yml +++ b/templates/docker-build.yml @@ -1,21 +1,51 @@ +spec: + inputs: + stage: + description: Stage of the job. + default: build + image_id: + description: Image name and tag of the built image. + default: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA + context_path: + description: Path to the build context, usually the project. + default: . + dockerfile_name: + description: Name of the dockerfile. + default: Dockerfile + docker_host: + description: Docker daemon host URL. + default: tcp://docker:2375/ + docker_driver: + description: Storage driver used by Docker. + default: overlay2 + kaniko_options: + description: Additional options to pass to Kaniko for image building. + default: "" + kaniko_tag: + description: Version tag of the Kaniko executor image. + default: v1.23.2-debug + +--- docker_build: stage: build variables: - DOCKER_HOST: tcp://docker:2375/ - DOCKER_DRIVER: overlay2 - TARGET_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA - PROJECT_PATH: . - KANIKO_OPTIONS: "" + IMAGE_ID: $[[ inputs.image_id ]] + CONTEXT_PATH: $[[ inputs.context_path ]] + DOCKERFILE_NAME: $[[ inputs.dockerfile_name ]] + DOCKER_HOST: $[[ inputs.docker_host ]] + DOCKER_DRIVER: $[[ inputs.docker_driver ]] + KANIKO_OPTIONS: $[[ inputs.kaniko_options ]] + KANIKO_TAG: $[[ inputs.kaniko_tag ]] image: - name: gcr.io/kaniko-project/executor:v1.14.0-debug + name: gcr.io/kaniko-project/executor:${KANIKO_TAG} entrypoint: [ "" ] tags: - docker script: - # Kaniko use $CI_REGISTRY_USER and $CI_REGISTRY_PASSWORD to connect to the + # Kaniko uses $CI_REGISTRY_USER and $CI_REGISTRY_PASSWORD to connect to the # registry - /kaniko/executor - --context "${PROJECT_PATH}" - --dockerfile "${PROJECT_PATH}/Dockerfile" - --destination "${TARGET_IMAGE}" + --context "${CONTEXT_PATH}" + --dockerfile "${CONTEXT_PATH}/${DOCKERFILE_NAME}" + --destination "${IMAGE_ID}" ${KANIKO_OPTIONS}