Skip to content

Commit 7f1676e

Browse files
committed
Final: Package/Lib Functioning
1 parent f6485f5 commit 7f1676e

6 files changed

Lines changed: 166 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Publish to GHCR
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: |
24+
chmod +x push-image.sh
25+
./push-image.sh

.idea/google-java-format.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 1) Build stage: install the package into a clean image
2+
FROM python:3.9-slim AS builder
3+
4+
LABEL org.opencontainers.image.source="https://github.com/hoangsonww/SQL-Mongo-Query-Converter"
5+
LABEL org.opencontainers.image.description="sql_mongo_converter: convert SQL ↔ MongoDB queries."
6+
7+
WORKDIR /app
8+
9+
# copy only what's needed to install
10+
COPY setup.py README.md ./
11+
COPY sql_mongo_converter/ ./sql_mongo_converter/
12+
13+
# install package (and cache dependencies)
14+
RUN pip install --no-cache-dir .
15+
16+
# 2) Final runtime image
17+
FROM python:3.9-slim
18+
19+
WORKDIR /app
20+
21+
# copy installed package from builder
22+
COPY --from=builder /usr/local/lib/python3.9/site-packages/sql_mongo_converter* \
23+
/usr/local/lib/python3.9/site-packages/
24+
25+
# copy any entrypoint script if you have one, or just expose it
26+
# e.g. an entrypoint.py that calls your package
27+
# COPY entrypoint.py ./
28+
29+
# default command: show help
30+
CMD ["python", "-m", "sql_mongo_converter", "--help"]

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Makefile for sql_mongo_converter Docker image
2+
3+
# ← our GHCR namespace & repo
4+
IMAGE ?= ghcr.io/hoangsonww/sql-mongo-converter
5+
REGISTRY ?= ghcr.io
6+
USER ?= hoangsonww
7+
8+
# ← parse version="x.y.z" from setup.py (portable sed)
9+
VERSION := $(shell sed -nE "s/^[[:space:]]*version[[:space:]]*=[[:space:]]*[\"']([0-9]+\.[0-9]+\.[0-9]+)[\"'].*$$/\1/p" setup.py)
10+
11+
.PHONY: all login build push clean version
12+
13+
all: login build push
14+
15+
version:
16+
@echo $(VERSION)
17+
18+
login:
19+
@# ensure we have a token
20+
@test -n "$(GITHUB_TOKEN)" || (echo "Error: GITHUB_TOKEN not set" && exit 1)
21+
@echo "🔑 Logging into $(REGISTRY) as $(USER)"
22+
@echo "$(GITHUB_TOKEN)" | docker login $(REGISTRY) -u $(USER) --password-stdin
23+
24+
build:
25+
@echo "🔨 Building Docker image $(IMAGE):$(VERSION)"
26+
@docker build --pull -t $(IMAGE):$(VERSION) -t $(IMAGE):latest .
27+
28+
push:
29+
@echo "🚀 Pushing $(IMAGE):$(VERSION) and $(IMAGE):latest"
30+
@docker push $(IMAGE):$(VERSION)
31+
@docker push $(IMAGE):latest
32+
33+
clean:
34+
@echo "🗑 Removing images"
35+
-@docker rmi $(IMAGE):$(VERSION) $(IMAGE):latest || true

build.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
# build.sh — clean + test + build your Python package
3+
4+
set -euo pipefail
5+
6+
# 1. Clean up old builds
7+
echo "🧹 Cleaning up previous builds…"
8+
rm -rf build/ dist/ *.egg-info/
9+
10+
# 2. Run your test suite (if you have one)
11+
if command -v pytest &> /dev/null; then
12+
echo "🧪 Running tests…"
13+
pytest
14+
else
15+
echo "⚠️ pytest not found — skipping tests"
16+
fi
17+
18+
# 3. Ensure build tools are installed
19+
echo "📦 Ensuring latest build tools…"
20+
python3 -m pip install --upgrade build wheel twine
21+
22+
# 4. Build source & wheel
23+
echo "🚧 Building source and wheel distributions…"
24+
python3 -m build
25+
26+
# 5. Verify the distributions
27+
echo "🔍 Checking distribution integrity…"
28+
python3 -m twine check dist/*
29+
30+
echo "✅ Build complete — artifacts in dist/"

push-image.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
GH_USER="hoangsonww"
5+
IMAGE="ghcr.io/${GH_USER}/sql-mongo-converter"
6+
7+
# 1) extract version from setup.py (portable)
8+
# works on both macOS and Linux
9+
VERSION=$(sed -nE "s/^[[:space:]]*version[[:space:]]*=[[:space:]]*['\"]([0-9]+\.[0-9]+\.[0-9]+)['\"].*/\1/p" setup.py)
10+
11+
if [ -z "${VERSION}" ]; then
12+
echo "❌ Could not parse version from setup.py"
13+
exit 1
14+
fi
15+
16+
echo "ℹ️ Building and pushing version ${VERSION}"
17+
18+
# 2) require GITHUB_TOKEN
19+
if [ -z "${GITHUB_TOKEN:-}" ]; then
20+
echo "❌ Please export GITHUB_TOKEN (with write:packages scope)."
21+
exit 1
22+
fi
23+
24+
# 3) login to GitHub Container Registry
25+
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u "${GH_USER}" --password-stdin
26+
27+
# 4) build & tag
28+
docker build \
29+
--pull \
30+
-t "${IMAGE}:${VERSION}" \
31+
-t "${IMAGE}:latest" \
32+
.
33+
34+
# 5) push
35+
docker push "${IMAGE}:${VERSION}"
36+
docker push "${IMAGE}:latest"
37+
38+
echo "✅ Pushed:"
39+
echo "${IMAGE}:${VERSION}"
40+
echo "${IMAGE}:latest"

0 commit comments

Comments
 (0)