From f2acca6a45b9a79ba54fdd2492974fc764b229fc Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 11 Jul 2023 11:54:44 +0200 Subject: [PATCH 1/6] add actions --- deploy-to-kubernetes/action.yml | 27 +++++++++++++++++++++++++++ setup-digital-ocean/action.yml | 20 ++++++++++++++++++++ xxx/action.yml | 11 ----------- 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 deploy-to-kubernetes/action.yml create mode 100644 setup-digital-ocean/action.yml delete mode 100644 xxx/action.yml diff --git a/deploy-to-kubernetes/action.yml b/deploy-to-kubernetes/action.yml new file mode 100644 index 0000000..436b88a --- /dev/null +++ b/deploy-to-kubernetes/action.yml @@ -0,0 +1,27 @@ +name: 'Deploy to Kubernetes' +description: 'Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured first.' + +inputs: + environment: + description: '"test" or "prod"' + namespace-name: + description: 'Digital Ocean namespace name' + deployment-name: + description: 'Kubernetes deployment name' + +runs: + using: "composite" + steps: + - name: Deploy to Kubernetes + run: kubectl apply -f infrastructure/kubernetes.${{ inputs.environment }}.yml + shell: bash + + - name: Verify deployment + id: verify + run: kubectl rollout status -n ${{ inputs.namespace-name }} deployment/${{ inputs.deployment-name }} + shell: bash + + - name: Undo deployment if failed + if: ${{ failure() && steps.verify.conclusion == 'failure' }} + run: kubectl rollout undo -n ${{ inputs.namespace-name }} deployment/${{ inputs.deployment-name }} + shell: bash diff --git a/setup-digital-ocean/action.yml b/setup-digital-ocean/action.yml new file mode 100644 index 0000000..77ecd74 --- /dev/null +++ b/setup-digital-ocean/action.yml @@ -0,0 +1,20 @@ +name: 'Setup Kubernetes for Digital-Ocean.' +description: 'Setup Digital-Ocean CLI and configure Kubernetes.' + +inputs: + cluster-name: + description: 'Kubernetes cluster name' + digital-ocean-token: + description: 'Digital Ocean access token' + +runs: + using: "composite" + steps: + - name: Install doctl + uses: digitalocean/action-doctl@v2 + with: + token: ${{ inputs.digital-ocean-token }} + + - name: Save DigitalOcean kubeconfig with short-lived credentials + run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ inputs.cluster-name }} + shell: bash diff --git a/xxx/action.yml b/xxx/action.yml deleted file mode 100644 index 534073c..0000000 --- a/xxx/action.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: 'xxx' - -inputs: - xxx-version: - description: 'The xxx version that should be used for the build' - required: true - default: 'xxx' - -runs: - using: "composite" - steps: From 8febfceb0f6aa87d1b61717b061fb1f43aaa2aae Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 11 Jul 2023 11:54:54 +0200 Subject: [PATCH 2/6] update readme and add license --- license.md | 7 +++++++ readme.md | 28 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 license.md diff --git a/license.md b/license.md new file mode 100644 index 0000000..21586f5 --- /dev/null +++ b/license.md @@ -0,0 +1,7 @@ +Copyright About Bits GmbH + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/readme.md b/readme.md index 15e0f21..b151774 100644 --- a/readme.md +++ b/readme.md @@ -1,19 +1,35 @@ # GitHub Actions Kubernetes -A collection of GitHub actions for Kubernetes projects. +A collection of GitHub actions for Kubernetes. -## Example Playbook +## Setup DigitalOcean +Setup Digital-Ocean CLI and configure Kubernetes. + +### Example + +```yaml + - uses: aboutbits/github-actions-kubernetes/setup-digital-ocean@v1 + with: + cluster-name: ${{ env.TEST_CLUSTER_NAME }} + digital-ocean-token: ${{ secrets.DIGITALOCEAN_TOKEN }} +``` + +## Deploy to Kubernetes +Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured first. + +### Example ```yaml - - name: Build code - uses: aboutbits/github-actions-kubernetes/xxx@v1 + - uses: aboutbits/github-actions-kubernetes/deploy-to-kubernetes@v1 with: - xxx-version: ${{ env.NODE_VERSION }} + environment: 'test' + namespace-name: ${{ env.NAMESPACE_NAME }} + deployment-name: ${{ env.DEPLOYMENT_NAME }} ``` ## Versioning -In order to have a verioning in place and working, create leightweight tags that point to the appropriate minor release versions. +In order to have a versioning in place and working, create lightweight tags that point to the appropriate minor release versions. Creating a new minor release: From 735b99914cfa5a611e93c701e160a5be25e7f717 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Tue, 11 Jul 2023 13:25:38 +0200 Subject: [PATCH 3/6] rename actions --- {deploy-to-kubernetes => deploy}/action.yml | 4 ++-- readme.md | 8 +++++--- {setup-digital-ocean => setup-kubectl}/action.yml | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) rename {deploy-to-kubernetes => deploy}/action.yml (83%) rename {setup-digital-ocean => setup-kubectl}/action.yml (81%) diff --git a/deploy-to-kubernetes/action.yml b/deploy/action.yml similarity index 83% rename from deploy-to-kubernetes/action.yml rename to deploy/action.yml index 436b88a..18eb0ab 100644 --- a/deploy-to-kubernetes/action.yml +++ b/deploy/action.yml @@ -1,11 +1,11 @@ name: 'Deploy to Kubernetes' -description: 'Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured first.' +description: 'Deploy an application to a Kubernetes cluster.' inputs: environment: description: '"test" or "prod"' namespace-name: - description: 'Digital Ocean namespace name' + description: 'Kubernetes namespace name' deployment-name: description: 'Kubernetes deployment name' diff --git a/readme.md b/readme.md index b151774..b2b5421 100644 --- a/readme.md +++ b/readme.md @@ -3,24 +3,26 @@ A collection of GitHub actions for Kubernetes. ## Setup DigitalOcean + Setup Digital-Ocean CLI and configure Kubernetes. ### Example ```yaml - - uses: aboutbits/github-actions-kubernetes/setup-digital-ocean@v1 + - uses: aboutbits/github-actions-kubernetes/setup-kubectl@v1 with: - cluster-name: ${{ env.TEST_CLUSTER_NAME }} digital-ocean-token: ${{ secrets.DIGITALOCEAN_TOKEN }} + cluster-name: ${{ env.CLUSTER_NAME }} ``` ## Deploy to Kubernetes + Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured first. ### Example ```yaml - - uses: aboutbits/github-actions-kubernetes/deploy-to-kubernetes@v1 + - uses: aboutbits/github-actions-kubernetes/deploy@v1 with: environment: 'test' namespace-name: ${{ env.NAMESPACE_NAME }} diff --git a/setup-digital-ocean/action.yml b/setup-kubectl/action.yml similarity index 81% rename from setup-digital-ocean/action.yml rename to setup-kubectl/action.yml index 77ecd74..d37c0c7 100644 --- a/setup-digital-ocean/action.yml +++ b/setup-kubectl/action.yml @@ -1,11 +1,11 @@ -name: 'Setup Kubernetes for Digital-Ocean.' -description: 'Setup Digital-Ocean CLI and configure Kubernetes.' +name: 'Setup kubectl for DigitalOcean.' +description: 'Setup DigitalOcean CLI and configure kubectl.' inputs: - cluster-name: - description: 'Kubernetes cluster name' digital-ocean-token: description: 'Digital Ocean access token' + cluster-name: + description: 'Kubernetes cluster name' runs: using: "composite" From bf590ee1df9c23ec8da519f3c66cafc5454ff437 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Thu, 13 Jul 2023 14:46:43 +0200 Subject: [PATCH 4/6] rename action and replace parameter --- deploy/action.yml | 4 ++-- {setup-kubectl => do-setup-kubectl}/action.yml | 0 readme.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename {setup-kubectl => do-setup-kubectl}/action.yml (100%) diff --git a/deploy/action.yml b/deploy/action.yml index 18eb0ab..1366b4e 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -2,7 +2,7 @@ name: 'Deploy to Kubernetes' description: 'Deploy an application to a Kubernetes cluster.' inputs: - environment: + deployment-file: description: '"test" or "prod"' namespace-name: description: 'Kubernetes namespace name' @@ -13,7 +13,7 @@ runs: using: "composite" steps: - name: Deploy to Kubernetes - run: kubectl apply -f infrastructure/kubernetes.${{ inputs.environment }}.yml + run: kubectl apply -f ${{ inputs.deployment-file }} shell: bash - name: Verify deployment diff --git a/setup-kubectl/action.yml b/do-setup-kubectl/action.yml similarity index 100% rename from setup-kubectl/action.yml rename to do-setup-kubectl/action.yml diff --git a/readme.md b/readme.md index b2b5421..6cdaee5 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ Setup Digital-Ocean CLI and configure Kubernetes. ### Example ```yaml - - uses: aboutbits/github-actions-kubernetes/setup-kubectl@v1 + - uses: aboutbits/github-actions-kubernetes/do-setup-kubectl@v1 with: digital-ocean-token: ${{ secrets.DIGITALOCEAN_TOKEN }} cluster-name: ${{ env.CLUSTER_NAME }} @@ -24,7 +24,7 @@ Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured ```yaml - uses: aboutbits/github-actions-kubernetes/deploy@v1 with: - environment: 'test' + deployment-file: 'infrastructure/kubernetes.prod.yml' namespace-name: ${{ env.NAMESPACE_NAME }} deployment-name: ${{ env.DEPLOYMENT_NAME }} ``` From 34c50f68d78bcb02426d80f36ea9431072f94151 Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Fri, 14 Jul 2023 08:47:23 +0200 Subject: [PATCH 5/6] update documentation --- deploy/action.yml | 5 ++++- do-setup-kubectl/action.yml | 2 ++ readme.md | 33 ++++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/deploy/action.yml b/deploy/action.yml index 1366b4e..48089b5 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -3,11 +3,14 @@ description: 'Deploy an application to a Kubernetes cluster.' inputs: deployment-file: - description: '"test" or "prod"' + description: 'Deployment file for kubectl to apply' + required: true namespace-name: description: 'Kubernetes namespace name' + required: true deployment-name: description: 'Kubernetes deployment name' + required: true runs: using: "composite" diff --git a/do-setup-kubectl/action.yml b/do-setup-kubectl/action.yml index d37c0c7..50a2c9c 100644 --- a/do-setup-kubectl/action.yml +++ b/do-setup-kubectl/action.yml @@ -4,8 +4,10 @@ description: 'Setup DigitalOcean CLI and configure kubectl.' inputs: digital-ocean-token: description: 'Digital Ocean access token' + required: true cluster-name: description: 'Kubernetes cluster name' + required: true runs: using: "composite" diff --git a/readme.md b/readme.md index 6cdaee5..c74299f 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,14 @@ # GitHub Actions Kubernetes -A collection of GitHub actions for Kubernetes. +A collection of Kubernetes related GitHub actions. -## Setup DigitalOcean +## Actions + +### Setup DigitalOcean Setup Digital-Ocean CLI and configure Kubernetes. -### Example +#### Example ```yaml - uses: aboutbits/github-actions-kubernetes/do-setup-kubectl@v1 @@ -15,11 +17,21 @@ Setup Digital-Ocean CLI and configure Kubernetes. cluster-name: ${{ env.CLUSTER_NAME }} ``` -## Deploy to Kubernetes +#### Inputs + +Following inputs can be used as `step.with` keys + +| Name | Required/Default | Description | +|--------------------------|--------------------|---------------------------------| +| `digital-ocean-token` | required | Digital Ocean access token | +| `cluster-name` | required | Kubernetes cluster name | + + +### Deploy to Kubernetes Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured first. -### Example +#### Example ```yaml - uses: aboutbits/github-actions-kubernetes/deploy@v1 @@ -29,6 +41,17 @@ Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured deployment-name: ${{ env.DEPLOYMENT_NAME }} ``` +#### Inputs + +Following inputs can be used as `step.with` keys + +| Name | Required/Default | Description | +|----------------------|--------------------|-------------------------------------------| +| `deployment-file` | required | Deployment file for kubectl to apply | +| `namespace-name` | required | Kubernetes namespace name | +| `deployment-name` | required | Kubernetes deployment name | + + ## Versioning In order to have a versioning in place and working, create lightweight tags that point to the appropriate minor release versions. From dfbffdbdc4c463c775099d5e09b1d8a9bc0a3b1f Mon Sep 17 00:00:00 2001 From: Andreas Hufler Date: Fri, 14 Jul 2023 10:53:27 +0200 Subject: [PATCH 6/6] add working directory and update readme --- deploy/action.yml | 6 +++++- do-setup-kubectl/action.yml | 2 +- readme.md | 15 ++++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/deploy/action.yml b/deploy/action.yml index 48089b5..daafe43 100644 --- a/deploy/action.yml +++ b/deploy/action.yml @@ -1,7 +1,10 @@ name: 'Deploy to Kubernetes' -description: 'Deploy an application to a Kubernetes cluster.' +description: 'Deploy an application to a Kubernetes cluster' inputs: + working-directory: + description: 'The working directory' + default: '.' deployment-file: description: 'Deployment file for kubectl to apply' required: true @@ -16,6 +19,7 @@ runs: using: "composite" steps: - name: Deploy to Kubernetes + working-directory: ${{ inputs.working-directory }} run: kubectl apply -f ${{ inputs.deployment-file }} shell: bash diff --git a/do-setup-kubectl/action.yml b/do-setup-kubectl/action.yml index 50a2c9c..c61e3d0 100644 --- a/do-setup-kubectl/action.yml +++ b/do-setup-kubectl/action.yml @@ -1,5 +1,5 @@ name: 'Setup kubectl for DigitalOcean.' -description: 'Setup DigitalOcean CLI and configure kubectl.' +description: 'Setup DigitalOcean CLI and configure kubectl' inputs: digital-ocean-token: diff --git a/readme.md b/readme.md index c74299f..8f3d90f 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,7 @@ Setup Digital-Ocean CLI and configure Kubernetes. #### Inputs -Following inputs can be used as `step.with` keys +The following inputs can be used as `step.with` keys: | Name | Required/Default | Description | |--------------------------|--------------------|---------------------------------| @@ -43,13 +43,14 @@ Deploy application to a Kubernetes Cluster. Requires Kubernetes to be configured #### Inputs -Following inputs can be used as `step.with` keys +The following inputs can be used as `step.with` keys: -| Name | Required/Default | Description | -|----------------------|--------------------|-------------------------------------------| -| `deployment-file` | required | Deployment file for kubectl to apply | -| `namespace-name` | required | Kubernetes namespace name | -| `deployment-name` | required | Kubernetes deployment name | +| Name | Required/Default | Description | +|------------------------|----------------------|--------------------------------------------| +| `deployment-file` | required | Deployment file for kubectl to apply | +| `namespace-name` | required | Kubernetes namespace name | +| `deployment-name` | required | Kubernetes deployment name | +| `working-directory` | `.` | The working directory | ## Versioning