A microservice for consents metadata
All DyCons software is archived and deprecated, left for reference only.
See dycons/design
for additional context on this repository.
Strongly modeled on the Go model service built for CanDIG in Summer 2018 and upgraded in Summer 2020. The stacks are nearly identical and the implementations are very similar. If you are interested in contributing to this toy service, or in building something similar, you may benefit from taking a look at the Go model service and its documentation.
- Install Docker v18.06.0+ and Docker Compose v3.7+. You can check which version, if any, is already installed by running
docker --version
anddocker-compose --version
. Any versions greater than or equal to the ones stated here should do. - Checkout this go-model-service repository:
git checkout https://github.com/dycons/consents.git
cd consents
- Set up the build environment by generating a
.env
file for Docker Compose to use:
cp default.env .env
- From the project root directory, run the test server. It is presently configured to run on port
0.0.0.0:3000
. If you prefer to run the development container, replacetest
withdev
in all following instructions.
docker-compose -f docker/docker-compose.test.yml up
- In a new shell (or the same shell if
docker-compose up --detach
was run), run the migrations script to prepare the database for use. Run it with the-t
flag for thetest
instance and the-d
flag for thedev
instance.
./docker/migrate.sh -t
- Send a request to the consents-service from Postman (import
./tests/consents-service.postman_collection.json
to run the collection against the./tests/postman-data.csv
data file). Alternately,curl
a request from the command line.
- Docker is used for containerizing the service and its dependencies.
- PostgreSQL database backend
- Go (Golang) backend
- Go mod is used for dependency management, similarly to how
dep
was used in the past. - Swagger/OpenAPI 2.0 is used to specify the API.
- Postman and the CLI runner Newman are used for end-to-end API testing.
- TravisCI is used for continuous integration, testing both the service build and, in conjunction with Newman, the API.
- Go-swagger auto-generates boilerplate Go code from a
swagger.yml
API definition. Swagger tooling is based on the OpenAPI specification. - Gobuffalo pop is used as an orm-like for interfacing between the go code and the sqlite3 database. The
soda
CLI auto-generates boilerplate Go code for models and migrations, as well as performing migrations on the database.fizz
files are used for defining database migrations in a Go-like syntax (see syntax documentation.) - Gobuffalo validate is a framework used for writing custom validators. Some of their validators in the
validators
package are used as-is.
The consents-app
image built from docker/test.Dockerfile
depends upon the consents-deps
image built from docker/deps.Dockerfile
, the image containing most of the stack and package dependencies for the app. These images have been split so that the consents-app
build can be tested by TravisCI following every git push without time spent building the dependencies.
The stack and project dependencies image consents-deps
can be pulled from dyconsent/consents-deps
. Alternately, it can be built and run locally with the following commands:
docker build -t <username>/consents-deps -f ./docker/deps.Dockerfile
docker run -it --rm <username>/consents-deps
If you would like to push your altered image of consents-deps
, consider using the ./docker/push-image.sh
script provided to quickly semantically version the image. Run ./docker/push-image.sh -h
for usage instructions.
docker login && ./docker/push-image.sh -f ./docker/deps.Dockerfile -u <username> consents-deps <patch>
For containerized installation instructions, please see the Quick Start.
If you are interested in attempting a non-containerized installation, the following files contain build instructions for Docker, Docker Compose, and Travis CI. They may equally be followed manually to accomplish a manual installation of the stack and service:
docker/deps.Dockerfile
for the installation of the stack and of most other project dependenciesdocker/test.Dockerfile
for the installation of the app, along withdocker/docker-compose.test.yml
anddefault.env
for the configuration of the service, database, and build-time environmenttravis.yml
for running the service and its associated end-to-end API tests
From the project root directory, run the server. It is presently configured to run on port 0.0.0.0:3000
.
docker-compose -f docker/docker-compose.test.yml up
If you have Postman installed, the quickest way to test the go-model-service API is to import ./tests/consents-service.postman_collection.json
and run the collection against the ./tests/postman-data.csv
data file.
Note that most auto-generated code, including binary files, are intentionally excluded from this repository.
If you would like to learn more about using this stack, especially with regards to its code-generation components, please take a look at the Go Model Service DEVELOPER-GUIDE.md.