Skip to content

Commit

Permalink
Merge pull request #345 from internetofwater/docker-adjustments
Browse files Browse the repository at this point in the history
Improve docker build and test setup
  • Loading branch information
Ethan Grahn authored Oct 31, 2022
2 parents d39f2c5 + 4520246 commit 22c5e13
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 29 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/internetofwater/nldi-services/compare/1.12.4...master)
## [Unreleased](https://github.com/internetofwater/nldi-services/compare/1.12.5...master)
### Changed
* Switched to using actively maintained Docker images
* Simplified docker compose workflow

## [1.12.5](https://github.com/internetofwater/nldi-services/compare/1.12.4...1.12.5)
### Fixed
* Feature ID validation no longer fails in comid is null

### Changed
* Updated dependencies

## [1.12.4](https://github.com/internetofwater/nldi-services/compare/1.12.3...1.12.4)
### Fixed
* Proper CORS header is included in response
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM artifactory.wma.chs.usgs.gov/docker-official-mirror/maven:3.6.0-jdk-11 AS build
ARG DOCKER_MIRROR
FROM ${DOCKER_MIRROR}maven:3.8.1-jdk-11-slim AS build
LABEL maintainer="[email protected]"

# Add pom.xml and install dependencies
Expand All @@ -10,7 +11,7 @@ RUN mvn -B dependency:go-offline
COPY src /build/src
RUN mvn -B clean package -Dmaven.test.skip=true

FROM artifactory.wma.chs.usgs.gov/docker-official-mirror/usgswma/openjdk:debian-stretch-openjdk-11.0.2-89c4dd2d55ba476c77aa8fd5274dcb8a1ef115b7
FROM ${DOCKER_MIRROR}openjdk:11.0-jre-slim

COPY --chown=1000:1000 --from=build /build/target/nldi-services-*.jar app.jar

Expand All @@ -19,4 +20,5 @@ USER $USER
CMD ["java", "-jar", "app.jar"]

HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -H "Accept: application/json" -v -k "http://127.0.0.1:${SERVER_PORT}${SERVER_CONTEXT_PATH}/about/health" | grep -q "{\"status\":\"UP\"}" || exit 1
CMD curl -H "Accept: application/json" -v -k \
"http://127.0.0.1:${SERVER_PORT}${SERVER_CONTEXT_PATH}/about/health" | grep -q "{\"status\":\"UP\"}" || exit 1
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

This repository houses code behind the Network Linked Data Index (NLDI) API [(Swagger Docs)](https://labs.waterdata.usgs.gov/api/nldi/swagger-ui/index.html). The NLDI is hosted as part of the [USGS Waterdata Labs](https://labs.waterdata.usgs.gov/index.html), a set of new capabilities being developed by the USGS Water Mission Area.

## Table of Contents
* [Public API](#public-api)
* [The root is {host}/api/nldi](#the-root-is-hostapinldi)
* [Up/Down Stream navigation](#updown-stream-navigation)
* [Up/Down Stream data](#updown-stream-data)
* [Query Parameters](#query-parameters)
* [Other Endpoints](#other-endpoints)
* [Development](#development)
* [Dependencies](#dependencies)
* [Docker Compose](#docker-compose)
* [Environment variables](#environment-variables)
* [Testing](#testing)

## Public API
The services are accessed via an http GET request. All output is generated as JSON and GeoJSON.

Expand Down Expand Up @@ -56,13 +69,23 @@ Rather, start up the demo db and create an application.yml file as described bel
This application utilizes a PostgreSQL database.
[nldi-db](https://github.com/internetofwater/nldi-db) contains everything you need to set up a development database environment. It includes data for the Yahara River in Wisconsin.

### Running the Demo DB for local development
See the nldi-db project for more details, but in short:
```shell
docker network create --subnet=172.26.0.0/16 nldi
docker run -it --env-file ./.env -p 127.0.0.1:5437:5432/tcp ghcr.io/internetofwater/nldi-db:demo
### Docker Compose
This project includes a Docker-Compose file with all necessary variables predefined.
First, start the demo database by running:

```sh
docker-compose up -d nldi-db
```
Note the _5437_ port mapping, which is used in the environmental variables below.

Then, build and start the NLDI services by running:

```sh
docker-compose up nldi-services
```

These test services will be accessible at <localhost:8080/nldi>. \
If you would like to build these images using a mirror url simply set a `DOCKER_MIRROR` environment variable or include
it as a build argument.

### Environment variables
To run the project (connecting to a separately running db instance) you will need to create the file application.yml in the project's root directory and add the following (normal defaults are filled in):
Expand Down
8 changes: 0 additions & 8 deletions config.env

This file was deleted.

47 changes: 41 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,46 @@

services:
nldi-services:
build: .
image: nldi-services
container_name: nldi-services
build:
context: .
args:
DOCKER_MIRROR: ${DOCKER_MIRROR}
ports:
- "8082:8080"

env_file:
- config.env
- secrets.env
- "8080:8080"
environment:
serverContextPath: /nldi
serverPort: 8080
nldiProtocol: http
nldiHost: "localhost:8080"
nldiPath: /nldi
springFrameworkLogLevel: info
nldiDbHost: nldi-db
nldiDbPort: 5432
nldiDbUsername: read_only_user
nldiDbPassword: changeMe
nldiDbName: nldi
pygeoapiUrl: "https://labs.waterdata.usgs.gov/api/nldi/pygeoapi/"
networks:
- nldi
nldi-db:
image: ghcr.io/internetofwater/nldi-db:demo
container_name: nldi-db-demo
environment:
POSTGRES_PASSWORD: changeMe
NLDI_DATABASE_ADDRESS: localhost
NLDI_DATABASE_NAME: nldi
NLDI_DB_OWNER_USERNAME: nldi
NLDI_DB_OWNER_PASSWORD: changeMe
NLDI_SCHEMA_OWNER_USERNAME: nldi_schema_owner
NLDI_SCHEMA_OWNER_PASSWORD: changeMe
NHDPLUS_SCHEMA_OWNER_USERNAME: nhdplus
NLDI_READ_ONLY_USERNAME: read_only_user
NLDI_READ_ONLY_PASSWORD: changeMe
DB_DEMO_PORT: 5432
networks:
- nldi

networks:
nldi:
5 changes: 0 additions & 5 deletions secrets.env.sample

This file was deleted.

0 comments on commit 22c5e13

Please sign in to comment.