Skip to content

Commit

Permalink
Merge pull request #30 from GISdevio/final-refactoring
Browse files Browse the repository at this point in the history
Refactoring and Dockerization
  • Loading branch information
frafra authored Feb 15, 2024
2 parents cd4d533 + f130f85 commit 79fecf7
Show file tree
Hide file tree
Showing 166 changed files with 489 additions and 496 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Docker

on:
push:
branches: [ 'main' ]
pull_request:
branches: [ 'main' ]

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

jobs:
docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- context: backend
suffix: -backend
- context: webapp
suffix: -webapp
permissions:
contents: read
packages: write
steps:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Checkout
uses: actions/checkout@v4
-
name: Login to 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 }}${{ matrix.suffix }}
-
name: Build and push container
uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: ${{ matrix.context }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
86 changes: 21 additions & 65 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,47 @@
# Setup on Debian 11
# Setup

Everything is run inside `/srv`, if not specified otherwise.
Prerequisites:
- docker
- docker compose
- git

## Install dependencies

### Common

```bash
apt-get install \
`# generic`
git sqlite3 libsqlite3-mod-spatialite
`# web app`
npm \
nginx libnginx-mod-http-lua \
`# pbf` \
osmium-tool \
`# OsmAndMapCreator` \
openjdk-11-jre-headless \
`# gpkg` \
gdal-bin
```

### Clone repository
## Clone repository

```bash
git clone https://github.com/osmItalia/estratti_OSM_Italia.git
cd estratti_OSM_Italia
```

## Configuration

### Scripts

#### Prepare environment

```bash
source estratti_osm-it.env
```

#### Setup OsmAndMapCreator
## Run using Docker

```bash
mkdir -p "$OSMAND_DIR"
cd "$_"
wget https://download.osmand.net/latest-night-build/OsmAndMapCreator-main.zip
unzip OsmAndMapCreator-main
rm OsmAndMapCreator-main.zip
docker compose up --build
```

#### mapshaper and topojson
## Run without Docker

Additional setup that could be required on WM servers to run npm:
### Backend

```bash
sudo aptitude install npm # select second option
```

Install mapshaper and topojson:
It is suggested to use `nix` or `nix-portable` to create an environment with the dependencies installed

```bash
npm --prefix=$NPM_PREFIX install mapshaper
npm --prefix=$NPM_PREFIX install topojson-server
cd backend/
nix-shell --pure
make setup
make pbf
make -j$(nproc)
make webapp
```

#### Run

```bash
./run.sh
```
### Frontend

### Web

Modify `default` accordingly to your needs.
Configure NGINX by customizing `nginx/default.conf`. Adjust `src/configuration.json` if needed (read more at `frontend/README.md`).

```bash
cp nginx/default.conf /etc/nginx/sites-enabled/default
systemctl start nginx
systemctl enable nginx

cd webapp
cd frontend/
npm install
npm run build
```

### crontab (example)

```
0 2 * * * /srv/estratti_OSM_Italia/backend/run.sh
```
The contents of `build/` should be served by NGINX.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Repository sul lavoro svolto per [Wikimedia Italia](https://www.wikimedia.it/) c

La repository include tre directory:
- backend: sistema di generazione degli estratti e dei topojson semplificati con relazioni tra i vari enti (vedasi `run.sh`)
- nginx: contiene un template per la configuratione del web server e un sistema per l'aggiunta della data di creazione del file al nome del file stesso per il download
- webapp: webapp per il download degli estratti

Il file `INSTALL.md` contiene le informazioni per installare i requisiti e configurare il sistema.
Expand Down
25 changes: 0 additions & 25 deletions backend/01_basic_configuration.sh

This file was deleted.

8 changes: 0 additions & 8 deletions backend/02_download_latest.sh

This file was deleted.

18 changes: 0 additions & 18 deletions backend/03_generate_boundaries.sh

This file was deleted.

7 changes: 0 additions & 7 deletions backend/04_generate_geojson.sh

This file was deleted.

55 changes: 0 additions & 55 deletions backend/05_extract_pbf.sh

This file was deleted.

13 changes: 0 additions & 13 deletions backend/06_convert_gpkg.sh

This file was deleted.

23 changes: 0 additions & 23 deletions backend/07_convert_obf.sh

This file was deleted.

29 changes: 29 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM docker.io/library/debian:trixie

RUN --mount=type=cache,sharing=locked,target=/var/cache/apt \
--mount=type=cache,sharing=locked,target=/var/lib/apt \
rm /etc/apt/apt.conf.d/docker-clean && \
apt-get update && \
apt-get install -yq --no-install-recommends \
`# generic` \
curl gettext make anacron sqlite3 libsqlite3-mod-spatialite \
`# pbf` \
osmium-tool \
`# OsmAndMapCreator` \
libarchive-tools openjdk-17-jre-headless \
`# boundaries, gpkg` \
gdal-bin \
`# mapshaper, topojson` \
npm \
&& \
rm /etc/cron.daily/apt-compat /etc/cron.daily/dpkg

WORKDIR /root
# https://github.com/moby/moby/issues/17175
COPY Makefile .
RUN make setup

COPY scripts/ scripts/
COPY cronjob.sh /etc/cron.daily/estratti

CMD ["anacron", "-d"]
Loading

0 comments on commit 79fecf7

Please sign in to comment.