Skip to content

Commit 7e913de

Browse files
authored
Merge pull request #6612 from NHSDigital/enable-postgis
Enable PostGIS
2 parents a2157f3 + b4eef4b commit 7e913de

13 files changed

Lines changed: 121 additions & 74 deletions
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
name: Create Dockerized Database
2-
run-name: Creating dockerized image from ${{ github.ref_name }}
1+
name: Build and push database image
2+
run-name: Build and push database image for ${{ github.ref_name }}
33

44
on:
55
workflow_dispatch:
66
push:
7-
branches:
8-
- next
7+
branches: [next]
98
workflow_call:
109
inputs:
1110
github_ref:
@@ -17,8 +16,8 @@ permissions:
1716
contents: read
1817

1918
jobs:
20-
setup-development-database:
21-
name: Setup Development Database
19+
build-and-push-database-image:
20+
name: Build and push database image
2221
runs-on: ubuntu-latest
2322
env:
2423
RAILS_ENV: development
@@ -32,34 +31,36 @@ jobs:
3231
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3332
with:
3433
ref: ${{ inputs.github_ref || github.ref_name == 'next' && 'next' || github.ref_name }}
35-
repository: nhsuk/manage-vaccinations-in-schools
34+
repository: nhsdigital/manage-vaccinations-in-schools
3635
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
3736
with:
3837
node-version-file: .tool-versions
3938
cache: yarn
40-
- name: Build custom postgres image
41-
run: |
42-
echo -e "FROM postgres:16.11\n\nENV PGDATA=\"/var/lib/postgresql/mydata\"" > db.Dockerfile
43-
docker build -t custom-postgres:latest -f db.Dockerfile .
44-
- name: Start db container
39+
- name: Create Dockerfile
40+
run: >-
41+
echo -e \
42+
"FROM postgis/postgis:17-master\nENV PGDATA=\"/var/lib/postgresql/mydata\"" \
43+
> database.Dockerfile
44+
- name: Build image
45+
run: docker build -t database:latest -f database.Dockerfile .
46+
- name: Start container
4547
run: |
4648
docker run -d \
4749
--name database \
4850
-e "POSTGRES_HOST_AUTH_METHOD=trust" \
4951
-p 5432:5432 \
50-
custom-postgres:latest
51-
- name: Wait for db to be ready
52+
database:latest
53+
- name: Wait for database to be ready
5254
run: |
5355
docker exec database bash -c '
5456
until pg_isready -U postgres; do
5557
echo "Waiting for postgres..."
5658
sleep 2
57-
done
58-
'
59+
done'
5960
- uses: ruby/setup-ruby@60ecfba8750476ff216b59eee3b88218bb5111cc # v1.303.0
6061
with:
6162
bundler-cache: true
62-
- name: Populate database for testing
63+
- name: Set up database for testing
6364
run: |
6465
bin/rails db:setup
6566
bin/rails feature_flags:enable_for_development
@@ -73,17 +74,17 @@ jobs:
7374
id: login-ecr
7475
uses: aws-actions/amazon-ecr-login@376925c9d111252e87ae59691e5a442dd100ef6a # v2.1.3
7576
# yamllint disable rule:line-length
76-
- name: get github ref short
77-
id: github-ref
77+
- name: Get image tag
78+
id: get-image-tag
7879
run: |
7980
git_ref=$(git rev-parse ${{ inputs.github_ref || github.ref_name == 'next' && 'origin/next' || github.ref_name }})
80-
echo "ref=$git_ref" >> "$GITHUB_OUTPUT"
81-
- name: Commit postgres container with database
81+
echo "value=$git_ref" >> "$GITHUB_OUTPUT"
82+
- name: Commit image
8283
run: >-
8384
docker commit database "${{ steps.login-ecr.outputs.registry
84-
}}/mavis/development/postgres_db:${{ steps.github-ref.outputs.ref }}"
85+
}}/mavis/development/postgres_db:${{ steps.get-image-tag.outputs.value }}"
8586
- name: Push image
8687
run: >-
8788
docker push "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{
88-
steps.github-ref.outputs.ref }}"
89+
steps.get-image-tag.outputs.value }}"
8990
# yamllint enable rule:line-length

.github/workflows/end-to-end-tests-aws.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: AWS deployment E2E tests
1+
name: AWS
22

33
on:
44
workflow_call:
@@ -122,7 +122,7 @@ jobs:
122122
permissions:
123123
id-token: write
124124
contents: read
125-
uses: ./.github/workflows/create_dockerized_db.yml
125+
uses: ./.github/workflows/build-and-push-database-image.yml
126126
with:
127127
github_ref: ${{ needs.check-database-image-presence.outputs.db_git_ref_sha }}
128128
launch-dockerized-devimage:

.github/workflows/end-to-end-tests-local.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
name: Local E2E tests
1+
name: Local
22

33
on: [workflow_call]
44

55
jobs:
66
end-to-end-tests:
77
runs-on: ubuntu-latest
88
services:
9-
postgres:
10-
image: postgres:17.2
9+
postgresql:
10+
image: postgis/postgis:17-master
1111
env:
1212
POSTGRES_PASSWORD: postgres
1313
options: >-

