|
| 1 | +name: EKS Deployment |
| 2 | +env: |
| 3 | + EKSClusterRegion: us-west-2 |
| 4 | + EKSKubeProxyVersion: latest |
| 5 | + EKSCoreDNSVersion: latest |
| 6 | + EKSEBSCSIVersion: latest |
| 7 | +# Controls when the workflow will run |
| 8 | +on: |
| 9 | + # Triggers the workflow on push or pull request events but only for the main branch |
| 10 | + # push: |
| 11 | + # branches: [ ucs-template ] |
| 12 | + # pull_request: |
| 13 | + # branches: [ ucs-template ] |
| 14 | + |
| 15 | + # Allows you to run this workflow manually from the Actions tab |
| 16 | + workflow_dispatch: |
| 17 | + branches: [ main ] |
| 18 | + inputs: |
| 19 | + distinct_id: |
| 20 | + TEARDOWN: |
| 21 | + description: 'Teardown EKS Cluster?' |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + default: false |
| 25 | + KEY: |
| 26 | + description: 'Access Key ID' |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + default: '' |
| 30 | + SECRET: |
| 31 | + description: 'Access Secret Key ID' |
| 32 | + required: false |
| 33 | + type: string |
| 34 | + default: '' |
| 35 | + TOKEN: |
| 36 | + description: 'AWS Session Token' |
| 37 | + required: false |
| 38 | + type: string |
| 39 | + default: '' |
| 40 | + METADATA: |
| 41 | + description: 'metadata description' |
| 42 | + required: true |
| 43 | + type: string |
| 44 | + AWSCONNECTION: |
| 45 | + description: 'Method of AWS connection' |
| 46 | + required: true |
| 47 | + type: choice |
| 48 | + default: 'oidc' |
| 49 | + options: |
| 50 | + - oidc |
| 51 | + - keys |
| 52 | + - iam |
| 53 | + DEPLOYMENTPROJECT: |
| 54 | + description: 'Deployment Project' |
| 55 | + required: true |
| 56 | + type: choice |
| 57 | + default: 'UNITY' |
| 58 | + options: |
| 59 | + - UNITY |
| 60 | + - SIPS |
| 61 | + DEPLOYMENTSTAGE: |
| 62 | + description: 'Deployment Target' |
| 63 | + required: true |
| 64 | + type: choice |
| 65 | + default: 'DEV' |
| 66 | + options: |
| 67 | + - DEV |
| 68 | + - TEST |
| 69 | + - OPS |
| 70 | + - SIPS |
| 71 | + DEPLOYMENTSOURCE: |
| 72 | + description: 'Where the action is being run' |
| 73 | + required: true |
| 74 | + type: choice |
| 75 | + default: 'github' |
| 76 | + options: |
| 77 | + - github |
| 78 | + - act |
| 79 | +permissions: |
| 80 | + id-token: write # required to use OIDC authentication |
| 81 | + contents: read # required to checkout the code from the repo |
| 82 | + |
| 83 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 84 | +jobs: |
| 85 | + deployment: |
| 86 | + # The type of runner that the job will run on |
| 87 | + runs-on: ubuntu-latest |
| 88 | + |
| 89 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 90 | + steps: |
| 91 | + # Set up current working directory with the repo contents |
| 92 | + - uses: actions/checkout@v3 |
| 93 | + - name: Install aws |
| 94 | + run: | |
| 95 | + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" |
| 96 | + unzip -q awscliv2.zip |
| 97 | + sudo ./aws/install --update |
| 98 | + - name: Install kubectl |
| 99 | + run: | |
| 100 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" |
| 101 | + sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl |
| 102 | +
|
| 103 | + # Install eksctl to launch EKS |
| 104 | + - name: Install eksctl |
| 105 | + run: | |
| 106 | + curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/v0.132.0/eksctl_Linux_amd64.tar.gz" | tar xz -C /tmp && \ |
| 107 | + sudo mv /tmp/eksctl /usr/local/bin && \ |
| 108 | + eksctl version |
| 109 | +
|
| 110 | + - name: Install Helm |
| 111 | + run: | |
| 112 | + curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 |
| 113 | + chmod 700 get_helm.sh |
| 114 | + ./get_helm.sh |
| 115 | +
|
| 116 | + # Launch EKS |
| 117 | + - name: Launch EKS cluster |
| 118 | + if: "${{ ! inputs.TEARDOWN }}" |
| 119 | + run: | |
| 120 | + export cluster=$(echo '${{ env.CLUSTERNAME }}') |
| 121 | + echo '${{env.EKSTEMPLATE}}' > /tmp/eksctl-config.yaml |
| 122 | + eksctl create cluster -f /tmp/eksctl-config.yaml |
| 123 | + aws eks update-kubeconfig --region us-west-2 --name $cluster |
| 124 | + kubectl patch storageclass gp2 -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}' |
| 125 | + export IFS=";" |
| 126 | + sentence="$EKSUserArn" |
| 127 | + for word in $sentence; do |
| 128 | + echo "$word" |
| 129 | + #eksctl create iamidentitymapping --cluster ${cluster} --region=us-west-2 --arn arn:aws:iam::237868187491:role/mcp-tenantDeveloper --group system:masters --username admin |
| 130 | + #eksctl create iamidentitymapping --cluster ${cluster} --region=us-west-2 --arn arn:aws:iam::237868187491:role/mcp-tenantOperator --group system:masters --username adminOp |
| 131 | + eksctl create iamidentitymapping --cluster ${cluster} --region=us-west-2 --arn $word --group system:masters --username admin |
| 132 | + done |
| 133 | + helm repo add fairwinds-stable https://charts.fairwinds.com/stable |
| 134 | + helm install vpa fairwinds-stable/vpa --namespace vpa --create-namespace |
| 135 | + helm install goldilocks --namespace goldilocks --create-namespace fairwinds-stable/goldilocks |
| 136 | +
|
| 137 | + - name: Write SSM Params |
| 138 | + if: "${{ ! inputs.TEARDOWN }}" |
| 139 | + run: | |
| 140 | + export cluster=$(echo '${{ inputs.METADATA }}' | jq -r .clustername) |
| 141 | + aws ssm put-parameter --name /unity/extensions/eks/${cluster}/nodeGroups/default/name --type String --value defaultgroupNodeGroup |
| 142 | + aws ssm put-parameter --name /unity/extensions/eks/${cluster}/nodeGroups/default/launchTemplateName --type String --value eksctl-${cluster}-nodegroup-defaultgroupNodeGroup |
| 143 | + aws ssm put-parameter --name /unity/extensions/eks/${cluster}/networking/subnets/privateIds --type StringList --value "$(utils/get-ssm-param.sh /unity/account/network/subnets/eks/private)" |
| 144 | +
|
| 145 | + # Teardown EKS |
| 146 | + - name: Teardown EKS cluster |
| 147 | + if: ${{ inputs.TEARDOWN }} |
| 148 | + run: | |
| 149 | + if [ "${{inputs.AWSCONNECTION}}" == "keys" ] |
| 150 | + then |
| 151 | + export AWS_ACCESS_KEY_ID=${{ inputs.KEY }} |
| 152 | + export AWS_SECRET_ACCESS_KEY=${{ inputs.SECRET }} |
| 153 | + export AWS_SESSION_TOKEN=${{ inputs.TOKEN }} |
| 154 | + export AWS_PAGER="" |
| 155 | + fi |
| 156 | + export IFS=";" |
| 157 | + export cluster=$(echo '${{ inputs.METADATA }}' | jq -r .clustername) |
| 158 | + aws eks update-kubeconfig --region us-west-2 --name $cluster |
| 159 | + helm repo add fairwinds-stable https://charts.fairwinds.com/stable |
| 160 | + helm uninstall vpa --namespace vpa |
| 161 | + helm uninstall goldilocks --namespace goldilocks |
| 162 | + eksctl delete nodegroup defaultgroupNodeGroup --cluster $cluster --drain=false --disable-eviction |
| 163 | + eksctl delete cluster --name $cluster |
| 164 | + |
| 165 | + - name: Delete SSM Params |
| 166 | + if: ${{ inputs.TEARDOWN }} |
| 167 | + run: | |
| 168 | + export cluster=$(echo '${{ inputs.METADATA }}' | jq -r .clustername) |
| 169 | + aws ssm delete-parameter --name /unity/extensions/eks/${cluster}/nodeGroups/default/name |
| 170 | + aws ssm delete-parameter --name /unity/extensions/eks/${cluster}/nodeGroups/default/launchTemplateName |
| 171 | + aws ssm delete-parameter --name /unity/extensions/eks/${cluster}/networking/subnets/privateIds |
0 commit comments