From 1c69ca3cbb6330b5d9e0ad3f73b833b26161c06f Mon Sep 17 00:00:00 2001 From: Ruslan Rotaru Date: Tue, 11 Jul 2023 10:42:58 +0100 Subject: [PATCH] added base k8s deployment added pipeline added brew.sh script added concurrency to all pipelines --- .github/workflows/cd-testnet.yaml | 17 ++++++ .github/workflows/ci.yml | 6 ++- .github/workflows/template-deploy.yaml | 71 ++++++++++++++++++++++++++ brew.sh | 8 +++ k8s/base/deployment.yaml | 34 ++++++++++++ k8s/base/kustomization.yaml | 8 +++ k8s/testnet/kustomization.yaml | 10 ++++ 7 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cd-testnet.yaml create mode 100644 .github/workflows/template-deploy.yaml create mode 100755 brew.sh create mode 100644 k8s/base/deployment.yaml create mode 100644 k8s/base/kustomization.yaml create mode 100644 k8s/testnet/kustomization.yaml diff --git a/.github/workflows/cd-testnet.yaml b/.github/workflows/cd-testnet.yaml new file mode 100644 index 0000000..d569d5c --- /dev/null +++ b/.github/workflows/cd-testnet.yaml @@ -0,0 +1,17 @@ +name: Testnet CD for graphix + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +on: + workflow_dispatch: + pull_request: + +jobs: + deploy: + uses: ./.github/workflows/template-deploy.yaml + with: + ENVIRONMENT: testnet + secrets: + GCP_SECRET: ${{ secrets.GCP_GRAPH_NETWORK }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e38e6ae..2b718ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,9 @@ name: CI pipeline +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + on: push: branches: [main] @@ -34,7 +38,7 @@ jobs: args: --all -- --check docker-api-server: - runs-on: ubuntu-latest + runs-on: ubuntu-latest/Users/rotarur/projects/edgeandnode/graph-infra/.github/workflows/template-deploy.yaml steps: - name: Set up QEMU uses: docker/setup-qemu-action@v2 diff --git a/.github/workflows/template-deploy.yaml b/.github/workflows/template-deploy.yaml new file mode 100644 index 0000000..67909b5 --- /dev/null +++ b/.github/workflows/template-deploy.yaml @@ -0,0 +1,71 @@ +name: Template Deploy + +on: + workflow_call: + inputs: + GCP_PROJECT_ID: + required: false + type: string + default: graph-mainnet + CLUSTER_NAME: + required: false + type: string + default: testnet + CLUSTER_LOCATION: + required: false + type: string + default: us-central1-a + ENVIRONMENT: + required: false + type: string + default: testnet + ENABLE_DIFF: + required: false + type: boolean + default: true + ENABLE_APPLY: + required: false + type: boolean + default: false + secrets: + GCP_SECRET: + required: true + +jobs: + template-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + + - id: "auth" + uses: "google-github-actions/auth@v1" + with: + credentials_json: ${{ secrets.GCP_SECRET }} + + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 + with: + project_id: ${{ inputs.GCP_PROJECT_ID }} + + - id: "get-credentials" + uses: "google-github-actions/get-gke-credentials@v1" + with: + cluster_name: ${{ inputs.CLUSTER_NAME }} + location: ${{ inputs.CLUSTER_LOCATION }} + + - name: Enable homebrew + uses: raviqqe/enable-homebrew@v1.0.0 + + - name: Install infrastructure tools + run: ./brew.sh + + - name: Diff ${{ inputs.ENVIRONMENT }} + if: inputs.ENABLE_DIFF + working-directory: k8s + run: kubectl diff -k ${{ inputs.ENVIRONMENT }} + + - name: Deploy to ${{ inputs.ENVIRONMENT }} cluster + if: inputs.ENABLE_APPLY + working-directory: k8s + run: kubectl apply -k ${{ inputs.ENVIRONMENT }} diff --git a/brew.sh b/brew.sh new file mode 100755 index 0000000..a7e0a55 --- /dev/null +++ b/brew.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +brew install cask google-cloud-sdk +gcloud components install gke-gcloud-auth-plugin + +curl -LO "https://dl.k8s.io/release/v1.24.1/bin/linux/amd64/kubectl" +chmod +x ./kubectl +mv ./kubectl /usr/local/bin/kubectl diff --git a/k8s/base/deployment.yaml b/k8s/base/deployment.yaml new file mode 100644 index 0000000..81962af --- /dev/null +++ b/k8s/base/deployment.yaml @@ -0,0 +1,34 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: graphix + labels: + app: graphix +spec: + replicas: 1 + selector: + matchLabels: + app: graphix + template: + metadata: + labels: + app: graphix + annotations: + prometheus.io/scrape: "true" + prometheus.io/path: "/metrics" + prometheus.io/port: "7300" + spec: + imagePullSecrets: + - name: docker-registry + containers: + - name: graphix + image: graphix:to-be-replaced-by-kustomize + imagePullPolicy: IfNotPresent + ports: + - name: graphix + containerPort: 80 + - name: metrics + containerPort: 7300 + command: + - sleep + - infinte diff --git a/k8s/base/kustomization.yaml b/k8s/base/kustomization.yaml new file mode 100644 index 0000000..d52a53f --- /dev/null +++ b/k8s/base/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - deployment.yaml + # - service.yaml + # - ingress.yaml + # - servicemonitor.yaml diff --git a/k8s/testnet/kustomization.yaml b/k8s/testnet/kustomization.yaml new file mode 100644 index 0000000..e104a64 --- /dev/null +++ b/k8s/testnet/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +bases: + - ../base + +images: + - name: graphix + newName: ghcr.io/edgeandnode/graphix-cross-checker + newTag: latest