Skip to content
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

Dockerized development #29

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Auto detect text files and perform LF normalization,
# when the file has been committed with CRLF, no conversion is done.
* text=auto
31 changes: 16 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/npm-debug.log
/node_modules
/dist
/build
.idea
*~
/documento.odt
/src/index.html
/assets/style/less/g3w-skins-custom/
/build
/config.js
/test/
/deploy/
/src/libs/sdk/g3w-ol3/config/config.js
/src/libs/sdk/config/dev/
/src/plugins/
/src/app/dev/
/src/config/keys/index.js
/cypress.env.json
/deploy/
/dist
/documento.odt
/g3w-admin/
/node_modules
/npm-debug.log
/test/
/test/config/
/src/app/__dev__/
/src/app/core/iframe/test/
/src/app/dev/
/src/config/dev/index.js
/assets/style/less/g3w-skins-custom/
/src/app/__dev__/
/src/config/keys/index.js
/src/libs/sdk/config/dev/
/src/libs/sdk/g3w-ol3/config/config.js
/src/index.html
/src/plugins/
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# If set to true, npm will refuse to install any package
# not compatible with the current Node version (see "engines" in package.json)
engine-strict=true
8 changes: 4 additions & 4 deletions config.template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const PROTOCOL = 'http';
const HOST = '127.0.0.1';
const PROXY_PORT = '8001';
const PROXY_PORT = '8000';
const LOCAL_PORT = '3000';

