Skip to content

Commit 39887be

Browse files
authored
Merge pull request #239 from ngageoint/local-dockerfile
Local dockerfile
2 parents 333850b + 46918ea commit 39887be

File tree

7 files changed

+242
-124
lines changed

7 files changed

+242
-124
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
lib

Dockerfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Build service
2+
FROM node:20.11.1 AS build-service
3+
4+
WORKDIR /service
5+
COPY service/package*.json ./
6+
RUN npm install
7+
COPY service/ ./
8+
RUN npm run build
9+
10+
# RUN rm -rf node_modules
11+
RUN npm pack
12+
13+
# Build web-app
14+
FROM node:20.11.1 AS build-webapp
15+
16+
WORKDIR /web-app
17+
COPY web-app/package*.json ./
18+
RUN npm install
19+
COPY web-app/ ./
20+
RUN npm run build
21+
22+
# RUN rm -rf node_modules
23+
RUN npm pack ./dist
24+
25+
FROM node:20.11.1 AS build-arcwebplugin
26+
# Build arcgis service plugin
27+
WORKDIR /arcgiswebplugin
28+
COPY plugins/arcgis/web-app/package*.json ./
29+
RUN npm install
30+
COPY --from=build-service /service /arcgisserviceplugin/node_modules/@ngageoint/mage.service
31+
COPY plugins/arcgis/web-app/ ./
32+
RUN npm run build
33+
RUN npm pack ./dist/main
34+
35+
FROM node:20.11.1 AS build-arcserviceplugin
36+
WORKDIR /arcgisserviceplugin
37+
COPY plugins/arcgis/service/package*.json ./
38+
RUN npm install
39+
COPY --from=build-service /service /arcgisserviceplugin/node_modules/@ngageoint/mage.service
40+
COPY plugins/arcgis/service/ ./
41+
RUN npm run build
42+
RUN npm pack
43+
44+
FROM node:20.11.1 AS build-imageserviceplugin
45+
WORKDIR /imageserviceplugin
46+
COPY plugins/image/service/package*.json ./
47+
RUN npm install
48+
COPY --from=build-service /service /imageserviceplugin/node_modules/@ngageoint/mage.service
49+
COPY plugins/arcgis/service/ ./
50+
RUN npm run build
51+
RUN npm pack
52+
53+
# Build instance
54+
FROM node:20.11.1 AS build-instance
55+
COPY --from=build-service /service/ngageoint*.tgz /service/
56+
COPY --from=build-webapp /web-app/ngageoint*.tgz /web-app/
57+
COPY --from=build-arcwebplugin /arcgiswebplugin/ngageoint*.tgz /arcgiswebplugin/
58+
COPY --from=build-arcserviceplugin /arcgisserviceplugin/ngageoint*.tgz /arcgisserviceplugin/
59+
60+
WORKDIR /instance
61+
RUN npm install ../service/ngageoint-mage.service*.tgz \
62+
npm install ../web-app/ngageoint-mage.web-app*.tgz \
63+
npm install ../arcgiswebplugin/ngageoint*.tgz \
64+
npm install ../arcgisserviceplugin/ngageoint*.tgz
65+
66+
67+
ENV NODE_PATH=./node_modules
68+
ENTRYPOINT [ \
69+
"./node_modules/.bin/mage.service", \
70+
"--plugin", "@ngageoint/mage.image.service", \
71+
"--plugin", "@ngageoint/mage.arcgis.service", \
72+
"--web-plugin", "@ngageoint/mage.arcgis.web-app" \
73+
]

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,118 @@ in your plugin working tree. You can check using the `npm ls` command as follow
363363
└── @ngageoint/[email protected] -> ./../../../service
364364
```
365365

366+
## Docker Setup
367+
The docker directory includes documentation and dockerfiles for building using the release npm packages. The root Dockerfile and docker-compose.yml are used for building and running a dockerfile from the source/local code. Simply run `docker compose up` to spin up a local mongo db database along with the web server. After it starts up, navitage to localhost:4242 to view the web server.
368+
369+
By default, the Dockerfile includes additional plugins. Should you want to add/remove any plugins, you will need to modify the Entrypoint command. Simply uncomment the `entrypoint` section of the docker compose to specify what plugins you would like to include, or exlude
370+
371+
### HTTPS/TLS reverse proxy
372+
373+
Then `mage-web-proxy` service is optional when developing and running on
374+
localhost, but highly recommended when running MAGE Server on publicly
375+
accessible servers. The service in `docker-compose.yml` uses the official
376+
nginx docker image with an appropriate [configuration](web/nginx.conf). This
377+
is an example of setting up a reverse proxy in front of the Node server to
378+
enforce HTTPS/TLS connections to the server. Of course, you could use any
379+
reverse proxy you see fit, such as [Apache HTTP Server](https://httpd.apache.org/)
380+
or an AWS [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html). To run your MAGE server behind the TLS
381+
reverse proxy, peform the following modifications to `docker-compose.yml`.
382+
1. Comment the `ports` block for the `mage-server` service to disallow
383+
connections directly to the Node.js server.
384+
1. Uncomment the block with the `mage-web-proxy` service key.
385+
386+
For testing in a development environment, you can create a self-signed server
387+
certificate for nginx to use. The following OpenSSL command, run from the
388+
directory of this README, will create a self-signed server certificate and
389+
private key in the `web` directory that should allow the MAGE mobile app to
390+
connect to nginx. Replace the values of the `SUBJ_*` variables at the
391+
beginning of the command with your own values.
392+
```
393+
SUBJ_C="XX" \
394+
SUBJ_ST="State" \
395+
SUBJ_L="Locality" \
396+
SUBJ_O="Organization" \
397+
SUBJ_OU="Organizational_Unit" \
398+
SUBJ_CN="HOST_NAME_OR_IP"; \
399+
openssl req -new -nodes -x509 -newkey rsa:4096 -sha256 -days 1095 \
400+
-out web/mage-web.crt -keyout web/mage-web.key \
401+
-config <(cat /etc/ssl/openssl.cnf <(printf "[mage]\n \
402+
subjectAltName=DNS:$SUBJ_CN\n \
403+
basicConstraints=CA:true")) \
404+
-subj "/C=$SUBJ_C/ST=$SUBJ_ST/L=$SUBJ_L/O=$SUBJ_O/OU=$SUBJ_OU/CN=$SUBJ_CN" \
405+
-extensions mage; \
406+
unset SUBJ_C SUBJ_ST SUBJ_L SUBJ_O SUBJ_OU SUBJ_CN
407+
```
408+
The preceding command creates `web/mage-web.crt` and `web/mage-web.key`, which
409+
the nginx configuration file references. The `<(...)` operator is Unix process
410+
substitution and allows treating the enclosed command output as a file. The
411+
`subjectAltName` and `basicConstraints` arguments are necessary to install the
412+
public certificate, `mage-web.crt`, as a trusted authority on a mobile device.
413+
414+
**IMPORTANT** If you intend to connect to your reverse proxy from a mobile
415+
device or simulator/emulator running the MAGE mobile app, make sure that the
416+
value of the `SUBJ_CN` variable matches the IP address of your MAGE Server
417+
host on your network, or the resolvable host name of the host. TLS connections
418+
will not succeed if Common Name and Subject Alternative Name fields in the
419+
public certificate do not match the host name.
420+
421+
When running with the reverse proxy and default port settings in the Compose
422+
file, your server will be available at https://localhost:5443. If you are
423+
connecting from a mobile device on the same network.
424+
425+
### Bind mounts
426+
427+
The Compose file uses [bind mounts](https://docs.docker.com/storage/bind-mounts/)
428+
for the MongoDB database directory, database log path, and MAGE server
429+
[resources](../README.md#mage-local-media-directory). By default, the source
430+
paths of those bind mounts are `database/data`, `database/log`, and
431+
`server/resources`, respectively. You can change the source paths according to
432+
your environment and needs.
433+
434+
With these bind mounts, the MAGE server will retain its data on your host file
435+
system in directories you can explore and manage yourself. For example, this
436+
setup allows you to mount a directory into the MAGE server container from a
437+
[FUSE-based](https://github.com/libfuse/libfuse) file system, which might
438+
provide extra functionality like [encryption](https://www.veracrypt.fr) or
439+
[remote mounting](https://github.com/libfuse/sshfs) transparently to the
440+
Docker container and MAGE application. If you don't have any requirements of
441+
that sort, you can modify the Compose file to use [Docker-managed volumes](https://docs.docker.com/storage/volumes/) instead of bind mounts.
442+
443+
### Ports
444+
The only port the Compose file exposes to the host by default is 4242 on the
445+
`mage-server` service to allow HTTP connections from your host web browser to
446+
the MAGE server running in the Docker container. In a production environment,
447+
you could add another service in the Compose file to run an
448+
[nginx](https://hub.docker.com/_/nginx/) or [httpd](https://hub.docker.com/_/httpd/)
449+
reverse proxy with TLS or other security measures in front of the MAGE Server
450+
Node application. In that case you would remove the
451+
```yaml
452+
ports:
453+
- 4242:4242
454+
```
455+
lines from the Compose file under the `mage-server` service entry. You would
456+
then most likely add the mapping
457+
```yaml
458+
ports:
459+
- 443:443
460+
```
461+
to the reverse proxy's service definition.
462+
463+
You can also allow connections from your host to the MongoDB database container
464+
by uncommenting the `ports` block of the `mage-db` service. You would then be
465+
able to connect directly to the MongoDB database using the `mongo` client on
466+
your host machine to examine or modify the database contents.
467+
468+
### Environment settings
469+
470+
You can configure the MAGE server Docker app using [environment variables](../README.md#mage-environment-settings).
471+
The Compose file does this by necessity to configure the MongoDB URL for the MAGE server.
472+
```yaml
473+
environment:
474+
MAGE_MONGO_URL: mongodb://mage-db:27017/magedb
475+
```
476+
477+
366478
## ReST API
367479

368480
The MAGE ReSTful API is documented using [OpenAPI](https://swagger.io/specification/). A MAGE server instance includes

docker-compose.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
services:
2+
3+
mage-db:
4+
image: mongo:4.4-focal
5+
# Uncomment the following ports block to allow the mongo client on your
6+
# host machine to connect to MongoDB in the Docker container.
7+
# ports:
8+
# - 27017:27017
9+
networks:
10+
- mage.net
11+
12+
mage-server:
13+
depends_on: [ mage-db ]
14+
build:
15+
context: ./
16+
# dockerfile: Dockerfile-debug
17+
image: mage:local
18+
# entrypoint: ["./node_modules/.bin/mage.service", "--plugin", "@ngageoint/mage.image.service"] Uncomment to specify new entrypoint commands
19+
platform: linux/amd64
20+
volumes:
21+
- ./server/resources:/var/lib/mage
22+
# Comment the ports block to disallow connections directly to the node
23+
# server when running the mage-web-proxy below.
24+
ports:
25+
- 4242:4242
26+
# Uncomment to allow debuggers to attach the Node process inside the
27+
# container on port 14242
28+
# - 14242:14242
29+
networks:
30+
- mage.net
31+
environment:
32+
MAGE_MONGO_URL: mongodb://mage-db:27017/magedb
33+
MAGE_TOKEN_EXPIRATION: "28800"
34+
35+
# Uncomment the following block to enable the TLS reverse proxy. You will
36+
# also need to generate the key and certificate as the README describes.
37+
# mage-web-proxy:
38+
# image: nginx
39+
# volumes:
40+
# - ./web/nginx.conf:/etc/nginx/nginx.conf
41+
# - ./web/mage-web.crt:/etc/nginx/ssl/web.crt
42+
# - ./web/mage-web.key:/etc/nginx/ssl/web.key
43+
# ports:
44+
# - 4280:80
45+
# - 4243:4243
46+
# networks:
47+
# - mage.net
48+
49+
networks:
50+
mage.net:
51+
driver: bridge

docker/README.md

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -158,109 +158,5 @@ mage-server 6.3.0-beta.1 34093daa6c4e 2 hours ago 522MB
158158
Note the same values in the `IMAGE ID` column in the example output, along with
159159
different `TAG` values.
160160

161-
### HTTPS/TLS reverse proxy
162161

163-
Then `mage-web-proxy` service is optional when developing and running on
164-
localhost, but highly recommended when running MAGE Server on publicly
165-
accessible servers. The service in `docker-compose.yml` uses the official
166-
nginx docker image with an appropriate [configuration](web/nginx.conf). This
167-
is an example of setting up a reverse proxy in front of the Node server to
168-
enforce HTTPS/TLS connections to the server. Of course, you could use any
169-
reverse proxy you see fit, such as [Apache HTTP Server](https://httpd.apache.org/)
170-
or an AWS [Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html). To run your MAGE server behind the TLS
171-
reverse proxy, peform the following modifications to `docker-compose.yml`.
172-
1. Comment the `ports` block for the `mage-server` service to disallow
173-
connections directly to the Node.js server.
174-
1. Uncomment the block with the `mage-web-proxy` service key.
175-
176-
For testing in a development environment, you can create a self-signed server
177-
certificate for nginx to use. The following OpenSSL command, run from the
178-
directory of this README, will create a self-signed server certificate and
179-
private key in the `web` directory that should allow the MAGE mobile app to
180-
connect to nginx. Replace the values of the `SUBJ_*` variables at the
181-
beginning of the command with your own values.
182-
```
183-
SUBJ_C="XX" \
184-
SUBJ_ST="State" \
185-
SUBJ_L="Locality" \
186-
SUBJ_O="Organization" \
187-
SUBJ_OU="Organizational_Unit" \
188-
SUBJ_CN="HOST_NAME_OR_IP"; \
189-
openssl req -new -nodes -x509 -newkey rsa:4096 -sha256 -days 1095 \
190-
-out web/mage-web.crt -keyout web/mage-web.key \
191-
-config <(cat /etc/ssl/openssl.cnf <(printf "[mage]\n \
192-
subjectAltName=DNS:$SUBJ_CN\n \
193-
basicConstraints=CA:true")) \
194-
-subj "/C=$SUBJ_C/ST=$SUBJ_ST/L=$SUBJ_L/O=$SUBJ_O/OU=$SUBJ_OU/CN=$SUBJ_CN" \
195-
-extensions mage; \
196-
unset SUBJ_C SUBJ_ST SUBJ_L SUBJ_O SUBJ_OU SUBJ_CN
197-
```
198-
The preceding command creates `web/mage-web.crt` and `web/mage-web.key`, which
199-
the nginx configuration file references. The `<(...)` operator is Unix process
200-
substitution and allows treating the enclosed command output as a file. The
201-
`subjectAltName` and `basicConstraints` arguments are necessary to install the
202-
public certificate, `mage-web.crt`, as a trusted authority on a mobile device.
203-
204-
**IMPORTANT** If you intend to connect to your reverse proxy from a mobile
205-
device or simulator/emulator running the MAGE mobile app, make sure that the
206-
value of the `SUBJ_CN` variable matches the IP address of your MAGE Server
207-
host on your network, or the resolvable host name of the host. TLS connections
208-
will not succeed if Common Name and Subject Alternative Name fields in the
209-
public certificate do not match the host name.
210-
211-
When running with the reverse proxy and default port settings in the Compose
212-
file, your server will be available at https://localhost:5443. If you are
213-
connecting from a mobile device on the same network.
214-
215-
### Bind mounts
216-
217-
The Compose file uses [bind mounts](https://docs.docker.com/storage/bind-mounts/)
218-
for the MongoDB database directory, database log path, and MAGE server
219-
[resources](../README.md#mage-local-media-directory). By default, the source
220-
paths of those bind mounts are `database/data`, `database/log`, and
221-
`server/resources`, respectively. You can change the source paths according to
222-
your environment and needs.
223-
224-
With these bind mounts, the MAGE server will retain its data on your host file
225-
system in directories you can explore and manage yourself. For example, this
226-
setup allows you to mount a directory into the MAGE server container from a
227-
[FUSE-based](https://github.com/libfuse/libfuse) file system, which might
228-
provide extra functionality like [encryption](https://www.veracrypt.fr) or
229-
[remote mounting](https://github.com/libfuse/sshfs) transparently to the
230-
Docker container and MAGE application. If you don't have any requirements of
231-
that sort, you can modify the Compose file to use [Docker-managed volumes](https://docs.docker.com/storage/volumes/) instead of bind mounts.
232-
233-
### Ports
234-
The only port the Compose file exposes to the host by default is 4242 on the
235-
`mage-server` service to allow HTTP connections from your host web browser to
236-
the MAGE server running in the Docker container. In a production environment,
237-
you could add another service in the Compose file to run an
238-
[nginx](https://hub.docker.com/_/nginx/) or [httpd](https://hub.docker.com/_/httpd/)
239-
reverse proxy with TLS or other security measures in front of the MAGE Server
240-
Node application. In that case you would remove the
241-
```yaml
242-
ports:
243-
- 4242:4242
244-
```
245-
lines from the Compose file under the `mage-server` service entry. You would
246-
then most likely add the mapping
247-
```yaml
248-
ports:
249-
- 443:443
250-
```
251-
to the reverse proxy's service definition.
252-
253-
You can also allow connections from your host to the MongoDB database container
254-
by uncommenting the `ports` block of the `mage-db` service. You would then be
255-
able to connect directly to the MongoDB database using the `mongo` client on
256-
your host machine to examine or modify the database contents.
257-
258-
### Environment settings
259-
260-
You can configure the MAGE server Docker app using [environment variables](../README.md#mage-environment-settings).
261-
The Compose file does this by necessity to configure the MongoDB URL for the MAGE server.
262-
```yaml
263-
environment:
264-
MAGE_MONGO_URL: mongodb://mage-db:27017/magedb
265-
```
266162

docker/server/Dockerfile.arcgis

Lines changed: 0 additions & 18 deletions
This file was deleted.

instance/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"scripts": {
66
"start": "npm run start:dev-env",
77
"start:dev": "NODE_PATH=./node_modules node ./node_modules/.bin/mage.service -C config.js",
8-
"start:dev-env": "NODE_PATH=./node_modules node ./node_modules/.bin/mage.service",
9-
"postinstall": "node ./init.js"
8+
"postinstall": "node ./init.js",
9+
"start:dev-env": "NODE_PATH=./node_modules node ./node_modules/.bin/mage.service"
10+
1011
},
1112
"repository": {
1213
"type": "git",

0 commit comments

Comments
 (0)