diff --git a/VERSION b/VERSION index f25af7f1..b6db450d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -${yyyy}${mm}${dd} +0.9.0-${snapshot} diff --git a/docs/adr/ADR-004_Agree_CICD_pipeline_structure.md b/docs/adr/ADR-004_Agree_CICD_pipeline_structure.md index 5fdf6e81..6e6caadf 100644 --- a/docs/adr/ADR-004_Agree_CICD_pipeline_structure.md +++ b/docs/adr/ADR-004_Agree_CICD_pipeline_structure.md @@ -2,11 +2,11 @@ >| | | >| ------------ | --- | ->| Date | `12/09/2022` | +>| Date | `15/09/2022` | >| Status | `RFC` | >| Deciders | `Engineering` | >| Significance | `Construction techniques` | ->| Owners | `?` | +>| Owners | `Dan Stefaniuk, Nick Sparks` | --- @@ -24,6 +24,14 @@ ## Context +Continuous integration and continuous delivery pipeline is to organise all steps required to go from idea to a releasable software using automation of the development process. The key ideas upon it is founded are as follows: + +- The reliable, repeatable production of high quality software. +- The application of scientific principles, experimentation, feedback and learning. +- The pipeline (or set of workflows) as a mechanism to organise and automate the development process. + +For this to work it is essential to apply principles and practices noted in the [NHSE Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework) + Requirements: - Implement the exemplar CI/CD pipeline using GitHub workflows and actions diff --git a/scripts/config/repository-template.yaml b/scripts/config/repository-template.yaml index eb37ceec..984fa0e2 100644 --- a/scripts/config/repository-template.yaml +++ b/scripts/config/repository-template.yaml @@ -1 +1,19 @@ update-from-template: + modules: [ "terraform", "docker", "tests", "githooks", "reports", "config" ] + ignore: + +cicd-config: + stage: + build: + only-when-pr-present: true + acceptance: + only-when-pr-present: true + +version: + build-datetime: 2023-02-21T10:46:17+0000 + template: + url: https://github.com/nhs-england-tools/repository-template + branch: main + commit-hash: 94834f9ecd87d96b6f43a6f0307f2e7ee905b1b4 + tags: [] + release-notes-url: diff --git a/scripts/docker/docker.lib.sh b/scripts/docker/docker.lib.sh index 18787105..f8cc3473 100644 --- a/scripts/docker/docker.lib.sh +++ b/scripts/docker/docker.lib.sh @@ -124,21 +124,8 @@ function docker-clean() { function version-create-effective-file() { local dir=${dir:-$PWD} - local version_file="$dir/VERSION" - local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} - if [ -f "$version_file" ]; then - # shellcheck disable=SC2002 - cat "$version_file" | \ - sed "s/\(\${yyyy}\|\$yyyy\)/$(date --date="${build_datetime}" -u +"%Y")/g" | \ - sed "s/\(\${mm}\|\$mm\)/$(date --date="${build_datetime}" -u +"%m")/g" | \ - sed "s/\(\${dd}\|\$dd\)/$(date --date="${build_datetime}" -u +"%d")/g" | \ - sed "s/\(\${HH}\|\$HH\)/$(date --date="${build_datetime}" -u +"%H")/g" | \ - sed "s/\(\${MM}\|\$MM\)/$(date --date="${build_datetime}" -u +"%M")/g" | \ - sed "s/\(\${SS}\|\$SS\)/$(date --date="${build_datetime}" -u +"%S")/g" | \ - sed "s/\(\${hash}\|\$hash\)/$(git rev-parse --short HEAD)/g" \ - > "$dir/.version" - fi + file="$dir/VERSION" output_file="$dir/.version" _replace-version-placeholders } # ============================================================================== @@ -220,7 +207,6 @@ function _replace-image-latest-by-specific-version() { local dir=${dir:-$PWD} local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}" local dockerfile="${dir}/Dockerfile.effective" - local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} if [ -f "$versions_file" ]; then # First, list the entries specific for Docker to take precedence, then the rest but exclude comments @@ -234,9 +220,26 @@ function _replace-image-latest-by-specific-version() { done fi - if [ -f "$dockerfile" ]; then + file="$dockerfile" _replace-version-placeholders + # Do not ignore the issue if 'latest' is used in the effective image and ensure the ignore rule is removed, if present] + sed -Ei "/#.*hadolint.*ignore=DL3007$/d" "$dockerfile" +} + +# Replace version placeholders. +# Arguments (provided as environment variables): +# file=[path to the file to use as the input] +# output_file=[path to the file to use as the output, default is the same as the input file] +# BUILD_DATETIME=[build date and time in the '%Y-%m-%dT%H:%M:%S%z' format generated by the CI/CD pipeline, default is current date and time] +function _replace-version-placeholders() { + + local file="$file" + local output_file="${output_file:-$file}" + local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} + + if [ -f "$file" ]; then # shellcheck disable=SC2002 - cat "$dockerfile" | \ + cat "$file" | \ + sed "s/\(\${snapshot}\|\$snapshot\)/$(date --date="${build_datetime}" -u +"%Y%m%d.%H%M%S")/g" | \ sed "s/\(\${yyyy}\|\$yyyy\)/$(date --date="${build_datetime}" -u +"%Y")/g" | \ sed "s/\(\${mm}\|\$mm\)/$(date --date="${build_datetime}" -u +"%m")/g" | \ sed "s/\(\${dd}\|\$dd\)/$(date --date="${build_datetime}" -u +"%d")/g" | \ @@ -244,12 +247,9 @@ function _replace-image-latest-by-specific-version() { sed "s/\(\${MM}\|\$MM\)/$(date --date="${build_datetime}" -u +"%M")/g" | \ sed "s/\(\${SS}\|\$SS\)/$(date --date="${build_datetime}" -u +"%S")/g" | \ sed "s/\(\${hash}\|\$hash\)/$(git rev-parse --short HEAD)/g" \ - > "$dockerfile.tmp" - mv "$dockerfile.tmp" "$dockerfile" + > "$file.tmp" + mv "$file.tmp" "$output_file" fi - - # Do not ignore the issue if 'latest' is used in the effective image - sed -Ei "/# hadolint ignore=DL3007$/d" "${dir}/Dockerfile.effective" } # Append metadata to the end of Dockerfile.