const conf = {
Expand All @@ -11,9 +11,9 @@ const conf = {
localServerPort: LOCAL_PORT, // port for local server. If not set local server run on port 3000
g3w_admin_paths: {
dev: {
g3w_admin_plugins_basepath: '<RELATIVE PATH OF G3W-ADMIN-INSTALLATION>/g3w-admin/g3w-admin/', // local G3W-ADMIN main path code
g3w_admin_client_dest_static: '<RELATIVE PATH OF G3W-ADMIN-INSTALLATION>/g3w-admin/g3w-admin/client/static', // local G3W-ADMIN client static path
g3w_admin_client_dest_template: '<RELATIVE PATH OF G3W-ADMIN-INSTALLATION>/g3w-admin/g3w-admin/client/templates', // local G3W-ADMIN client template folder
g3w_admin_plugins_basepath: '../g3w-admin/g3w-admin/', // local G3W-ADMIN main path code
g3w_admin_client_dest_static: '../g3w-admin/g3w-admin/client/static', // local G3W-ADMIN client static path
g3w_admin_client_dest_template: '../g3w-admin/g3w-admin/client/templates', // local G3W-ADMIN client template folder
}
},
host: HOST,
Expand Down
47 changes: 47 additions & 0 deletions docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
G3WSUITE_LOCAL_CODE_PATH=../../g3w-admin
G3WSUITE_DEBUG=True

# Public hostmane
WEBGIS_PUBLIC_HOSTNAME=dev.g3wsuite.it

# Shared volume mount (docker internal: shared-volume)
# I suggest not to use the /tmp/ folder, /tmp/ folder is cleaned at each reboot
WEBGIS_DOCKER_SHARED_VOLUME=/tmp/shared-volume-g3wsuite-dev

# Docker internal DB
G3WSUITE_POSTGRES_USER_LOCAL=g3wsuite
G3WSUITE_POSTGRES_PASS=89#kL8y3D
G3WSUITE_POSTGRES_DBNAME=g3wsuite
G3WSUITE_POSTGRES_HOST=postgis
G3WSUITE_POSTGRES_PORT=5432

# Set this to true to activate the frontend module
FRONTEND=False

# QGIS Server env variables
# ----------------------------------------------------
PGSERVICEFILE=/pg_service/pg_service.conf
# Put your pg service into ./scripts/pg_service.conf file, the conf file will be mounted into
# docker container at runtime a the PGSERVICEFILE

QGIS_SERVER_LOG_FILE=/shared_volume/QGIS/error.log
QGIS_SERVER_LOG_LEVEL=2

# Extra QGIS env variables.
# Every QGIS environment variables available as specified on manual
# https://docs.qgis.org/3.22/en/docs/server_manual/config.html#environment-variables
# can be set, important is remember to add thy to `docker-compose.yml` o `docker-compose-consument.yml`.

# Openrouteservice
# ----------------------------------------------------
#ORS_API_ENDPOINT='https://api.openrouteservice.org/v2'
# Optional, can be blank if the key is not required by the endpoint
#ORS_API_KEY='<your API key goes here>'
# Max number of ranges (it depends on the server configuration)
#ORS_MAX_RANGES=6
# Max number of locations(it depends on the server configuration)
#ORS_MAX_LOCATIONS=2

# *Important*: remember to add this env vars also to docker-compose.yml or
# docker-compose-consumer.yml

126 changes: 126 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# G3W-CLIENT docker container

In this folder you can find various scripts and configuration files needed to set up a suitable local docker container to test and develop the [g3w-client](https://g3w-suite.readthedocs.io/en/latest/g3wsuite_client.html) cartographic viewer.

---

## Project setup

Download and install [Node.js and NPM](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) and [Docker Compose](https://docs.docker.com/compose/install/) in your development enviroment.

Clone and place the [g3w-admin](https://github.com/g3w-suite/g3w-admin) and [g3w-client](https://github.com/g3w-suite/g3w-client) repositories into two separated adjacent folders:

```sh
cd /path/to/your/development/workspace

git clone https://github.com/g3w-suite/g3w-admin.git --single-branch --branch dev ./g3w-admin
git clone https://github.com/g3w-suite/g3w-client.git --single-branch --branch dev ./g3w-client
```

Download all javascript and docker dependencies from within your [g3w-client](https://github.com/g3w-suite/g3w-client) local repository:

```sh
cd ./g3w-client
```
```sh
npm install # javascript dependencies (client)
```
```sh
npm run docker pull # docker dependencies (admin)
```

For more info about this project dependencies see:

- [package.json](../package.json)
- [docker-compose.yml](./docker-compose.yml)

---

## How to develop

You can start the built-in development servers (client + admin) by using the following command:

```sh
npm run dev
```

Before that, for the first time only, create these configuration files from the available templates:

- [/config.template.js](../config.template.js) --> `/config.js`
- [/src/config/dev/index.template.js](../src/config/dev/index.template.js) --> `src/config/dev/index.js`
- [/src/config/keys/index.template.js](../src/config/keys/index.template.js) --> `src/config/keys/index.js`

---

## Overview of Docker Compose

For those unfamiliar with docker development [docker-compose](https://docs.docker.com/compose/) is a tool for defining and running multi-container applications.

Below are described the most frequent commands, that are also available here in this repository as [npm scripts](https://docs.npmjs.com/cli/run-script/), you can find similar information by running `npm run` from the command line.


Define and run the services that make up the g3w-client (admin) development server:

```
docker
docker compose --env-file ./docker/.env --file ./docker/docker-compose.yml --project-name g3w-client --project-directory ./docker
```

Create and start containers (run default admin server at [localhost:8000](http://localhost:8000)):

```
docker:up
npm run docker up -- -d
```

Stop and remove containers, networks, images, and volumes:

```
docker:down
npm run docker down
```

Validate and view the Compose file (load and parse [docker-compose.yml](./docker-compose.yml) and [.env](./.env) variables):

```
docker:config
npm run docker config
```

View output from containers:

```
docker:logs
npm run docker logs
```

For more info:

- [Overview of docker-compose CLI](https://docs.docker.com/compose/reference/)

---

## Additional setup and troubleshooting

These are some environment variables defined within the [.env](./.env) file that you might be interested in checking:

- `G3WSUITE_LOCAL_CODE_PATH`: path to local [g3w-admin](https://github.com/g3w-suite/g3w-admin) folder (default: `../../g3w-admin`)
- `G3WSUITE_DEBUG`: True | False
- `WEBGIS_DOCKER_SHARED_VOLUME`: path to docker container shared volume (default: `/tmp/shared-volume-g3wsuite-dev`)

If you are having trouble with your current project configuration you can use the docker config command to inspect the actual values of the variables passed to your docker container:

```sh
npm run docker config
```

If your container struggles to boot properly you can also use the docker logs command related to a specific container:

```sh
npm run docker logs g3w-suite -- -f
npm run docker logs postgis -- -f
```

For more info:

- [Overview of g3w-suite dockerization](https://g3w-suite.readthedocs.io/en/latest/docker.html)