Skip to content

Commit

Permalink
Push OMMX Artifact in Python (#52)
Browse files Browse the repository at this point in the history
- New APIs
  - `Artifact.image_name` property
  - `Artifact.push` method
- Documentations update
- New notebook for handling OMMX Artifact
  • Loading branch information
termoshtt authored Jun 6, 2024
1 parent 033f6c1 commit 6f5823a
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ jobs:
- name: Run notebooks
run: |
jupyter nbconvert --to notebook --execute notebooks/*.ipynb
env:
OMMX_BASIC_AUTH_DOMAIN: ghcr.io
OMMX_BASIC_AUTH_USERNAME: ${{ github.actor }}
OMMX_BASIC_AUTH_PASSWORD: ${{ github.token }}
66 changes: 42 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ proptest = "1.4.0"
prost = "0.12.6"
prost-build = "0.12.6"
pyo3 = { version = "0.21.2", features = ["anyhow"] }
pyo3-log = "0.10.0"
rand = "0.8.5"
rand_xoshiro = "0.6.0"
serde = { version = "1.0.197", features = ["derive"] }
Expand Down
155 changes: 155 additions & 0 deletions notebooks/artifact.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ec41c28b-5d3f-4e6c-a76a-bae41a57186f",
"metadata": {},
"source": [
"# Create OMMX Artifact"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f8fe903b-8acd-40dc-9263-7c5f9197876d",
"metadata": {},
"outputs": [],
"source": [
"import uuid # To generate random tag for testing\n",
"import logging # To see the log of pushing artifact\n",
"logging.basicConfig(level=logging.INFO)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "57b9e174-2c4c-444a-9ea7-d0ab6f112162",
"metadata": {},
"outputs": [],
"source": [
"from ommx.artifact import Artifact, ArtifactBuilder\n",
"from ommx.testing import SingleFeasibleLPGenerator, DataType"
]
},
{
"cell_type": "markdown",
"id": "a2779a4a-4f76-4c77-a2e2-c64d5a4c2aff",
"metadata": {},
"source": [
"## Ready `ommx.v1.Instance` to be packed into artifact"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4be947b0-95c5-477b-8c7e-d2501c03a2d8",
"metadata": {},
"outputs": [],
"source": [
"generator = SingleFeasibleLPGenerator(3, DataType.INT)\n",
"instance = generator.get_v1_instance()"
]
},
{
"cell_type": "markdown",
"id": "cb3adc3e-483d-4c4a-96fc-23888a43e1f1",
"metadata": {},
"source": [
"## Build OMMX artifact"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "00061527-a0ee-4b78-8727-8472c27cac7e",
"metadata": {},
"outputs": [],
"source": [
"builder = ArtifactBuilder.for_github(\n",
" \"Jij-Inc\", # GitHub organization\n",
" \"ommx\", # Repository name\n",
" \"single_feasible_lp\", # Name of artifact\n",
" str(uuid.uuid4()) # Tag of artifact\n",
")\n",
"builder.add_instance(instance)\n",
"artifact = builder.build()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5374f4f4-1d6f-44b4-83f2-8056f349a36c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'ghcr.io/jij-inc/ommx/single_feasible_lp:4c09b065-a55c-4358-8083-9ce3db3b6e6c'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"artifact.image_name"
]
},
{
"cell_type": "markdown",
"id": "a04b993d-d13c-4fba-83fc-677da7d6543d",
"metadata": {},
"source": [
"## Push artifact to container registry\n",
"\n",
"- This artifact will be pushed to <https://github.com/Jij-Inc/ommx/pkgs/container/ommx%2Fsingle_feasible_lp>\n",
"- `push` requires authentication using personal access token (PAT) or `GITHUB_TOKEN` on GitHub Actions."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a06ef2f5-595f-485a-9ca9-11923278123b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:ommx.artifact:Pushing: ghcr.io/jij-inc/ommx/single_feasible_lp:4c09b065-a55c-4358-8083-9ce3db3b6e6c\n",
"INFO:ocipkg.distribution.client:POST https://ghcr.io/v2/jij-inc/ommx/single_feasible_lp/blobs/uploads/\n",
"INFO:ocipkg.distribution.client:PUT https://ghcr.io/v2/jij-inc/ommx/single_feasible_lp/blobs/upload/ebb244fb-38e4-4472-b460-932b43569344\n",
"INFO:ocipkg.distribution.client:POST https://ghcr.io/v2/jij-inc/ommx/single_feasible_lp/blobs/uploads/\n",
"INFO:ocipkg.distribution.client:PUT https://ghcr.io/v2/jij-inc/ommx/single_feasible_lp/blobs/upload/09b62410-7376-4cbe-bfc2-aaac66736b43\n",
"INFO:ocipkg.distribution.client:PUT https://ghcr.io/v2/jij-inc/ommx/single_feasible_lp/manifests/4c09b065-a55c-4358-8083-9ce3db3b6e6c\n"
]
}
],
"source": [
"artifact.push()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 6f5823a

Please sign in to comment.