.github/workflows/end-to-end-tests-on-pull-request.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: E2E tests on PR
1+
name: End-to-end tests
22

33
on: [pull_request]
44

@@ -11,7 +11,7 @@ permissions: {}
1111
jobs:
1212
aws-e2e-flow:
1313
if: github.event.pull_request.head.repo.full_name == github.repository
14-
name: AWS deployment E2E tests
14+
name: AWS
1515
permissions:
1616
id-token: write
1717
contents: write
@@ -22,7 +22,7 @@ jobs:
2222

2323
local-e2e-flow:
2424
if: github.event.pull_request.head.repo.full_name != github.repository
25-
name: Local E2E tests
25+
name: Local
2626
uses: ./.github/workflows/end-to-end-tests-local.yml
2727

2828
ensure-run-success:

.github/workflows/test.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
name: RSpec
1212
runs-on: ubuntu-latest
1313
services:
14-
postgres:
15-
image: postgres:17.2
14+
postgresql:
15+
image: postgis/postgis:17-master
1616
env:
1717
POSTGRES_PASSWORD: postgres
1818
options: >-
@@ -50,8 +50,8 @@ jobs:
5050
name: Seeds
5151
runs-on: ubuntu-latest
5252
services:
53-
postgres:
54-
image: postgres:17.2
53+
postgresql:
54+
image: postgis/postgis:17-master
5555
env:
5656
POSTGRES_PASSWORD: postgres
5757
options: >-
@@ -60,7 +60,8 @@ jobs:
6060
- 5432:5432
6161
env:
6262
RAILS_ENV: development
63-
DATABASE_URL: postgres://postgres:postgres@localhost:5432/manage_vaccinations_development
63+
DATABASE_URL: >-
64+
postgis://postgres:postgres@localhost:5432/manage_vaccinations_development
6465
steps:
6566
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
6667
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
@@ -70,7 +71,7 @@ jobs:
7071
- uses: ruby/setup-ruby@60ecfba8750476ff216b59eee3b88218bb5111cc # v1.303.0
7172
with:
7273
bundler-cache: true
73-
- name: Check seeds run
74+
- name: Run seeds
7475
run: bin/rails db:prepare
7576

7677
jest:
@@ -82,5 +83,7 @@ jobs:
8283
with:
8384
node-version-file: .tool-versions
8485
cache: yarn
85-
- run: yarn install --immutable --immutable-cache --check-cache
86-
- run: yarn test
86+
- name: Install dependencies
87+
run: yarn install --immutable --immutable-cache --check-cache
88+
- name: Run tests
89+
run: yarn test

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ awscli 2.27.46
33
hk 1.37.0
44
nodejs 22.15.0
55
pkl 0.31.0
6-
postgres 17.2
76
python 3.14.4
8-
redis 8.2.1
97
ruby 4.0.3
108
shellcheck 0.11.0
119
yamllint 1.38.0
10+
yarn 4.9.4
11+
uv 0.11.7

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gem "stackprof"
2222

2323
# 3rd party gems
2424
gem "activerecord-import"
25+
gem "activerecord-postgis-adapter"
2526
gem "activerecord-session_store"
2627
gem "active_record_union"
2728
gem "amazing_print"

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ GEM
9090
timeout (>= 0.4.0)
9191
activerecord-import (2.2.0)
9292
activerecord (>= 4.2)
93+
activerecord-postgis-adapter (11.1.1)
94+
activerecord (~> 8.1.0)
95+
rgeo-activerecord (~> 8.1.0)
9396
activerecord-session_store (2.2.0)
9497
actionpack (>= 7.0)
9598
activerecord (>= 7.0)
@@ -664,6 +667,10 @@ GEM
664667
reverse_markdown (3.0.2)
665668
nokogiri
666669
rexml (3.4.4)
670+
rgeo (3.1.0)
671+
rgeo-activerecord (8.1.0)
672+
activerecord (>= 8.1, < 8.2)
673+
rgeo (>= 3.0)
667674
rladr (1.2.0)
668675
rspec (3.13.2)
669676
rspec-core (~> 3.13.0)
@@ -910,6 +917,7 @@ PLATFORMS
910917
DEPENDENCIES
911918
active_record_union
912919
activerecord-import
920+
activerecord-postgis-adapter
913921
activerecord-session_store
914922
amazing_print
915923
annotaterb

README.md

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ This is a service used within the NHS for managing and recording school-aged vac
1616

1717
We have two RDoc versions:
1818

