Deploy - USEPA/USEEIO_API GitHub Wiki
Deploying the Go version locally
Once built, you can deploy the run the Go application is just a single executable file. The folder with the data files, the server port, and the location of the static files (HTML, JavaScript, CSS) of the application can be specified via command line arguments:
From the Windows command line
On Windows, open a command line, browse to the build
directory and type:
app -data <folder with data files> -static <folder with static files> -port <server port>
All arguments are optional and the defaults are the same like starting the application in the following way:
app -data data -static static -port 5000
To stop the server on Windows, use CTRL+C
.
Deploying the Python version locally
From Windows command line
On Windows, open a command line, browse to the python directory and type:
>python -m useeioapi -data path\to\data\files -static ..\build\static -port 8080
To stop the server on Windows, use CTRL+C
.
From Pycharm
Mark the python
directory as sources root.
Run __main__.py
under python/useeioapi
This will by default run the server on port 8080 with data files from build\data
folder
To stop the server, hit the 'Stop' button.
Prerequisites
- Python 3x
- numpy >= 1.17
- requests >= 2.20
- flask >= 1.1 Once python is installed and pip is available from the command line, the other requirements can be installed like:
>pip install numpy
>pip install requests
>pip install flask
At this time, the Python version has only been tested with local deployment, and does not include hosting the documentation.
Deploying the Go version to a Cloud Foundry instance (like cloud.gov)
The go version can be deployed in a Cloud Foundry
instance using the binary build pack.
The script cfdist.bat
compiles the back-end for Linux and packages all the
resources into the folder cfdist
that can be then deployed using the
Cloud Foundry Command Line Interface.
The cfdist.bat
script expects that the build
folder exists and that
you put the data that should be deployed with the server into the folder
build/data
, otherwise it will exit with an error message. You should
then be able to run the script. You probably need to change the meta-data in the
cfdist/manifest.yaml
file before deploying the application but in general the
workflow should look like this:
cfdist.bat
cd cfdist
# change meta-data in manifest.yaml
cf login -a api.run.pivotal.io # login
# deploy the application as binary package:
cf push -b https://github.com/cloudfoundry/binary-buildpack.git
Deploying the Go version as a Docker image
The repository contains a simple Dockerfile
which can be used to build a Docker image:
FROM scratch
COPY useeio_api /opt/useeio_api
WORKDIR /opt/useeio_api
EXPOSE 8080
CMD [ "./app", "-port", "8080"]
It expects that the API binary of the Go version is saved in a file app
that is located in a folder useeio_api
next to the folders data
and static
that contain the API data and the static pages that should be hosted together with the API:
- useeio_api/
+-- data/
+-- static/
- app
- Dockerfile
In this folder, you can then run the docker build
command to build the image, e.g.:
docker build -t useeio_api .
This will store the image under useeio_api
and you should be able to run it via the following command (-p 8080:8080
maps the port 8080
of the docker container to the port 8080
of the host system):
docker run -p 8080:8080 useeio_api
To export the image as tar file, run
docker save -o export.file.name.tar