diff --git a/deploy/action.yml b/deploy/action.yml new file mode 100644 index 0000000..daafe43 --- /dev/null +++ b/deploy/action.yml @@ -0,0 +1,34 @@ +name: 'Deploy to Kubernetes' +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 + namespace-name: + description: 'Kubernetes namespace name' + required: true + deployment-name: + description: 'Kubernetes deployment name' + required: true + +runs: + using: "composite" + steps: + - name: Deploy to Kubernetes + working-directory: ${{ inputs.working-directory }} + run: kubectl apply -f ${{ inputs.deployment-file }} + 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/do-setup-kubectl/action.yml b/do-setup-kubectl/action.yml new file mode 100644 index 0000000..c61e3d0 --- /dev/null +++ b/do-setup-kubectl/action.yml @@ -0,0 +1,22 @@ +name: 'Setup kubectl for DigitalOcean.' +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" + 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/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..8f3d90f 100644 --- a/readme.md +++ b/readme.md @@ -1,19 +1,61 @@ # GitHub Actions Kubernetes -A collection of GitHub actions for Kubernetes projects. +A collection of Kubernetes related GitHub actions. -## Example Playbook +## Actions + +### Setup DigitalOcean + +Setup Digital-Ocean CLI and configure Kubernetes. + +#### Example + +```yaml + - uses: aboutbits/github-actions-kubernetes/do-setup-kubectl@v1 + with: + digital-ocean-token: ${{ secrets.DIGITALOCEAN_TOKEN }} + cluster-name: ${{ env.CLUSTER_NAME }} +``` + +#### Inputs + +The 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 ```yaml - - name: Build code - uses: aboutbits/github-actions-kubernetes/xxx@v1 + - uses: aboutbits/github-actions-kubernetes/deploy@v1 with: - xxx-version: ${{ env.NODE_VERSION }} + deployment-file: 'infrastructure/kubernetes.prod.yml' + namespace-name: ${{ env.NAMESPACE_NAME }} + deployment-name: ${{ env.DEPLOYMENT_NAME }} ``` +#### Inputs + +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 | +| `working-directory` | `.` | The working directory | + + ## 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: 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: