|
1 | | -name: Create DigitalOcean Kubernetes Cluster |
| 1 | +name: 'DigitalOcean Kubernetes Cluster' |
| 2 | +description: 'Spin up a Kubernetes cluster on DigitalOcean' |
2 | 3 |
|
3 | 4 | on: |
4 | 5 | workflow_dispatch: |
5 | | - inputs: |
6 | | - cluster_name: |
7 | | - description: 'Cluster Name' |
8 | | - required: true |
9 | | - default: 'my-do-cluster' |
10 | | - region: |
11 | | - description: 'Region' |
12 | | - required: false |
13 | | - default: 'nyc1' |
14 | | - node_size: |
15 | | - description: 'Node Size' |
16 | | - required: false |
17 | | - default: 's-2vcpu-4gb' |
18 | | - node_count: |
19 | | - description: 'Node Count' |
20 | | - required: false |
21 | | - default: '2' |
22 | | - |
23 | | -jobs: |
24 | | - create-cluster: |
25 | | - runs-on: ubuntu-latest |
26 | | - steps: |
27 | | - - name: Checkout repository |
28 | | - uses: actions/checkout@v4 |
29 | | - |
30 | | - - name: Install doctl (DigitalOcean CLI) |
31 | | - run: | |
32 | | - curl -sSL https://github.com/digitalocean/doctl/releases/latest/download/doctl-$(uname -s)-$(uname -m) -o doctl |
33 | | - chmod +x doctl |
34 | | - sudo mv doctl /usr/local/bin/ |
35 | | -
|
36 | | - - name: Authenticate with DigitalOcean |
37 | | - env: |
38 | | - DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} |
39 | | - run: | |
40 | | - doctl auth init -t $DIGITALOCEAN_ACCESS_TOKEN |
41 | | -
|
42 | | - - name: Create Kubernetes Cluster |
43 | | - env: |
44 | | - CLUSTER_NAME: ${{ github.event.inputs.cluster_name }} |
45 | | - REGION: ${{ github.event.inputs.region }} |
46 | | - NODE_SIZE: ${{ github.event.inputs.node_size }} |
47 | | - NODE_COUNT: ${{ github.event.inputs.node_count }} |
48 | | - run: | |
49 | | - doctl kubernetes cluster create $CLUSTER_NAME \ |
50 | | - --region $REGION \ |
51 | | - --size $NODE_SIZE \ |
52 | | - --count $NODE_COUNT \ |
53 | | - --wait |
54 | | -
|
55 | | - - name: Get Cluster Kubeconfig |
56 | | - env: |
57 | | - CLUSTER_NAME: ${{ github.event.inputs.cluster_name }} |
58 | | - run: | |
59 | | - doctl kubernetes cluster kubeconfig save $CLUSTER_NAME |
| 6 | + |
| 7 | +inputs: |
| 8 | + do_token: |
| 9 | + description: 'DigitalOcean API Token' |
| 10 | + required: true |
| 11 | + cluster_name: |
| 12 | + description: 'Name of the cluster' |
| 13 | + required: true |
| 14 | + default: 'github-action-cluster' |
| 15 | + region: |
| 16 | + description: 'Region to deploy the cluster in' |
| 17 | + required: true |
| 18 | + default: 'nyc3' |
| 19 | + node_size: |
| 20 | + description: 'Droplet size for nodes' |
| 21 | + required: true |
| 22 | + default: 's-2vcpu-4gb' |
| 23 | + node_count: |
| 24 | + description: 'Number of nodes' |
| 25 | + required: true |
| 26 | + default: '2' |
| 27 | + |
| 28 | +runs: |
| 29 | + using: 'composite' |
| 30 | + steps: |
| 31 | + - name: Install doctl |
| 32 | + run: | |
| 33 | + curl -sL https://github.com/digitalocean/doctl/releases/latest/download/doctl-$(uname -s)-$(uname -m) -o doctl |
| 34 | + chmod +x doctl |
| 35 | + sudo mv doctl /usr/local/bin/ |
| 36 | + shell: bash |
| 37 | + |
| 38 | + - name: Authenticate doctl |
| 39 | + run: | |
| 40 | + doctl auth init --access-token ${{ inputs.do_token }} |
| 41 | + shell: bash |
| 42 | + |
| 43 | + - name: Create Kubernetes Cluster |
| 44 | + run: | |
| 45 | + doctl kubernetes cluster create ${{ inputs.cluster_name }} \ |
| 46 | + --region ${{ inputs.region }} \ |
| 47 | + --size ${{ inputs.node_size }} \ |
| 48 | + --count ${{ inputs.node_count }} |
| 49 | + shell: bash |
| 50 | + |
| 51 | + - name: Get Kubeconfig |
| 52 | + run: | |
| 53 | + doctl kubernetes cluster kubeconfig save ${{ inputs.cluster_name }} |
| 54 | + shell: bash |
| 55 | + |
| 56 | + - name: Output Cluster Info |
| 57 | + run: | |
| 58 | + doctl kubernetes cluster get ${{ inputs.cluster_name }} |
| 59 | + shell: bash |
| 60 | + |
0 commit comments