From e4c40f8918ee6a728ba2b918acab96a45a87ae2b Mon Sep 17 00:00:00 2001 From: Noah Lee Date: Mon, 2 May 2022 23:07:46 +0900 Subject: [PATCH] Combine dev and production environment for the pipeline (#426) * Add the serialization option * Combine dev and prod environment for the pipeline --- .github/workflows/deploy-to-cloud.yaml | 83 ++++---------------------- .gitignore | 2 - deploy.yml | 23 ++++++- release/values.dev.yaml | 33 ++++++++++ release/values.production.yaml | 32 ++++++++++ 5 files changed, 96 insertions(+), 77 deletions(-) create mode 100644 release/values.dev.yaml create mode 100644 release/values.production.yaml diff --git a/.github/workflows/deploy-to-cloud.yaml b/.github/workflows/deploy-to-cloud.yaml index 1567fa30..b6fab980 100644 --- a/.github/workflows/deploy-to-cloud.yaml +++ b/.github/workflows/deploy-to-cloud.yaml @@ -4,40 +4,20 @@ on: deployment jobs: - deploy-local: + deploy: runs-on: ubuntu-latest - if: ${{ github.event.deployment.environment == 'local' }} steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Deploy successfully - if: success() uses: chrnorm/deployment-status@releases/v1 with: deployment_id: ${{ github.event.deployment.id }} - state: "success" + description: Trigger the pipeline + state: "queued" token: "${{ github.token }}" - description: Finish to deploy successfully. - - deploy-dev: - runs-on: ubuntu-latest - # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#deployment - if: ${{ github.event.deployment.environment == 'dev' }} - steps: - name: Checkout uses: actions/checkout@v2 - - name: Create values.yaml - uses: finnp/create-file-action@master - env: - FILE_NAME: "./.github/values.yaml" - FILE_BASE64: "aW5ncmVzczoKICBlbmFibGVkOiB0cnVlCiAgYW5ub3RhdGlvbnM6CiAgICBrdWJlcm5ldGVzLmlvL2luZ3Jlc3MuY2xhc3M6IG5naW54CiAgICBjZXJ0LW1hbmFnZXIuaW8vY2x1c3Rlci1pc3N1ZXI6ICJsZXRzZW5jcnlwdC1wcm9kIgogIGhvc3RzOgogICAgLSBob3N0OiBkZXYuZ2l0cGxveS5pbwogICAgICBwYXRoczoKICAgICAgICAtIHBhdGg6IC8KICAgICAgICAgIHBhdGhUeXBlOiBQcmVmaXgKICB0bHM6CiAgIC0gc2VjcmV0TmFtZTogZ2l0cGxveS1kZXYtdGxzCiAgICAgaG9zdHM6CiAgICAgICAtIGRldi5naXRwbG95LmlvCgpyZXNvdXJjZXM6CiAgcmVxdWVzdHM6CiAgICBjcHU6IDUwbQogICAgbWVtb3J5OiAxMjhNaQoKZW52OgogIEdJVFBMT1lfREVCVUdfTU9ERTogInRydWUiCiAgR0lUUExPWV9TRVJWRVJfSE9TVDogImRldi5naXRwbG95LmlvIgogIEdJVFBMT1lfU0VSVkVSX1BST1RPOiBodHRwcwogIEdJVFBMT1lfQURNSU5fVVNFUlM6ICJoYW5qdW5sZWUiCiAgR0lUUExPWV9NRU1CRVJfRU5UUklFUzogImdpdHBsb3ktaW8iCiAgR0lUUExPWV9QUk9NRVRIRVVTX0VOQUJMRUQ6ICJ0cnVlIgoKZXh0cmFTZWNyZXROYW1lc0ZvckVudkZyb206CiAgLSBnaXRwbG95LWRldi1zZWNyZXQKCnBlcnNpc3RlbnRWb2x1bWU6CiAgZW5hYmxlZDogdHJ1ZQo=" - - - name: Start to deploy uses: chrnorm/deployment-status@releases/v1 with: deployment_id: ${{ github.event.deployment.id }} @@ -45,8 +25,9 @@ jobs: state: "in_progress" token: "${{ github.token }}" - - name: Deploy + name: Deploy Dev uses: WyriHaximus/github-action-helm3@v2 + if: ${{ github.event.deployment.environment == 'dev' }} with: # Upgrade to the version. exec: > @@ -55,55 +36,15 @@ jobs: --install --atomic --namespace=gitploy - -f .github/values.yaml + -f release/values.dev.yaml --set=image.tag=${GITHUB_REF#refs/tags/v} - --set=image.pullPolicy=Always + --set=image.pullPolicy=${{ github.event.deployment.payload.pullPolicy }} --description="Upgrade to ${GITHUB_REF#refs/tags/}" kubeconfig: '${{ secrets.KUBECONFIG }}' - - name: Deploy successfully - if: success() - uses: chrnorm/deployment-status@releases/v1 - with: - deployment_id: ${{ github.event.deployment.id }} - description: Finish to deploy successfully. - state: "success" - token: "${{ github.token }}" - - - name: Deploy failed - if: failure() - uses: chrnorm/deployment-status@releases/v1 - with: - deployment_id: ${{ github.event.deployment.id }} - description: Failed to deploy. - state: "failure" - token: "${{ github.token }}" - - deploy-production: - runs-on: ubuntu-latest - # https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#deployment - if: ${{ github.event.deployment.environment == 'production' }} - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Create values.yaml - uses: finnp/create-file-action@master - env: - FILE_NAME: "./.github/values.yaml" - FILE_BASE64: "cmVwbGljYUNvdW50OiAyCgppbmdyZXNzOgogIGVuYWJsZWQ6IHRydWUKICBhbm5vdGF0aW9uczoKICAgIGt1YmVybmV0ZXMuaW8vaW5ncmVzcy5jbGFzczogbmdpbngKICAgIGNlcnQtbWFuYWdlci5pby9jbHVzdGVyLWlzc3VlcjogImxldHNlbmNyeXB0LXByb2QiCiAgaG9zdHM6CiAgICAtIGhvc3Q6IGNsb3VkLmdpdHBsb3kuaW8KICAgICAgcGF0aHM6CiAgICAgICAgLSBwYXRoOiAvCiAgICAgICAgICBwYXRoVHlwZTogUHJlZml4CiAgdGxzOgogICAtIHNlY3JldE5hbWU6IGdpdHBsb3ktcHJvZC10bHMKICAgICBob3N0czoKICAgICAgIC0gY2xvdWQuZ2l0cGxveS5pbwoKcmVzb3VyY2VzOgogIHJlcXVlc3RzOgogICAgY3B1OiAxMDBtCiAgICBtZW1vcnk6IDI1Nk1pCgplbnY6CiAgR0lUUExPWV9ERUJVR19NT0RFOiAidHJ1ZSIKICBHSVRQTE9ZX1NFUlZFUl9IT1NUOiAiY2xvdWQuZ2l0cGxveS5pbyIKICBHSVRQTE9ZX1NFUlZFUl9QUk9UTzogaHR0cHMKICBHSVRQTE9ZX0FETUlOX1VTRVJTOiAiaGFuanVubGVlIgogIEdJVFBMT1lfR0lUSFVCX1NDT1BFUzogInB1YmxpY19yZXBvLHJlYWQ6dXNlcixyZWFkOm9yZyIKICBHSVRQTE9ZX1NUT1JFX0RSSVZFUjogIm15c3FsIgoKZXh0cmFTZWNyZXROYW1lc0ZvckVudkZyb206CiAgLSBnaXRwbG95LXByb2Qtc2VjcmV0Cg==" - - - name: Start to deploy - uses: chrnorm/deployment-status@releases/v1 - with: - deployment_id: ${{ github.event.deployment.id }} - description: Start to deploy to the Kubernetes - state: "in_progress" - token: "${{ github.token }}" - - - name: Deploy + name: Deploy Production uses: WyriHaximus/github-action-helm3@v2 + if: ${{ github.event.deployment.environment == 'production' }} with: # Upgrade to the version. exec: > @@ -112,13 +53,12 @@ jobs: --install --atomic --namespace=gitploy - -f .github/values.yaml + -f release/values.production.yaml --set=image.tag=${GITHUB_REF#refs/tags/v} - --set=image.pullPolicy=Always + --set=image.pullPolicy=${{ github.event.deployment.payload.pullPolicy }} --description="Upgrade to ${GITHUB_REF#refs/tags/}" kubeconfig: '${{ secrets.KUBECONFIG }}' - - name: Deploy successfully if: success() uses: chrnorm/deployment-status@releases/v1 with: @@ -127,7 +67,6 @@ jobs: state: "success" token: "${{ github.token }}" - - name: Deploy failed if: failure() uses: chrnorm/deployment-status@releases/v1 with: diff --git a/.gitignore b/.gitignore index 9533f9a2..d666b05d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,3 @@ # vendor/ .env *.db - -release/ \ No newline at end of file diff --git a/deploy.yml b/deploy.yml index 759a6b93..eee1dae5 100644 --- a/deploy.yml +++ b/deploy.yml @@ -1,13 +1,20 @@ envs: - name: dev task: ${GITPLOY_DEPLOY_TASK:=rollback}:kubernetes - # Disable "auto_merge" to avoid merge conflict - # when it deploys the tag behind the head. auto_merge: false - # Check test and publish is succeed. required_contexts: - "publish-image" deployable_ref: 'v.*\..*\..*' + serialization: true + inputs: + pullPolicy: + required: true + type: select + description: Image pull policy + options: + - Always + - IfNotPresent + default: Always - name: production task: ${GITPLOY_DEPLOY_TASK:=rollback}:kubernetes @@ -21,3 +28,13 @@ envs: - hanjunlee - gitploy-qa deployable_ref: 'v.*\..*\..*' + serialization: true + inputs: + pullPolicy: + required: true + type: select + description: Image pull policy + options: + - Always + - IfNotPresent + default: Always diff --git a/release/values.dev.yaml b/release/values.dev.yaml new file mode 100644 index 00000000..0bccf25f --- /dev/null +++ b/release/values.dev.yaml @@ -0,0 +1,33 @@ +ingress: + enabled: true + annotations: + kubernetes.io/ingress.class: nginx + cert-manager.io/cluster-issuer: "letsencrypt-prod" + hosts: + - host: dev.gitploy.io + paths: + - path: / + pathType: Prefix + tls: + - secretName: gitploy-dev-tls + hosts: + - dev.gitploy.io + +resources: + requests: + cpu: 50m + memory: 128Mi + +env: + GITPLOY_DEBUG_MODE: "true" + GITPLOY_SERVER_HOST: "dev.gitploy.io" + GITPLOY_SERVER_PROTO: https + GITPLOY_ADMIN_USERS: "hanjunlee" + GITPLOY_MEMBER_ENTRIES: "gitploy-io" + GITPLOY_PROMETHEUS_ENABLED: "true" + +extraSecretNamesForEnvFrom: + - gitploy-dev-secret + +persistentVolume: + enabled: true \ No newline at end of file diff --git a/release/values.production.yaml b/release/values.production.yaml new file mode 100644 index 00000000..132ff805 --- /dev/null +++ b/release/values.production.yaml @@ -0,0 +1,32 @@ +replicaCount: 2 + +ingress: + enabled: true + annotations: + kubernetes.io/ingress.class: nginx + cert-manager.io/cluster-issuer: "letsencrypt-prod" + hosts: + - host: cloud.gitploy.io + paths: + - path: / + pathType: Prefix + tls: + - secretName: gitploy-prod-tls + hosts: + - cloud.gitploy.io + +resources: + requests: + cpu: 100m + memory: 256Mi + +env: + GITPLOY_DEBUG_MODE: "true" + GITPLOY_SERVER_HOST: "cloud.gitploy.io" + GITPLOY_SERVER_PROTO: https + GITPLOY_ADMIN_USERS: "hanjunlee" + GITPLOY_GITHUB_SCOPES: "public_repo,read:user,read:org" + GITPLOY_STORE_DRIVER: "mysql" + +extraSecretNamesForEnvFrom: + - gitploy-prod-secret \ No newline at end of file