Deployment

The project has eight files, two of which are built, and one service to run. That is a container: an image that installs the compiler and Python, builds and tests the core during the build so a broken core fails the build and not the deployment, and starts the service as its command.

The image

The base is the same distribution this container runs, because that is where the versions on every page of this project were measured. The compiler package is gnucobol, which is what owns /usr/bin/cobc in this image as well:

apk info -W /usr/bin/cobc

/usr/bin/cobc is owned by gnucobol-3.2-r0

The Dockerfile

FROM alpine:3.24 RUN apk add --no-cache gnucobol python3 WORKDIR /app COPY priceif.cpy price.cob coretest.cob ./ COPY server.py test_service.py ./ RUN cobc -x -free -Wall -O2 -o coretest coretest.cob \ && ./coretest \ && cobc -x -free -Wall -O2 -o price price.cob \ && cobc -m -free -Wall -O2 -o PRICECORE.so price.cob ENV PRICE_HOST=0.0.0.0 EXPOSE 8765 HEALTHCHECK --interval=30s --timeout=3s \ CMD wget -qO- http://127.0.0.1:8765/health || exit 1 CMD ["python3", "-I", "server.py", "8765"]

Five decisions in that file are worth naming. The build compiles the test driver first and runs it before it builds anything else, so an image is never produced from a core that fails its own five cases. The same source is then built twice, once as the executable the service runs and once as the module the ctypes path needs, which costs a second and keeps both ways in the image. ENV PRICE_HOST=0.0.0.0 makes the service bind every interface, because a service bound to 127.0.0.1 inside a container answers its own health check and nothing through a published port. The HEALTHCHECK calls /health, so the orchestrator can tell a service with no core from a service that is down. And the command runs Python with -I, so the service does not pick up a module from the working directory by accident.

Run on the host in Docker

The image was built on the host with Docker, from the files assembled from these pages, and the build step printed the five cases of the driver as it went:

pass case 1
pass case 2
pass case 3
pass case 4
pass case 5
passed 005 failed 000

The image built, and docker inspect reported the health check healthy about thirty seconds after the container started. Two calls inside that container, the same two the service page makes against a local process:

GET /health -> {"status": "ok", "core": "./price", "core_exists": true}
POST /price, C00001WIDGET0100002000123456N1 -> C00001000000024691200000032099PRICED

And the log of the same container, which is the log of the local run with the same two lines:

listening on 127.0.0.1:8765, core ./price
"GET /health HTTP/1.1" 200 -
"POST /price HTTP/1.1" 200 -

That log line is the reason this page changed: it is the container of the first build, whose service still bound 127.0.0.1. The ENV PRICE_HOST=0.0.0.0 above is the fix: with that variable set, the service printed listening on 0.0.0.0:8802 in this container and answered on both the container address and the loopback, and the image built from the corrected Dockerfile printed the same line for port 8765, which the next section shows.

Through a published port

The same image was then started with the container port 8765 published as 18765 on the host, and the calls were made from the host, which is the path the first build failed. The run, in the order it happened:

docker build -t price-service .
docker run -d --name cpc -p 18765:8765 price-service
curl -s http://127.0.0.1:18765/health

{"status": "ok", "core": "./price", "core_exists": true}

A real order through the same published port, with curl printing the HTTP status after the body:

printf 'C00001WIDGET0100002000123456N1' | curl -s -w '\n%{http_code}\n' \
    --data-binary @- http://127.0.0.1:18765/price

C00001000000024691200000032099PRICED              

200

The body is the fifty-byte answer, so the message is followed by its padding to twenty characters; the empty line before the 200 is curl\'s \n and not part of the record. And the log of the container, which now shows the bind address the published port needs and the host address the request came from:

listening on 0.0.0.0:8765, core ./price
172.17.0.1 "GET /health HTTP/1.1" 200 -

The 172.17.0.1 is the host as the container sees it through the published port, and the 200 is the health check answered through that port. The order\'s line is not quoted here because the host quoted one log line; what the host did quote is the call above, and its answer and its 200. That is the whole deployment path working: build, run with a published port, call from outside.

The steps a deploy would take

docker build -t price-service . docker run --rm -p 8765:8765 price-service curl -s http://127.0.0.1:8765/health printf 'C00001WIDGET0100002000123456N1' | curl -s -X POST --data-binary @- \     http://127.0.0.1:8765/price

The third and fourth lines are the ones a deployment check and a smoke test run, through the published port. They are the commands of the service page with the port mapped instead of a local process, and the two sections above are their answers from the host run.

The last page of the group is what a production version should change, starting from what these runs measured.

Everything on this page ran: the project and its tests in this container with cobc (GnuCOBOL) 3.2.0 and Python 3.14.10 on Alpine Linux 3.24.3 (x86_64) with nproc 4, and the image on the host in Docker, built, run with a published port and called from the host, on the same Alpine base and the same gnucobol package.

Article author: Arthur Isaev

Banner image