Skip to content

Commit 8b41671

Browse files
committed
feat: dockerfile
1 parent 334089b commit 8b41671

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

.github/workflows/docker-build.yaml

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Create and publish Docker images with specific build args
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- dev
9+
tags:
10+
- v*
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
15+
jobs:
16+
build-main-image:
17+
runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
18+
permissions:
19+
contents: read
20+
packages: write
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
platform:
25+
- linux/amd64
26+
- linux/arm64
27+
28+
steps:
29+
# GitHub Packages requires the entire repository name to be in lowercase
30+
# although the repository owner has a lowercase username, this prevents some people from running actions after forking
31+
- name: Set repository and image name to lowercase
32+
run: |
33+
echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
34+
echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
35+
env:
36+
IMAGE_NAME: "${{ github.repository }}"
37+
38+
- name: Prepare
39+
run: |
40+
platform=${{ matrix.platform }}
41+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
42+
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
48+
49+
- name: Set up Docker Buildx
50+
uses: docker/setup-buildx-action@v3
51+
52+
- name: Log in to the Container registry
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ${{ env.REGISTRY }}
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Extract metadata for Docker images (default latest tag)
60+
id: meta
61+
uses: docker/metadata-action@v5
62+
with:
63+
images: ${{ env.FULL_IMAGE_NAME }}
64+
tags: |
65+
type=ref,event=branch
66+
type=ref,event=tag
67+
type=sha,prefix=git-
68+
type=semver,pattern={{version}}
69+
type=semver,pattern={{major}}.{{minor}}
70+
flavor: |
71+
latest=${{ github.ref == 'refs/heads/main' }}
72+
73+
- name: Extract metadata for Docker cache
74+
id: cache-meta
75+
uses: docker/metadata-action@v5
76+
with:
77+
images: ${{ env.FULL_IMAGE_NAME }}
78+
tags: |
79+
type=ref,event=branch
80+
${{ github.ref_type == 'tag' && 'type=raw,value=main' || '' }}
81+
flavor: |
82+
prefix=cache-${{ matrix.platform }}-
83+
latest=false
84+
85+
- name: Build Docker image (latest)
86+
uses: docker/build-push-action@v5
87+
id: build
88+
with:
89+
context: .
90+
push: true
91+
platforms: ${{ matrix.platform }}
92+
labels: ${{ steps.meta.outputs.labels }}
93+
outputs: type=image,name=${{ env.FULL_IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
94+
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
95+
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
96+
build-args: |
97+
BUILD_HASH=${{ github.sha }}
98+
99+
- name: Export digest
100+
run: |
101+
mkdir -p /tmp/digests
102+
digest="${{ steps.build.outputs.digest }}"
103+
touch "/tmp/digests/${digest#sha256:}"
104+
105+
- name: Upload digest
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: digests-main-${{ env.PLATFORM_PAIR }}
109+
path: /tmp/digests/*
110+
if-no-files-found: error
111+
retention-days: 1
112+
113+
merge-main-images:
114+
runs-on: ubuntu-latest
115+
needs: [build-main-image]
116+
steps:
117+
# GitHub Packages requires the entire repository name to be in lowercase
118+
# although the repository owner has a lowercase username, this prevents some people from running actions after forking
119+
- name: Set repository and image name to lowercase
120+
run: |
121+
echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV}
122+
echo "FULL_IMAGE_NAME=ghcr.io/${IMAGE_NAME,,}" >>${GITHUB_ENV}
123+
env:
124+
IMAGE_NAME: "${{ github.repository }}"
125+
126+
- name: Download digests
127+
uses: actions/download-artifact@v4
128+
with:
129+
pattern: digests-main-*
130+
path: /tmp/digests
131+
merge-multiple: true
132+
133+
- name: Set up Docker Buildx
134+
uses: docker/setup-buildx-action@v3
135+
136+
- name: Log in to the Container registry
137+
uses: docker/login-action@v3
138+
with:
139+
registry: ${{ env.REGISTRY }}
140+
username: ${{ github.actor }}
141+
password: ${{ secrets.GITHUB_TOKEN }}
142+
143+
- name: Extract metadata for Docker images (default latest tag)
144+
id: meta
145+
uses: docker/metadata-action@v5
146+
with:
147+
images: ${{ env.FULL_IMAGE_NAME }}
148+
tags: |
149+
type=ref,event=branch
150+
type=ref,event=tag
151+
type=sha,prefix=git-
152+
type=semver,pattern={{version}}
153+
type=semver,pattern={{major}}.{{minor}}
154+
flavor: |
155+
latest=${{ github.ref == 'refs/heads/main' }}
156+
157+
- name: Create manifest list and push
158+
working-directory: /tmp/digests
159+
run: |
160+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
161+
$(printf '${{ env.FULL_IMAGE_NAME }}@sha256:%s ' *)
162+
163+
- name: Inspect image
164+
run: |
165+
docker buildx imagetools inspect ${{ env.FULL_IMAGE_NAME }}:${{ steps.meta.outputs.version }}

Dockerfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM python:3.12-slim-bookworm
2+
3+
# Install uv (from official binary), nodejs, npm, and git
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
5+
6+
RUN apt-get update && apt-get install -y --no-install-recommends \
7+
git \
8+
curl \
9+
ca-certificates \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Install Node.js and npm via NodeSource
13+
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
14+
&& apt-get install -y nodejs \
15+
&& rm -rf /var/lib/apt/lists/*
16+
17+
# Confirm npm and node versions (optional debugging info)
18+
RUN node -v && npm -v
19+
20+
# Copy your mcpo source code (assuming in src/mcpo)
21+
COPY src/mcpo /app/mcpo
22+
COPY pyproject.toml /app/
23+
WORKDIR /app
24+
25+
# Install mcpo via uv
26+
RUN uv venv \
27+
&& uv pip install . \
28+
&& rm -rf ~/.cache
29+
30+
# Expose port (optional but common default)
31+
EXPOSE 8000
32+
33+
# Entrypoint set for easy container invocation
34+
ENTRYPOINT ["mcpo"]
35+
36+
# Default help CMD (can override at runtime)
37+
CMD ["--help"]

0 commit comments

Comments
 (0)