Skip to content

Commit

Permalink
Intermittent commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stefaniuk committed Nov 24, 2023
1 parent 40fe447 commit d28e43f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${yyyy}${mm}${dd}
0.9.0-${snapshot}
12 changes: 10 additions & 2 deletions docs/adr/ADR-004_Agree_CICD_pipeline_structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
---

Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions scripts/config/repository-template.yaml
Original file line number Diff line number Diff line change
@@ -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:
44 changes: 22 additions & 22 deletions scripts/docker/docker.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

# ==============================================================================
Expand Down Expand Up @@ -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
Expand All @@ -234,22 +220,36 @@ 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" | \
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" \
> "$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.
Expand Down

0 comments on commit d28e43f

Please sign in to comment.