- clone the repo
git clone https://github.com/geneontology/go-fastapi
- install requirements into a virtual environment
poetry install
- start the API server
make start
- run the tests
make test
Note: tests will run with or without a functioning server locally.
- build the docker image
docker build -t geneontology/go-fastapi .
- run the docker image
-d
tells docker to run the image in the background (the image includes a command to start the API), so this
will run the image and start the API server but give the control of the terminal back to the local user.
-p
tells docker to map the container port 8080 to the host port 8080. This way the user can access the API docker
version of the running API from their local browser via: http://127.0.0.1:8080/docs
docker run -d -p 8080:8080 geneontology/go-fastapi
To remove images and containers:
docker rm -vf $(docker ps -aq)
(removes all local images)
docker rmi -f $(docker images -aq)
(removes all local containers)
Check the port mapping:
docker port go-fastapi
(see the port mapping)
- checkout and build the API code locally
This should result in a locally running API server on port 8081 (note the port difference from the docker version)
git clone https://github.com/geneontology/go-fastapi
cd go-fastapi
make dev
localhost:8081/docs will be available for testing the API locally if the commands above are successful.
- make a change to the API code
- test the API changes
make test
- rebuild the docker image with the changed code
docker build -t geneontology/go-fastapi .
- test the rebuilt docker image
docker run -i -t --name geneontology/go-fastapi -p 8080:8080 geneontology/go-fastapi bash
make start
make test
GitHub Actions will automatically build and push the docker image to Dockerhub when a new versioned tag is created. To do this manually, run the following commands, replacing [tag_name] with the tag or version number:
docker login
docker build -t geneontology/go-fastapi .
docker tag geneontology/go-fastapi:latest geneontology/go-fastapi:[tag_name]
docker push geneontology/go-fastapi:[tag_name]