Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.github
.vscode
data/
LICENSE.md
README.md
ATTRIBUTION.md
.env*
docker-compose.yml
31 changes: 31 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# EditorConfig is awesome: https://EditorConfig.org

# Top-most EditorConfig file
root = true

# Default settings for all files
[*]
charset = utf-8
end_of_line = lf
# insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

# YAML files often use 2-space indentation
[*.{yaml,yml}]
indent_style = space
indent_size = 2

[*.{json}]
indent_style = space
indent_size = 2

# Makefiles require tabs
[Makefile]
indent_style = tab

[*.go]
indent_style = tab
tab_width = 4
max_line_length = 100
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
131 changes: 131 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Build and publish Docker image

on:
push:
branches: ["main"]
tags: ["v*.*.*"]
pull_request:
branches: ["main"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
checks: write

services:
docker:
image: docker:dind
options: --privileged

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"

- name: Install testcontainers dependencies
run: docker --version

- name: Cache Docker images
uses: actions/cache@v4
with:
path: /var/lib/docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-docker-

- name: Test
run: |
go install gotest.tools/gotestsum@latest
mkdir -p ./test-reports/
gotestsum --junitfile=./test-reports/junit.xml --format github-actions -- -v -coverprofile=profile.cov -coverpkg=./... ./...

- name: Collect test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: ./test-reports/

- name: Publish test results
uses: mikepenz/action-junit-report@v5
if: always()
with:
report_paths: "./test-reports/junit.xml"
comment: true
include_passed: true
detailed_summary: true

- name: Upload coverage to Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov

- name: Lint
uses: golangci/golangci-lint-action@v8

docker-publish:
concurrency:
group: "publishing"
needs:
- build-and-test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write

steps:
- name: Checkout repository with full history
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: "Log into registry: ${{ env.REGISTRY }}"
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha
labels: |
maintainer=rm-hull
org.opencontainers.image.description=REST API for GPS routes
org.opencontainers.image.licenses=MIT

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64 #,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ go.work.sum
# Editor/IDE
# .idea/
# .vscode/

data/
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch HTTP server",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": []
}
]
}
7 changes: 7 additions & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Attribution

You may use this data under the Open Government License v3.0, and must include the following copyright notices:

- Contains OS data © Crown copyright and database right 2020
- Contains Royal Mail data © Royal Mail copyright and database right 2020
- Source: Office for National Statistics licensed under the Open Government Licence v.3.0
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM golang:1.24-alpine AS build

RUN apk update && \
apk add --no-cache ca-certificates tzdata git && \
update-ca-certificates

RUN adduser -D -g '' appuser

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

ENV GOOS=linux

RUN go build -ldflags="-w -s" -o postcode-polygons .

FROM alpine:latest AS runtime
ENV GIN_MODE=release
ENV TZ=UTC

RUN apk --no-cache add curl ca-certificates tzdata && \
update-ca-certificates

RUN adduser -D -g '' appuser
WORKDIR /app

COPY --from=build /app/postcode-polygons .
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /usr/share/zoneinfo /usr/share/zoneinfo

USER appuser
EXPOSE 8080/tcp

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1

ENTRYPOINT ["./postcode-polygons"]
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# postcode-polygons
# Postcode Polygons

## Data extraction and reprocessing

First download (or otherwise generate) the **gb-postcodes-v5.tar.bz2** data file. See https://longair.net/blog/2021/08/23/open-data-gb-postcode-unit-boundaries/.

```console
$ curl https://postcodes-mapit-static.s3.eu-west-2.amazonaws.com/data/gb-postcodes-v5.tar.bz2 -O data/gb-postcodes-v5.tar.bz2
$ go run main.go
```
Loading