diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d1127a1..811a30b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -10,10 +10,52 @@ env: GO_VERSION: "1.24.6" jobs: + docker-push: + name: Build Docker Image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=sha,prefix=main-{{date 'YYYYMMDD'}}-,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + deploy-staging: name: Deploy to Staging runs-on: ubuntu-latest environment: staging + needs: docker-push steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index e476860..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Docker Build and Push - -on: - push: - branches: [ main ] - -jobs: - build-and-push: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=sha,prefix=main-{{date 'YYYYMMDD'}}-,enable={{is_default_branch}} - - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/deploy/pkg/k8s/registry.go b/deploy/pkg/k8s/registry.go index ba453ff..86f4267 100644 --- a/deploy/pkg/k8s/registry.go +++ b/deploy/pkg/k8s/registry.go @@ -1,6 +1,9 @@ package k8s import ( + "os/exec" + "strings" + v1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1" corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1" metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1" @@ -11,6 +14,17 @@ import ( "github.com/modelcontextprotocol/registry/deploy/infra/pkg/providers" ) +// getGitCommitHash returns the current git commit hash +func getGitCommitHash() string { + cmd := exec.Command("git", "rev-parse", "HEAD") + output, err := cmd.Output() + if err != nil { + // Fallback to a default value if git command fails + return "unknown" + } + return strings.TrimSpace(string(output)) +} + // DeployMCPRegistry deploys the MCP Registry to the Kubernetes cluster func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, environment string) (*corev1.Service, error) { conf := config.New(ctx, "mcp-registry") @@ -58,6 +72,10 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env Labels: pulumi.StringMap{ "app": pulumi.String("mcp-registry"), }, + Annotations: pulumi.StringMap{ + // Use git commit hash to trigger pod restarts when deploying new infra versions + "registry.modelcontextprotocol.io/deployCommit": pulumi.String(getGitCommitHash()), + }, }, Spec: &corev1.PodSpecArgs{ Containers: corev1.ContainerArray{