Skip to content

Commit c97b41a

Browse files
0.57.0 Release (#131)
* Implement Fast API optional component (#117) * added Fast API optional component Signed-off-by: Dixon Whitmire <[email protected]> * updating version number Signed-off-by: Dixon Whitmire <[email protected]> * updating CI to test on Python 3.9 and 3.10 (#118) Signed-off-by: Dixon Whitmire <[email protected]> * X12 Image Build (#121) * adding Dockerfile for image build Signed-off-by: Dixon Whitmire <[email protected]> * updating GitHub workflows Signed-off-by: Dixon Whitmire <[email protected]> * updating image ci to use build-args Signed-off-by: Dixon Whitmire <[email protected]> * configuring PR based image CI to build a single image to reduce wait times Signed-off-by: Dixon Whitmire <[email protected]> * updating image build ci Signed-off-by: Dixon Whitmire <[email protected]> * removing Dockerfile path condition since it's not working Signed-off-by: Dixon Whitmire <[email protected]> * Updated container support documentation (#127) Signed-off-by: Dixon Whitmire <[email protected]> * update /x12 [POST] endpoint segment mode to return an equivalent response as the CLI in segment mode (#129) Signed-off-by: Dixon Whitmire <[email protected]> * adding script to build and push multi-platform images (#130) Signed-off-by: Dixon Whitmire <[email protected]> * removing tag version from GitHub actions Signed-off-by: Dixon Whitmire <[email protected]>
1 parent 3734589 commit c97b41a

File tree

13 files changed

+421
-7
lines changed

13 files changed

+421
-7
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.github
2+
.idea
3+
.vscode
4+
**/.pytest_cache
5+
**/linuxforhealth_x12.egg-info
6+
demo-file
7+
repo-docs
8+
**/tests
9+
venv
10+
.gitignore
11+
LICENSE

.github/workflows/continuous-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: [3.8, 3.9]
15+
python-version: ["3.9.13", "3.10.5"]
1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Set up Python ${{ matrix.python-version }}
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip setuptools
25-
pip install -e .[dev]
25+
pip install -e .[dev,api]
2626
- name: Validate Formatting
2727
run: |
2828
black -t py38 --check --diff ./src
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test X12 Image Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-image:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out the repo
14+
uses: actions/checkout@v3
15+
- name: QEMU setup
16+
uses: docker/setup-qemu-action@v2
17+
- name: Docker buildx setup
18+
uses: docker/setup-buildx-action@v2
19+
- name: Build and push Docker image
20+
uses: docker/build-push-action@v3
21+
with:
22+
context: .
23+
build-args: |
24+
X12_SEM_VER=0.57.0
25+
platforms: linux/amd64
26+
push: false
27+
tags: ci-testing

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Builds the LinuxForHealth X12 API container using a multi-stage build
2+
3+
# build stage
4+
FROM python:3.10-slim-buster AS builder
5+
6+
# the full semantic version number, used to match to the generated wheel file in dist/
7+
ARG X12_SEM_VER
8+
9+
# OS library updates and build tooling
10+
RUN apt-get update
11+
RUN apt-get install -y --no-install-recommends \
12+
build-essential \
13+
gcc
14+
15+
# copy source and build files
16+
WORKDIR /tmp/lfh-x12
17+
COPY setup.cfg .
18+
COPY pyproject.toml .
19+
COPY ../src src/
20+
21+
# build the service
22+
RUN python -m venv /tmp/lfh-x12/venv
23+
ENV PATH="/tmp/lfh-x12/venv/bin:$PATH"
24+
RUN python -m pip install --upgrade pip setuptools wheel build
25+
RUN python -m build
26+
RUN python -m pip install dist/linuxforhealth_x12-"$X12_SEM_VER"-py3-none-any.whl[api]
27+
28+
# main image
29+
FROM python:3.10-slim-buster
30+
31+
# container build arguments
32+
# lfh user id and group ids
33+
ARG LFH_USER_ID=1000
34+
ARG LFH_GROUP_ID=1000
35+
36+
# create service user and group
37+
RUN groupadd -g $LFH_GROUP_ID lfh && \
38+
useradd -m -u $LFH_USER_ID -g lfh lfh
39+
USER lfh
40+
WORKDIR /home/lfh
41+
42+
# configure and execute application
43+
COPY --from=builder /tmp/lfh-x12/venv ./venv
44+
# set venv executables first in path
45+
ENV PATH="/home/lfh/venv/bin:$PATH"
46+
# listening address for application
47+
ENV X12_UVICORN_HOST=0.0.0.0
48+
EXPOSE 5000
49+
CMD ["python", "-m", "linuxforhealth.x12.api"]

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ git clone https://github.com/LinuxForHealth/x12
3636
cd x12
3737

3838
python3 -m venv venv && source venv/bin/activate && pip install --upgrade pip setuptools
39-
pip install -e .[dev]
39+
pip install -e .[dev, api] # installs dev packages and optional API endpoint
4040
pytest
4141
```
4242

@@ -130,6 +130,27 @@ To parse a X12 message into models with pretty printing enabled
130130
131131
In "model" mode, the `-x` option excludes `None` values from output.
132132
133+
### API
134+
LinuxForHealth X12 includes an experimental "api" setup "extra" which activates a [Fast API](https://fastapi.tiangolo.com/)
135+
endpoint used to submit X12 payloads.
136+
137+
```shell
138+
user@mbp x12 % source venv/bin/activate
139+
(venv) user@mbp x12 % pip install -e ".[api]"
140+
(venv) user@mbp x12 % lfhx12-api
141+
```
142+
Browse to http://localhost:5000/docs to view the Open API UI.
143+
144+
API server configurations are located in the [config module](./src/linuxforhealth/x12/config.py). The `X12ApiConfig` model
145+
is a [Pydantic Settings Model](https://pydantic-docs.helpmanual.io/usage/settings/) which can be configured using environment
146+
variables.
147+
148+
```shell
149+
user@mbp x12 % source venv/bin/activate
150+
(venv) user@mbp x12 % export X12_UVICORN_PORT=5002
151+
(venv) user@mbp x12 % lfhx12-api
152+
```
153+
133154
### Code Formatting
134155
135156
LinuxForHealth X12 adheres to the [Black Code Style and Convention](https://black.readthedocs.io/en/stable/index.html)
@@ -161,3 +182,4 @@ python3 -m build --no-isolation
161182
## Additional Resources
162183
- [Design Overview](repo-docs/DESIGN.md)
163184
- [New Transaction Support](repo-docs/NEW_TRANSACTION.md)
185+
- [Container Support](repo-docs/CONTAINER_SUPPORT.md)

demo-file/demo-single-line.270

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ISA*03*9876543210*01*9876543210*30*000000005 *30*12345 *131031*1147*^*00501*000000907*1*T*:~GS*HS*000000005*54321*20131031*1147*1*X*005010X279A1~ST*270*1234*005010X279A1~BHT*0022*13*10001234*20060501*1319~HL*1**20*1~NM1*PR*2*ABC COMPANY*****PI*842610001~HL*2*1*21*1~NM1*1P*2*BONE AND JOINT CLINIC*****SV*2000035~HL*3*2*22*0~TRN*1*93175-012547*9877281234~NM1*IL*1*SMITH*ROBERT****MI*11122333301~DMG*D8*19430519~DTP*291*D8*20060501~EQ*30~SE*13*1234~GE*1*1~IEA*1*000000907~

push-image.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
# push-image.sh
3+
# push-image.sh builds and pushes the multi-platform linuxforhealth/x12 image to an image repository.
4+
#
5+
# Pre-Requisites:
6+
# - The script environment is authenticated to the target image repository.
7+
# - The project has been built and a wheel exists in <project root>/dist.
8+
#
9+
# Usage:
10+
# ./push-image [image_tag] [image_url] [platforms]
11+
#
12+
# Positional Script arguments:
13+
# IMAGE_TAG - Aligns with the project's semantic version. Required.
14+
# IMAGE_URL - The image's URL. Defaults to ghcr.io/linuxforhealth/x12.
15+
# PLATFORMS - String containing the list of platforms. Defaults to linux/amd64,linux/arm64,linux/s390x.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
if [[ $# == 0 ]]
22+
then
23+
echo "Missing required argument IMAGE_TAG"
24+
echo "Usage: ./push-image.sh [image tag] [image url] [platforms]"
25+
exit 1;
26+
fi
27+
28+
IMAGE_TAG=$1
29+
IMAGE_URL="${2:-ghcr.io/linuxforhealth/x12}"
30+
PLATFORMS="${3:-linux/amd64,linux/arm64,linux/s390x}"
31+
32+
docker buildx build \
33+
--pull \
34+
--push \
35+
--platform "$PLATFORMS" \
36+
--build-arg X12_SEM_VER="$IMAGE_TAG" \
37+
--tag "$IMAGE_URL":"$IMAGE_TAG" \
38+
--tag "$IMAGE_URL":latest .

repo-docs/CONTAINER_SUPPORT.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# LinuxForHealth X12 Container Support
2+
3+
The LinuxForHealth X12 API component supports a containerized execution environment. This guide provides an overview of
4+
how to build and run the image.
5+
6+
## Image Build
7+
8+
### Supported Build Arguments
9+
10+
11+
| Build Argument | Description | Default Value |
12+
|----------------|------------------------------------------------|---------------|
13+
| X12_SEM_VER | The current X12 library sematic version number | None |
14+
| LFH_USER_ID | The user id used for the LFH container user | 1000 |
15+
| LFH_GROUP_ID | The group id used for the LFH container group | 1000 |
16+
17+
The `X12_SEM_VER`. This argument should align with the current `linuxforhealth.x12.__version__` attribute value and the
18+
desired image tag.
19+
20+
```shell
21+
docker build --build-arg X12_SEM_VER=0.57.0 -t x12:0.57.0 .
22+
```
23+
24+
## Run Container
25+
26+
### Supported Environment Configurations
27+
28+
| Build Argument | Description | Default Value |
29+
|------------------|-----------------------------------|---------------|
30+
| X12_UVICORN_HOST | The container's listening address | 0.0.0.0 |
31+
32+
33+
The following command launches the LinuxForHealth X12 container:
34+
```shell
35+
docker run --name lfh-x12 --rm -d -p 5000:5000 ghcr.io/linuxforhealth/x12:latest
36+
```
37+
38+
To access the Open API UI, browse to http://localhost:5000/docs
39+
40+
Finally, to stop and remove the container:
41+
```shell
42+
docker stop lfh-x12
43+
```

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ classifiers =
1515
Intended Audience :: Developers
1616

1717
[options]
18-
include_package_data = True
1918
install_requires =
2019
pydantic >= 1.9
2120
python-dotenv >= 0.19.0
@@ -32,7 +31,8 @@ where=src
3231
console_scripts =
3332
lfhx12 = linuxforhealth.x12.cli:main
3433
black = black:patched_main
34+
lfhx12-api = linuxforhealth.x12.api:run_server
3535

3636
[options.extras_require]
37-
api = fastapi; uvicorn[standard]
38-
dev = black>=21.8b0; pre-commit>=2.14.1;pytest>=6.2.5
37+
api = fastapi>=0.78.0; uvicorn[standard]>=0.17.0; requests>=2.27.0
38+
dev = black>=22.3.0; pre-commit>=2.14.1;pytest>=7.1.0

src/linuxforhealth/x12/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
load_dotenv()
99

10-
__version__ = "0.56.02"
10+
__version__ = "0.57.0"

0 commit comments

Comments
 (0)