Skip to content

Commit d07aac6

Browse files
BarberBarber
authored andcommitted
update deploys
1 parent 7e7d40d commit d07aac6

File tree

2 files changed

+171
-80
lines changed

2 files changed

+171
-80
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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

.github/workflows/deploy_project_apigateway.yml

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,11 @@ on:
99
workflow_dispatch:
1010
branches: [ main ]
1111
inputs:
12-
distinct_id:
1312
teardown:
1413
description: 'Teardown Project Api Gateway?'
1514
required: false
1615
type: boolean
1716
default: false
18-
deploymentProject:
19-
description: 'Deployment Project'
20-
required: true
21-
type: choice
22-
default: 'UNITY'
23-
options:
24-
- UNITY
25-
- SIPS
26-
deploymentStage:
27-
description: 'Deployment Target'
28-
required: true
29-
type: choice
30-
default: 'DEV'
31-
options:
32-
- DEV
33-
- TEST
34-
- OPS
35-
- SIPS
36-
deploymentOwner:
37-
description: 'Deployment Owner'
38-
required: true
39-
type: string
40-
default: 'nightly'
41-
deploymentTarget:
42-
description: 'Cloud Host'
43-
required: true
44-
type: choice
45-
default: 'mcp'
46-
options:
47-
- mcp
48-
apiName:
49-
description: 'API Name'
50-
required: true
51-
type: string
52-
default: 'Unity Project REST API Gateway'
53-
awsConnection:
54-
description: 'Method of AWS connection'
55-
required: true
56-
type: choice
57-
default: 'oidc'
58-
options:
59-
- oidc
60-
- keys
61-
- iam
62-
deploymentSource:
63-
description: 'Where the action is being run'
64-
required: true
65-
type: choice
66-
default: 'github'
67-
options:
68-
- github
69-
- act
7017

7118
permissions:
7219
id-token: write # required to use OIDC authentication
@@ -88,31 +35,11 @@ jobs:
8835
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list && \
8936
sudo apt update && sudo apt install terraform
9037
- name: Install apps
91-
if: "${{ github.event.inputs.deploymentSource =='act'}}"
9238
run: |
9339
sudo apt update && sudo apt install -y curl git jq unzip && \
9440
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && sudo ./aws/install && \
9541
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
9642
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
97-
- name: echo distinct ID ${{ github.event.inputs.distinct_id }}
98-
run: echo ${{ github.event.inputs.distinct_id }}
99-
- name: Configure default variables
100-
env:
101-
DEFAULT_TARGET: 'mcp'
102-
DEFAULT_COMMIT: 'main'
103-
DEFAULT_STAGE: 'DEV'
104-
DEFAULT_PROJECT: 'UNITY'
105-
DEFAULT_OWNER: 'nightly'
106-
DEFAULT_APINAME: 'Unity Project REST API Gateway'
107-
DEFAULT_TF_DIRECTORY: 'terraform-project-api-gateway_module'
108-
run: |
109-
echo "TARGET_ENV=${{ github.event.inputs.deploymentTarget || env.DEFAULT_TARGET }}" >> $GITHUB_ENV
110-
echo "TARGET_STAGE=${{ github.event.inputs.deploymentStage || env.DEFAULT_STAGE }}" >> $GITHUB_ENV
111-
echo "COMMIT_HASH=${{ github.event.inputs.sourceBranch || env.DEFAULT_COMMIT }}" >> $GITHUB_ENV
112-
echo "TARGET_PROJECT=${{ github.event.inputs.deploymentProject || env.DEFAULT_PROJECT }}" >> $GITHUB_ENV
113-
echo "TARGET_OWNER=${{ github.event.inputs.deploymentOwner || env.DEFAULT_OWNER }}" >> $GITHUB_ENV
114-
echo "TARGET_API=${{ github.event.inputs.apiName || env.DEFAULT_APINAME }}" >> $GITHUB_ENV
115-
echo "TF_DIRECTORY=${{ env.DEFAULT_TF_DIRECTORY }}" >> $GITHUB_ENV
11643
11744
- name: Display deployment configuration
11845
run :
@@ -127,13 +54,6 @@ jobs:
12754
run :
12855
terraform workspace select ${{ env.TARGET_ENV }}_${{ env.TARGET_STAGE }}_${{ env.TARGET_PROJECT }}_${{ env.TARGET_OWNER }} || terraform workspace new ${{ env.TARGET_ENV }}_${{ env.TARGET_STAGE }}_${{ env.TARGET_PROJECT }}_${{ env.TARGET_OWNER }}
12956

130-
- name: Configure AWS credentials
131-
uses: aws-actions/configure-aws-credentials@v1
132-
if: ${{ INPUTS.awsConnection == 'oidc' }}
133-
with:
134-
role-to-assume: ${{ secrets[format('OIDC_{0}_ROLE', env.TARGET_STAGE)] }}
135-
aws-region: ${{ vars.AWS_REGION }}
136-
13757
- name: Get AWS Caller Identity
13858
run: aws sts get-caller-identity
13959

0 commit comments

Comments
 (0)