diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml new file mode 100644 index 0000000..f726d75 --- /dev/null +++ b/.gitea/workflows/docker-build.yml @@ -0,0 +1,56 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + REGISTRY: gitea.samson.media + IMAGE_NAME: samson-media/brave-search-mcp-server + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Gitea Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.GITEA_USERNAME }} + password: ${{ secrets.GITEA_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix={{branch}}- + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max diff --git a/Dockerfile b/Dockerfile index ddee78f..3ba97cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,24 @@ -FROM node:alpine@sha256:5209bcaca9836eb3448b650396213dbe9d9a34d31840c2ae1f206cb2986a8543 AS builder - -RUN apk add --no-cache openssl=3.5.8-r0 +FROM node:22-alpine WORKDIR /app -COPY ./package.json ./package.json -COPY ./package-lock.json ./package-lock.json +# Install build dependencies +RUN apk add --no-cache git -RUN npm ci --ignore-scripts +# Clone and install dependencies +RUN git clone https://github.com/brave/brave-search-mcp-server.git . && \ + npm ci --only=production && \ + npm run build -COPY ./src ./src -COPY ./tsconfig.json ./tsconfig.json +# Remove git since we don't need it in runtime +RUN apk del git -RUN npm run build +# Expose the MCP server port +EXPOSE 3000 -FROM node:alpine@sha256:5209bcaca9836eb3448b650396213dbe9d9a34d31840c2ae1f206cb2986a8543 AS release +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD node -e "require('http').get('http://localhost:3000/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))" -RUN apk add --no-cache openssl=3.5.8-r0 - -WORKDIR /app - -COPY --from=builder /app/dist /app/dist -COPY --from=builder /app/package.json /app/package.json -COPY --from=builder /app/package-lock.json /app/package-lock.json - -ENV NODE_ENV=production - -# The server defaults to binding 127.0.0.1 for safe local execution. Inside a -# container the port must be reachable through the published mapping, so bind to -# all interfaces here. Deployments can still override BRAVE_MCP_HOST. -ENV BRAVE_MCP_HOST=0.0.0.0 - -RUN npm ci --ignore-scripts --omit-dev - -USER node - -ENTRYPOINT ["node", "dist/index.js"] +# Start the MCP server +CMD ["npm", "start"]