This project illustrates using API Logic Server with Docker and docker-compose. The objective is to provide a simple way to explore using docker with API Logic Server on your local machine. These are not production procedures - they are designed for simple local machine operation.
The git project is an uncustomized API Logic Project created from the postgres Northwind database image. This database is provided in a docker container:
docker run -d --name postgresql-container --net dev-network -p 5432:5432 -e PGDATA=/pgdata -e POSTGRES_PASSWORD=p apilogicserver/postgres:latest
This doc explains:
-
I. Running the git project as an image - acquire pre-created project from git, and run
-
II. Running the git project as a docker-compose - build, deploy and run
-
III. Recreating the project - how to rebuild the project from scratch
-
IV. Status, Open Issues (eg, not working on windows)
We presume you have Python, pip installed
ApiLogicServer (version >= 09.01.25 - preview here), and docker.
Stop the docker-compose container, if it is running.
Install the current (or preview). Use the ApiLogicServer
command to verify the version note above.
The image contains not only Postgres, but also the Northwind
and authdb
databases.
docker run -d --name postgresql-container --net dev-network -p 5432:5432 -e PGDATA=/pgdata -e POSTGRES_PASSWORD=p apilogicserver/postgres:latest
Follow this procedure to obtain the pre-created project from git.
# git clone https://github.com/ApiLogicServer/docker-compose-nw-postgres.git
# cd docker-compose-nw-postgres
Verify proper installation:
-
Open the project in VSCode
-
Establish your (possibly preview) virtual environment
-
Press F5 to run the server
-
Run the Admin App, and Swagger
The git project does not store these files, so you must obtain them:
pushd devops/docker-compose
sh install-webapp.sh
popd
For preview versions, verify
devops/docker-image/build_image.dockerfile
is usingapilogicserver/api_logic_server_x
(note the _x).
cd <project>
sh devops/docker-image/build_image.sh .
First, if you haven't already done so, start the database:
docker run -d --name postgresql-container --net dev-network -p 5432:5432 -e PGDATA=/pgdata -e POSTGRES_PASSWORD=p apilogicserver/postgres:latest
When run from a container, the database uri using localhost
(from ApiLogicServer create) does not work. Observe the devops/docker-image/env.list
:
APILOGICPROJECT_SQLALCHEMY_DATABASE_URI=postgresql://postgres:p@postgresql-container/postgres
APILOGICPROJECT_SQLALCHEMY_DATABASE_URI_AUTHENTICATION=postgresql://postgres:p@postgresql-container/authdb
Use the pre-created command line script:
sh devops/docker-image/run_image.sh
Run the Admin App, and Swagger.
You can also run the Authentication Administration App to define users and roles (though not required).
The procedure below will spin up another database container.
Ensure you are not already running the API Logic Server postgres database in a docker container. If it's running, you will see port conflicts.
The following will build, deploy and start the container stack locally:
# cd ./devops/docker-compose/
# sh docker-compose.sh # windows: .\docker-compose.ps
Then, in your browser, open localhost
.
If that fails (e.g., windows), enter your port into devops/docker-image/docker-compose.yml
.
Then, use the following to build, deploy and start the default container stack locally:
# cd postgres-docker-compose # <project-root>
# docker-compose -f ./devops/docker-compose/docker-compose.yml up
Then, in your browser, open localhost
.
The postgres database contains authdb
. To activate security, update devops/docker-compose/docker-compose.yml
:
-
Set
- SECURITY_ENABLED=true
-
Under api-logic-server-environment, observe:
- APILOGICPROJECT_SQLALCHEMY_DATABASE_URI_AUTHENTICATION=postgresql://postgres:p@nw_postgres/authdb
After verifying project operation using the instructions above, you may wish to re-create the project from scratch.
Re-create this project as follows:
Stop the docker-compose container, if it is running.
docker run -d --name postgresql-container --net dev-network -p 5432:5432 -e PGDATA=/pgdata -e POSTGRES_PASSWORD=p apilogicserver/postgres:latest
Verify it looks like this:
Create the project with API Logic Server in the directory indicted below, as a sibling of this project obtained from github:
cd <parent folder to this project>
ApiLogicServer create --project_name=rebuild-docker-compose-nw-postgres --db_url=postgresql://postgres:p@localhost/postgres
The project should be ready to run without customization:
-
Open the project in VSCode
-
Establish your (possibly preview) virtual environment
-
Press F5 to run the server
-
Run the Admin App, and Swagger
Stop the server.
Using the terminal window inside VSCode:
ApiLogicServer add-auth --project_name=. --db_url=postgresql://postgres:p@localhost/authdb
Re-run the project (F5), observe you need to login. Observe further that u1 does not work - you need to use admin.
The git project does not store these files, so you must obtain them:
pushd devops/docker-compose
sh install-webapp.sh
popd
You have now recreated the git project. You should be able to execute the instructions at the top of this page.
This procedure has been validated on several computers, in all aspects described above.
As noted above, this project is provided to explore docker / API Logic Server in a simple, local environment. Production considerations:
- Instead of building the app image, you might prefer to built it separately and use that in the docker-compose, e.g.
services:
api_logic_project:
container_name: apilogicserver/docker-compose-nw
network_mode: dev-network
env_file:
- 'env.list'
- Database data is in the image to simplify installs. You would typically use volumes for data in production.
We are investigating the following improvements (comments requested):
The server builds, starts, and connects to the database. The web app, however, fails to start in the browser.
This is now obtained through an install step. Please report issues / reactions.