Skip to content

Commit

Permalink
Merge pull request #17 from camptocamp/add_FE_container
Browse files Browse the repository at this point in the history
geoshop FE
  • Loading branch information
marionb authored Aug 21, 2024
2 parents 39af703 + 30687f9 commit bc3e644
Show file tree
Hide file tree
Showing 13 changed files with 2,915 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
geoshop/resources/postgis_data/
35 changes: 23 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,11 @@ services:

# Geoshop
geoshop:
build: ./geoshop
build: ./geoshop/back
depends_on:
postgis:
condition: service_healthy
environment:
- POSTGRES_HOST=postgis
- POSTGRES_USER=geoshop
- POSTGRES_DB=geoshop
- POSTGRES_PASSWORD=geoshop
env_file: ./geoshop/.env
volumes:
- geoshop-files:/geoshop/files
healthcheck:
Expand All @@ -113,15 +109,30 @@ services:
timeout: 10s
retries: 15

# Geoshop Front End
# TODO: use env variables for the backend url and port
geoshop_fe:
build: ./geoshop/front
depends_on:
geoshop:
condition: service_healthy
ports:
# TODO repalce prot with env variable
- "8085:8080"

# Geoshop/Postgis
postgis:
image: postgis/postgis:14-3.2-alpine
environment:
- POSTGRES_DB=geoshop
- POSTGRES_USER=geoshop
- POSTGRES_PASSWORD=geoshop
volumes:
- ./geoshop/postgis:/docker-entrypoint-initdb.d/
- ./geoshop/resources/ini-scripts:/docker-entrypoint-initdb.d/:ro
- ./geoshop/resources/postgis_data:/var/lib/postgresql/data:rw
environment:
LANG: 'en_US.utf8'
LC_COLLATE: 'en_US.utf8'
LC_CTYPE: 'en_US.utf8'
env_file: ./geoshop/.env
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U geoshop"]
interval: 5s
Expand Down Expand Up @@ -210,4 +221,4 @@ services:
test: curl --fail http://localhost:4444/ || exit 1
interval: 10s
timeout: 10s
retries: 15
retries: 15
6 changes: 5 additions & 1 deletion geoshop/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PGPORT=5432
PGPASSWORD=geoshop
PGSCHEMA=geoshop

POSTGRES_USER=geoshop
POSTGRES_PASSWORD=geoshop
POSTGRES_DB=postgres

# The folder where the geodata will be uploaded
MEDIA_ROOT=/geoshop/files
# A link to public images used in product and metadata
Expand All @@ -31,7 +35,7 @@ LOGGING_LEVEL=INFO
# Generate this key with Django tools
SECRET_KEY=GenerateOneSecretKey
ADMIN_PASSWORD=Test1234
EXTRACT_USER_PASSWORD=Test1234
EXTRACT_USER_PASSWORD=5%G*1jA^BpJDiEpi

AUTO_LEGEND_URL=http://example.com/mapserv?FORMAT=image%2Fpng&TRANSPARENT=true&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&LAYER=
# If you plan to manage secret metadata, provide your intranet legend service
Expand Down
7 changes: 2 additions & 5 deletions geoshop/Dockerfile → geoshop/back/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ ENV POETRY_NO_INTERACTION=1 \
POETRY_HOME='/usr/local'

RUN apt update && \
apt install -y git curl libgdal-dev libffi-dev postgresql && \
apt install -y git libgdal-dev libffi-dev gettext && \
pip install poetry && \
git clone https://github.com/camptocamp/geoshop-back.git /geoshop/geoshop-back && \
cd /geoshop/geoshop-back && \
poetry install --only=main

COPY .env /geoshop/geoshop-back/.env
COPY settings.py /geoshop/geoshop-back/settings.py
COPY sampledata.sql /geoshop/sampledata.sql

COPY entrypoint.sh /geoshop/entrypoint.sh

# Copy default settings to settings only if there is no such file
RUN mv -vn /geoshop/geoshop-back/default_settings.py /geoshop/geoshop-back/settings.py
ENTRYPOINT [ "/geoshop/entrypoint.sh" ]
8 changes: 2 additions & 6 deletions geoshop/entrypoint.sh → geoshop/back/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ else
echo "No fixturizing needed."
fi

if [[ ! -f "/geoshop/.sampledata_lock" ]]; then
# TODO: Pass host, password and dbname from the env section of the postgis
PGPASSWORD=geoshop psql --host=postgis --username=geoshop --dbname=geoshop -p 5432 < /geoshop/sampledata.sql
touch "/geoshop/.sampledata_lock"
fi

python3 manage.py collectstatic --noinput
# TODO: translate all the languages or a defined one
python3 manage.py compilemessages --locale=fr
python3 manage.py runserver 0.0.0.0:8000
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions geoshop/front/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build with node
FROM node:22.6.0-slim AS builder
WORKDIR /usr/src/app

RUN apt update && \
apt upgrade -y && \
apt install -y git && \
git clone https://github.com/camptocamp/geoshop-front.git . && \
npm ci

COPY config.json src/assets/configs/config.json

RUN npm run build

# Serve with nginx unpprevileged
FROM nginxinc/nginx-unprivileged:stable

# copy server config
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

# Copy build artifacts
COPY --from=builder /usr/src/app/dist/ /usr/share/nginx/html
70 changes: 70 additions & 0 deletions geoshop/front/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"apiUrl": "http://localhost:8085/geoshop/",
"mediaUrl": "",
"baseMapUrl": "https://wmts.geo.admin.ch/1.0.0/{layer}/{style}/current/{TileMatrixSet}/{TileMatrix}/{TileCol}/{TileRow}",
"geocoderUrl": "https://nominatim.openstreetmap.org/search",
"geocoderLayers": [
"adresses_sitn", "nom_local_lieu_dit", "search_cours_eau",
"batiments_ofs", "axe_rue", "ImmeublesCanton", "communes", "cadastres",
"recenter_to"
],
"contact": {
"phone": {
"label": "",
"number": ""
},
"email": "[email protected]"
},
"initialCenter": [
2765505.527577451, 1173931.8492200195
],
"initialExtent": [
2420000, 1030000, 2900000, 1360000
],
"resolutions": [250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5],
"epsg": "EPSG:2056",
"basemaps": [
{
"id": "ch.swisstopo.pixelkarte-farbe",
"label": "Landeskarten (farbig)",
"description": "Landeskarten (farbig)",
"thumbUrl": "assets/images/planville.png",
"matrixSet": "2056",
"format": "jpeg"
},{
"id": "ch.swisstopo.pixelkarte-grau",
"label": "Karte Grau",
"description": "Karte Grau",
"thumbUrl": "assets/images/cadastre.png",
"matrixSet": "2056",
"format": "jpeg"
}
],
"pageformats": [
{
"name": "A4",
"width": 210,
"height": 297
},
{
"name": "A3",
"width": 297,
"height": 420
},
{
"name": "A2",
"width": 420,
"height": 594
},
{
"name": "A1",
"width": 594,
"height": 841
},
{
"name": "A0",
"width": 841,
"height": 1189
}
]
}
29 changes: 29 additions & 0 deletions geoshop/front/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
index index.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location / {
try_files $uri $uri/ /index.html =404;
}

location /welcome {
rewrite ^/welcome/?$ / break;
}

location /geoshop/ {
# Remove /api prefix and forward to geoportal
rewrite ^/geoshop/(.*)$ /$1 break;
proxy_pass http://geoshop:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Loading

0 comments on commit bc3e644

Please sign in to comment.