19-
1. [next](https://nhsuk.github.io/manage-vaccinations-in-schools/rdoc/next) - useful for dev work (based off the `next` branch).
20-
2. [release](https://nhsuk.github.io/manage-vaccinations-in-schools/rdoc/release) - useful for ops to debug live issues (based off the `release` branch).
19+
- [next](https://nhsdigital.github.io/manage-vaccinations-in-schools/rdoc/next/) - useful for dev work (based off the `next` branch).
20+
- [release](https://nhsdigital.github.io/manage-vaccinations-in-schools/rdoc/release/) - useful for ops to debug live issues (based off the `release` branch).
2121

2222
## Development
2323

@@ -29,7 +29,7 @@ This project depends on:
2929
- [Ruby on Rails](https://rubyonrails.org/)
3030
- [NodeJS](https://nodejs.org/)
3131
- [Yarn](https://yarnpkg.com/)
32-
- [PostgreSQL](https://www.postgresql.org/)
32+
- [PostgreSQL](https://www.postgresql.org/) with [PostGIS](https://postgis.net/)
3333
- [Redis](https://redis.io/) or [Valkey](https://valkey.io/)
3434

3535
The instructions below assume you are using `mise` to manage the necessary
@@ -48,34 +48,55 @@ bin/bundle exec rladr new title
4848

4949
### Installing dependencies
5050

51-
This project uses `mise`. Use the following to set up (replace `brew` and
52-
package names depending on your platform):
51+
This project uses [`mise`](https://mise.jdx.dev/) to manage tool versions.
52+
53+
#### Prerequisites
54+
55+
Before you can run `mise install` you might need to install some system
56+
libraries and databases.
57+
58+
##### macOS with Homebrew
5359

5460
```shell
55-
# Dependencies for ruby
61+
# Dependencies for Ruby
5662
brew install libyaml
5763

58-
# Dependencies for postgres
59-
brew install gcc readline zlib curl ossp-uuid icu4c pkg-config
64+
# PostgreSQL
65+
brew install postgresql postgis
6066

61-
# Env vars for postgres
62-
export OPENSSL_PATH=$(brew --prefix openssl)
63-
export CMAKE_PREFIX_PATH=$(brew --prefix icu4c)
64-
export PATH="$OPENSSL_PATH/bin:$CMAKE_PREFIX_PATH/bin:$PATH"
65-
export LDFLAGS="-L$OPENSSL_PATH/lib $LDFLAGS"
66-
export CPPFLAGS="-I$OPENSSL_PATH/include $CPPFLAGS"
67-
export PKG_CONFIG_PATH="$CMAKE_PREFIX_PATH/lib/pkgconfig"
68-
export MACOSX_DEPLOYMENT_TARGET="$(sw_vers -productVersion)"
67+
# Redis
68+
brew install redis
6969

70-
# Version manager
70+
# Mise
7171
brew install mise
72+
```
73+
74+
##### Debian-based Linux
7275

73-
# Yarn via brew as this skips installing `gpg`
74-
brew install yarn
76+
```shell
77+
# Dependencies for Ruby
78+
sudo apt install build-essential autoconf libssl-dev libyaml-dev zlib1g-dev libffi-dev libgmp-dev libicu-dev rustc
79+
80+
# PostgreSQL
81+
sudo apt install -y postgresql-common
82+
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
83+
sudo apt install postgresql-17 postgresql-contrib postgresql-17-postgis-3
84+
sudo -u postgres psql -c "CREATE USER $(whoami); ALTER USER $(whoami) WITH SUPERUSER;"
85+
86+
# Redis
87+
sudo apt install redis-server
88+
89+
# Mise
90+
curl https://mise.run | sh
7591
```
7692

77-
Then to install the required tools (or update, following a change to
78-
`.tool-versions`):
93+
See [installing Mise](https://mise.jdx.dev/installing-mise.html) for more
94+
details on how to install Mise.
95+
96+
#### Using Mise
97+
98+
At this point it should now be possible to use `mise` to install the required
99+
versions of the tools.
79100

80101
```shell
81102
mise install
@@ -86,28 +107,33 @@ mise install
86107
For the application to start successfully, PostgreSQL and Redis/Valkey must be
87108
running.
88109

89-
#### PostgreSQL
110+
#### macOS with Homebrew
90111

91-
If using `brew`, the simplest option is to run `brew services start postgresql`.
112+
```shell
113+
brew services start postgresql redis
114+
```
92115

93-
Alternatively, you can run the server manually:
116+
#### Debian-based Linux
94117

95118
```shell
96-
pg_ctl start
97-
psql -U postgres -c "CREATE USER $(whoami); ALTER USER $(whoami) WITH SUPERUSER;"
119+
sudo systemctl start postgresql.service
120+
sudo systemctl start redis.service
98121
```
99122

100-
#### Redis/Valkey
123+
#### Manually
101124

102-
If using `brew`, the simplest option is to run `brew services start redis`.
125+
```shell
126+
pg_ctl start
127+
psql -U postgres -c "CREATE USER $(whoami); ALTER USER $(whoami) WITH SUPERUSER;"
128+
```
103129

104-
Alternatively, you can run the server manually:
130+
You may have to run this as root via `sudo`.
105131

106132
```shell
107133
redis-server
108134
```
109135

110-
### Running locally
136+
### Running the application
111137

112138
When running for the first time, `bin/setup` will automatically install Ruby
113139
dependencies and set up the database.

0 commit comments

Comments
 (0)