Skip to content

Commit b9bfcc0

Browse files
committed
chore(hosting): Add A GitHub workflow to build and push docker image to a registry
1 parent 67a698a commit b9bfcc0

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*.*.*'
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch:
13+
14+
env:
15+
IMAGE_NAME: secops-mcp-server
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to private registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ secrets.DOCKER_REGISTRY_URL }}
35+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
36+
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ secrets.DOCKER_REGISTRY_URL }}/${{ env.IMAGE_NAME }}
43+
tags: |
44+
# Tag with branch name for branch pushes
45+
type=ref,event=branch
46+
# Tag with PR number for pull requests
47+
type=ref,event=pr
48+
# Tag with semver for version tags
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
# Tag with 'latest' for main branch
53+
type=raw,value=latest,enable={{is_default_branch}}
54+
# Tag with short SHA
55+
type=sha,prefix={{branch}}-
56+
57+
- name: Build and push Docker image
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
file: ./Dockerfile
62+
push: ${{ github.event_name != 'pull_request' }}
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max
67+
platforms: linux/amd64,linux/arm64
68+
69+
- name: Image digest
70+
run: echo "Image pushed with digest ${{ steps.build-push.outputs.digest }}"

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ COPY --from=builder /dist/*.whl /tmp/wheels/
4848
RUN uv pip install --system /tmp/wheels/*.whl && \
4949
rm -rf /tmp/wheels
5050

51-
# Create directory for OAuth tokens (if needed, though disabled in HTTP mode)
52-
RUN mkdir -p /home/mcpserver/.gitguardian && \
53-
chown -R mcpserver:mcpserver /home/mcpserver/.gitguardian
54-
5551
# Switch to non-root user
5652
USER mcpserver
5753

0 commit comments

Comments
 (0)