-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Dockerise Colouring London #780
Draft
edwardchalstrey1
wants to merge
9
commits into
master
Choose a base branch
from
dockerise-colouring-london
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2fe85a7
first attempt docker
edwardchalstrey1 08f3348
add init user db
edwardchalstrey1 478925a
Merge branch 'master' into dockerise-colouring-london
edwardchalstrey1 7ea23a8
use postgres 12
edwardchalstrey1 565bd68
dont create db - should exist
edwardchalstrey1 1667c04
correct path to volumes
edwardchalstrey1 f15e764
dont copy parts of the repo not needed
edwardchalstrey1 59dcc32
steps
edwardchalstrey1 709433d
more docker experimenting (not working yet)
edwardchalstrey1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update -y | ||
RUN apt-get upgrade -y | ||
|
||
RUN apt-get install -y build-essential wget | ||
RUN apt-get install parallel -y | ||
|
||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait | ||
RUN chmod +x /wait | ||
|
||
RUN mkdir /colouring-london | ||
COPY app /colouring-london/app | ||
COPY migrations /colouring-london/migrations | ||
COPY etl /colouring-london/etl | ||
|
||
ENV NODE_VERSION=16.13.2 | ||
RUN apt-get install -y curl | ||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash | ||
ENV NVM_DIR=/root/.nvm | ||
RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} | ||
RUN . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} | ||
RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} | ||
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}" | ||
|
||
RUN npm install -g npm@latest | ||
|
||
WORKDIR ./colouring-london/app | ||
RUN rm -rf node_modules | ||
RUN npm install | ||
|
||
EXPOSE 8080 | ||
CMD /wait && npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
version: "3" | ||
services: | ||
colouring-london: | ||
container_name: colouring-london | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
depends_on: | ||
- db | ||
environment: | ||
DATABASE_URL: postgres://dockeruser:postgres@postgres-colouring-london:5432/colouringlondon | ||
NODE_ENV: development | ||
PORT: 8080 | ||
APP_COOKIE_SECRET: 123456 | ||
ports: | ||
- "8080:8080" | ||
db: | ||
container_name: postgres-colouring-london | ||
image: ubuntu/postgres:13-21.10_beta | ||
ports: | ||
- "5432:5432" | ||
volumes: | ||
- ./postgresdata:/var/lib/postgresql/data | ||
- ./colouring-london/migrations:/colouring-london/migrations | ||
- ./colouring-london/etl:/colouring-london/etl | ||
- ./colouring-london/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh | ||
restart: always | ||
environment: | ||
POSTGRES_USER: dockeruser | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: colouringlondon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Create corresponding 'building' record with | ||
# id: <building-guid>, | ||
# doc: {}, | ||
# geom_id: <polygon-guid> | ||
# | ||
psql -d colouringlondon -c "INSERT INTO buildings ( geometry_id, ref_toid ) SELECT geometry_id, source_id from geometries;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Load geometries from GeoJSON to Postgres | ||
# - assume postgres connection details are set in the environment using PGUSER, PGHOST etc. | ||
# | ||
: ${1?"Usage: $0 ./path/to/mastermap/dir"} | ||
|
||
mastermap_dir=$1 | ||
|
||
# | ||
# Create 'geometry' record with | ||
# id: <polygon-guid>, | ||
# source_id: <toid>, | ||
# geom: <geom> | ||
# | ||
find $mastermap_dir -type f -name '*.3857.csv' \ | ||
-printf "$mastermap_dir/%f\n" | \ | ||
parallel \ | ||
cat {} '|' psql -d colouringlondon -c "\"COPY geometries ( geometry_geom, source_id ) FROM stdin WITH CSV HEADER;\"" | ||
|
||
# | ||
# Delete any duplicated geometries (by TOID) | ||
# | ||
psql -d colouringlondon -c "DELETE FROM geometries a USING ( | ||
SELECT MIN(ctid) as ctid, source_id | ||
FROM geometries | ||
GROUP BY source_id | ||
HAVING COUNT(*) > 1 | ||
) b | ||
WHERE a.source_id = b.source_id | ||
AND a.ctid <> b.ctid;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
apt-get update -y | ||
apt-get upgrade -y | ||
|
||
apt-get install -y postgresql-contrib libpq-dev postgis | ||
apt-get install -y postgresql-13-postgis-3 | ||
apt-get install -y gdal-bin libspatialindex-dev libgeos-dev libproj-dev | ||
|
||
apt-get install -y python3 python3-pip python3-dev | ||
|
||
psql -d colouringlondon -U dockeruser -c "SELECT 1 FROM pg_user WHERE usename = 'dockeruser';" | grep -q 1 || psql -d colouringlondon -U dockeruser -c "CREATE ROLE dockeruser SUPERUSER LOGIN PASSWORD 'postgres';" | ||
psql -d colouringlondon -U dockeruser -c "SELECT 1 FROM pg_database WHERE datname = 'colouringlondon';" | grep -q 1 || -u postgres createdb -E UTF8 -T template0 --locale=en_US.utf8 -O dockeruser colouringlondon | ||
|
||
psql -d colouringlondon -U dockeruser -c "create extension postgis;" | ||
psql -d colouringlondon -U dockeruser -c "create extension pgcrypto;" | ||
psql -d colouringlondon -U dockeruser -c "create extension pg_trgm;" | ||
|
||
ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d colouringlondon < $migration; done; | ||
|
||
pip install --upgrade pip | ||
pip install --upgrade setuptools wheel | ||
pip install -r ./colouring-london/etl/requirements.txt | ||
|
||
python ./colouring-london/etl/get_test_polygons.py | ||
./colouring-london/etl/load_geometries_cl.sh ./ | ||
psql -d colouringlondon -U dockeruser < ./colouring-london/app/migrations/002.index-geometries.up.sql | ||
./create_building_records_cl.sh | ||
psql -d colouringlondon -U dockeruser < ./colouring-london/app/migrations/003.index-buildings.up.sql | ||
ls ./colouring-london/migrations/*.up.sql 2>/dev/null | while read -r migration; do psql -d colouringlondon < $migration; done; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment