Skip to content

Commit 5f28100

Browse files
authored
Improve make config behaviour (nhs-england-tools#133)
## Description - This change fixes the unexpected behaviour of the `make config` command which fails when the `asdf` tool isn't correctly set up - `asdf` is no longer installed as part of the repository template, however it is listed as a required dependency - A fix to the `check-file-format` git pre-commit hook is also included as part of this PR ## Context - Fixes nhs-england-tools#124 - Fixes nhs-england-tools#126 - Fixes nhs-england-tools#102 ## Type of changes - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would change existing functionality) - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I am familiar with the [contributing guidelines](../docs/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 3928625 commit 5f28100

File tree

12 files changed

+53
-73
lines changed

12 files changed

+53
-73
lines changed

.tool-versions

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
nodejs 18.17.1 # Always check AWS and Azure runtime support
2-
python 3.11.4 # Always check AWS and Azure runtime support
3-
poetry 1.6.1
4-
yarn 1.22.19
5-
terraform 1.5.6
6-
pre-commit 3.3.3
1+
# This file is for you! Please, updated to the versions agreed by your team.
2+
3+
terraform 1.5.7
4+
pre-commit 3.4.0
75

86
# ==============================================================================
97
# The section below is reserved for Docker image versions.
108

11-
# alpine, SEE: https://hub.docker.com/_/alpine/tags
12-
# docker/alpine 3.18.3@sha256:c5c5fda71656f28e49ac9c5416b3643eaa6a108a8093151d6d1afc9463be8e33
13-
14-
# nodejs, SEE: https://hub.docker.com/_/node/tags
15-
# docker/node 18.17.1-alpine3.18@sha256:982b5b6f07cd9241c9ebb163829067deac8eaefc57cfa8f31927f4b18943d971
16-
17-
# python, SEE: https://hub.docker.com/_/python/tags
18-
# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86
19-
209
# terraform, SEE: https://hub.docker.com/r/hashicorp/terraform/tags
2110
# docker/hashicorp/terraform 1.5.6@sha256:180a7efa983386a27b43657ed610e9deed9e6c3848d54f9ea9b6cb8a5c8c25f5
2211

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ clean:: # Clean-up project resources (main) @Operations
2525
config:: # Configure development environment (main) @Configuration
2626
# TODO: Use only 'make' targets that are specific to this project, e.g. you may not need to install Node.js
2727
make \
28-
nodejs-install \
29-
python-install \
3028
terraform-install
3129

3230
# ==============================================================================

README.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ Start with an overview or a brief description of what the project is about and w
77

88
Welcome to our repository template designed to streamline your project setup! This robust template provides a reliable starting point for your new projects, covering an essential tech stack and encouraging best practices in documenting.
99

10-
This repository template aims to foster a user-friendly development environment by ensuring that every included file is concise and adequately self-documented. By adhering to this standard, we can promote increased clarity and maintainability throughout your project's lifecycle. Bundled within this template are resources that pave the way for seamless repository creation. Our supported tech stack includes:
10+
This repository template aims to foster a user-friendly development environment by ensuring that every included file is concise and adequately self-documented. By adhering to this standard, we can promote increased clarity and maintainability throughout your project's lifecycle. Bundled within this template are resources that pave the way for seamless repository creation. Currently supported technologies are:
1111

1212
- Terraform
13-
- Python
14-
- Node.js
13+
- Docker
1514

1615
Make use of this repository template to expedite your project setup and enhance your productivity right from the get-go. Enjoy the advantage of having a well-structured, self-documented project that reduces overhead and increases focus on what truly matters - coding!
1716

@@ -21,12 +20,12 @@ Make use of this repository template to expedite your project setup and enhance
2120
- [Table of Contents](#table-of-contents)
2221
- [Setup](#setup)
2322
- [Prerequisites](#prerequisites)
24-
- [Installation](#installation)
23+
- [Configuration](#configuration)
2524
- [Usage](#usage)
2625
- [Testing](#testing)
27-
- [Architecture](#architecture)
26+
- [Design](#design)
2827
- [Diagrams](#diagrams)
29-
- [Configuration](#configuration)
28+
- [Modularity](#modularity)
3029
- [Contributing](#contributing)
3130
- [Contacts](#contacts)
3231
- [Licence](#licence)
@@ -44,35 +43,30 @@ cd nhs-england-tools/repository-template
4443

4544
### Prerequisites
4645

47-
The following software packages or their equivalents are expected to be installed
48-
49-
- [GNU make](https://www.gnu.org/software/make/) **v3.82 or later: OS X users, take note below**
50-
- [Docker](https://www.docker.com/)
46+
The following software packages, or their equivalents, are expected to be installed:
5147

52-
Note that the version of GNU Make available by default on OS X is earlier than this. You will need to upgrade it, or certain `make` tasks will fail. On OS X, you will need [homebrew](https://brew.sh/) installed, then to install `make`, like so:
53-
54-
```shell
55-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
56-
brew install make
57-
```
48+
- [docker](https://www.docker.com/) container runtime or a compatible tool, e.g. [podman](https://podman.io/),
49+
- [asdf](https://asdf-vm.com/) version manager,
50+
- [GNU make](https://www.gnu.org/software/make/) 3.82 or later,
51+
- [GNU coreutils](https://www.gnu.org/software/coreutils/) and [GNU binutils](https://www.gnu.org/software/binutils/) may be required to build dependencies like Python, which may need to be compiled during installation. For macOS users, this has been scripted and automated by the `dotfiles` project; please see this [script](https://github.com/nhs-england-tools/dotfiles/blob/main/assets/20-install-base-packages.macos.sh) for details.
5852

59-
You will then see instructions to fix your `$PATH` variable to make the newly installed version available.
60-
If you are using [dotfiles](https://github.com/nhs-england-tools/dotfiles), this is all done for you.
53+
> [!NOTE]<br>
54+
> The version of GNU make available by default on macOS is earlier than 3.82. You will need to upgrade it or certain `make` tasks will fail. On macOS, you will need [homebrew](https://brew.sh/) installed, then to install `make`, like so:
55+
>
56+
> ```shell
57+
> brew install make
58+
> ```
59+
>
60+
> You will then see instructions to fix your `$PATH` variable to make the newly installed version available. If you are using [dotfiles](https://github.com/nhs-england-tools/dotfiles), this is all done for you.
6161
62-
### Installation
62+
### Configuration
6363
64-
Install and configure toolchain dependencies
64+
Installation and configuration of the toolchain dependencies
6565
6666
```shell
6767
make config
6868
```
6969
70-
If this repository is
71-
72-
```shell
73-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/org/repo/branch/install.sh)"
74-
```
75-
7670
## Usage
7771

7872
After a successful installation, provide an informative example of how this project can be used. Additional code snippets, screenshots and demos work well in this space. You may also link to the other documentation resources, e.g. the [User Guide](./docs/user-guide.md) to demonstrate more use cases and to show more features.
@@ -81,15 +75,15 @@ After a successful installation, provide an informative example of how this proj
8175

8276
There are `make` tasks for you to configure to run your tests. Run `make test` to see how they work. You should be able to use the same entry points for local development as in your CI pipeline.
8377

84-
## Architecture
78+
## Design
8579

8680
### Diagrams
8781

8882
The [C4 model](https://c4model.com/) is a simple and intuitive way to create software architecture diagrams that are clear, consistent, scalable and most importantly collaborative. This should result in documenting all the system interfaces, external dependencies and integration points.
8983

9084
![Repository Template](./docs/diagrams/Repository_Template_GitHub_Generic.png)
9185

92-
### Configuration
86+
### Modularity
9387

9488
Most of the projects are built with customisability and extendability in mind. At a minimum, this can be achieved by implementing service level configuration options and settings. The intention of this section is to show how this can be used. If the system processes data, you could mention here for example how the input is prepared for testing - anonymised, synthetic or live data.
9589

scripts/config/pre-commit.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ repos:
1010
hooks:
1111
- id: check-file-format
1212
name: Check File Format
13-
entry: check=staged-changes./scripts/githooks/check-file-format.sh
13+
entry: ./scripts/githooks/check-file-format.sh
14+
args: ["check=staged-changes"]
1415
language: script
1516
pass_filenames: false
1617
- repo: local

scripts/docker/docker.lib.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ set -euo pipefail
1111
# $ source ./docker.lib.sh
1212
#
1313
# Arguments (provided as environment variables):
14-
# DOCKER_IMAGE=ghcr.io/org/repo # Docker image name
15-
# DOCKER_TITLE="My Docker image" # Docker image title
14+
# DOCKER_IMAGE=ghcr.io/org/repo # Docker image name
15+
# DOCKER_TITLE="My Docker image" # Docker image title
16+
# TOOL_VERSIONS=$project_dir/.tool-versions # Path to the tool versions file
1617

1718
# ==============================================================================
1819
# Functions to be used with custom images.
@@ -164,7 +165,7 @@ function docker-get-image-version-and-pull() {
164165

165166
# Get the image full version from the '.tool-versions' file,
166167
# match it by name and version regex, if given.
167-
local versions_file="$(git rev-parse --show-toplevel)/.tool-versions"
168+
local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}"
168169
local version="latest"
169170
if [ -f "$versions_file" ]; then
170171
line=$(grep "docker/${name} " "$versions_file" | sed "s/^#\s*//; s/\s*#.*$//" | grep "${match_version:-'.*'}")
@@ -217,13 +218,13 @@ function _create-effective-dockerfile() {
217218
function _replace-image-latest-by-specific-version() {
218219

219220
local dir=${dir:-$PWD}
220-
local versions_file=$(git rev-parse --show-toplevel)/.tool-versions
221+
local versions_file="${TOOL_VERSIONS:=$(git rev-parse --show-toplevel)/.tool-versions}"
221222
local dockerfile="${dir}/Dockerfile.effective"
222223
local build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')}
223224

224225
if [ -f "$versions_file" ]; then
225226
# First, list the entries specific for Docker to take precedence, then the rest but exclude comments
226-
content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" | grep -v "^#")
227+
content=$(grep " docker/" "$versions_file"; grep -v " docker/" "$versions_file" ||: | grep -v "^#")
227228
echo "$content" | while IFS= read -r line; do
228229
[ -z "$line" ] && continue
229230
line=$(echo "$line" | sed "s/^#\s*//; s/\s*#.*$//" | sed "s;docker/;;")

scripts/docker/docker.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ docker-example-build: # Build Docker example @ExamplesAndTests
4545
cd scripts/docker/examples/python
4646
DOCKER_IMAGE=repository-template/docker-example-python
4747
DOCKER_TITLE="Repository Template Docker Python Example"
48+
TOOL_VERSIONS="$(shell git rev-parse --show-toplevel)/scripts/docker/examples/python/.tool-versions.example"
4849
docker-build
4950

5051
docker-example-lint: # Lint Docker example @ExamplesAndTests
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# python, SEE: https://hub.docker.com/_/python/tags
2+
# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
flask==2.3.2
2-
Flask-WTF==1.1.1
1+
blinker==1.6.2
2+
click==8.1.7
3+
Flask-WTF==1.2.0
4+
Flask==2.3.3
5+
itsdangerous==2.1.2
6+
Jinja2==3.1.2
7+
MarkupSafe==2.1.3
8+
pip==23.1.2
9+
setuptools==65.5.1
10+
Werkzeug==3.0.0
11+
wheel==0.41.1
12+
WTForms==3.0.1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# python, SEE: https://hub.docker.com/_/python/tags
2+
# docker/python 3.11.4-alpine3.18@sha256:0135ae6442d1269379860b361760ad2cf6ab7c403d21935a8015b48d5bf78a86

scripts/docker/tests/docker.test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function test-docker-build() {
7474
function test-docker-image-from-signature() {
7575

7676
# Arrange
77+
TOOL_VERSIONS="$(git rev-parse --show-toplevel)/scripts/docker/tests/.tool-versions.test"
7778
cp Dockerfile Dockerfile.effective
7879
# Act
7980
_replace-image-latest-by-specific-version

0 commit comments

Comments
 (0)