-
Notifications
You must be signed in to change notification settings - Fork 10
Added EKS Infrastructure #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
utf94
wants to merge
38
commits into
webaverse:master
Choose a base branch
from
utf94:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
27588ff
Added build
utf94 ed726a0
Fixes
utf94 bcbc85b
Fixes
utf94 5b27431
Fixes
utf94 b6a268c
Fixes
utf94 bd33bae
Fixes
utf94 ee80f03
Fixes
utf94 3ddef92
Fixes
utf94 22431b2
Fixes
utf94 2339261
Fixes
utf94 96add9c
Fixes
utf94 4ba68bd
Fixes
utf94 f644327
Fixes
utf94 693cf86
Fixes
utf94 f03370b
Fixes
utf94 a29588c
Fixes
utf94 df9b6cb
Fixes
utf94 f063d7a
Fixes
utf94 61acccb
Fixes
utf94 94772f9
Fixes
utf94 1fb4ea4
Fixes
utf94 95454b2
Fixes
utf94 8ac26a4
Fixes
utf94 1952e3c
Fixes
utf94 0531b1a
Fixes
utf94 4d1c5d3
Fixes
utf94 472c563
Fixes
utf94 a06b7fc
Fixes
utf94 3d6239c
Fixes
utf94 fd53a9d
Fixes
utf94 296606e
Fixes
utf94 d94418c
Fixes
utf94 308fb8e
Fixes
utf94 9519df9
Fixes
utf94 386eeda
Fixes
utf94 b70a2a3
Fixes
utf94 ea8b7fd
Fixes
utf94 63f01b2
Fixes
utf94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,62 @@ | ||
| version: 0.2 | ||
| run-as: root | ||
|
|
||
| phases: | ||
|
|
||
| install: | ||
| commands: | ||
| - echo Setting up required prerequisites | ||
| - pip install --upgrade awscli | ||
| - curl --silent --location -o /usr/local/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" | ||
| - chmod +x /usr/local/bin/kubectl | ||
| - curl --silent --location -o /usr/local/bin/aws-iam-authenticator "https://amazon-eks.s3-us-west-2.amazonaws.com/1.14.6/2019-08-22/bin/linux/amd64/aws-iam-authenticator" | ||
| - chmod +x /usr/local/bin/aws-iam-authenticator | ||
| - curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/v0.72.0/eksctl_Linux_amd64.tar.gz" | tar xz -C /tmp | ||
| - mv -v /tmp/eksctl /usr/local/bin | ||
| - chmod +x /usr/local/bin/eksctl | ||
| - AWS_ACCOUNT_ID=684910554524 | ||
| - IMAGE_TAG=latest | ||
|
|
||
| pre_build: | ||
| commands: | ||
| - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/webaverse | ||
| - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) | ||
| - IMAGE_TAG=${COMMIT_HASH:=latest} | ||
| - echo Logging in to Amazon EKS... | ||
| - ls -l | ||
| - chmod a+x ./eks/cluster-setup.sh | ||
| - sh ./eks/cluster-setup.sh | ||
| - aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name preview-server | ||
| - echo check config | ||
| - kubectl config view --minify | ||
| - echo check kubectl access | ||
| - kubectl get svc | ||
| - echo Logging in to Amazon ECR... | ||
| - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) | ||
| - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/ecrrepository-app | ||
|
|
||
| build: | ||
| commands: | ||
| - echo Build started on `date` | ||
| - echo Building the Docker image... | ||
| - echo Logging in to Docker Hub... | ||
| - echo "${DOCKERHUB_PASSWORD}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin | ||
| - docker build -t $REPOSITORY_URI:latest . | ||
| - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG | ||
| - echo Building the Docker image... | ||
| # - docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t ecrrepository-app:$IMAGE_TAG . | ||
| # - docker tag ecrrepository-app:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/ecrrepository-app:$IMAGE_TAG | ||
|
|
||
| post_build: | ||
| commands: | ||
| - echo Build completed on `date` | ||
| - echo Pushing the Docker images... | ||
| - echo Logging in to Amazon ECR... | ||
| - aws --version | ||
| - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com | ||
| - docker push $REPOSITORY_URI:latest | ||
| - docker push $REPOSITORY_URI:$IMAGE_TAG | ||
| - echo Writing image definitions file... | ||
| - printf '[{"name":"webaverse-preview-backend","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json | ||
| artifacts: | ||
| files: imagedefinitions.json | ||
| - echo Pushing the Docker image... | ||
| # - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/ecrrepository-app:$IMAGE_TAG | ||
| - echo Push the latest image to cluster | ||
| - kubectl apply -f ./eks/deployment.yaml | ||
| - kubectl rollout -h | ||
| - kubectl rollout restart -f ./eks/deployment.yaml | ||
| - kubectl apply -f ./eks/service.yaml | ||
| - kubectl get svc preview-server | ||
| - export loadbalancer=$(kubectl get svc preview-server -o jsonpath='{.status.loadBalancer.ingress[*].hostname}') | ||
| - kubectl get pods -o wide | ||
| - while [[ $(kubectl get pods -l app=preview-server-app -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod" && sleep 1; done | ||
| - kubectl get pods -o wide | ||
| - kubectl get endpoints | ||
| - kubectl get deployments | ||
| - kubectl logs -l app=preview-server-app | ||
| - echo http://${loadbalancer} | ||
| - curl -k http://${loadbalancer} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| version: 0.2 | ||
| run-as: root | ||
|
|
||
| phases: | ||
|
|
||
| install: | ||
| commands: | ||
| - echo Installing app dependencies... | ||
| - curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl | ||
| - chmod +x ./kubectl | ||
| - mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin | ||
| - echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc | ||
| - source ~/.bashrc | ||
| - echo 'Check kubectl version' | ||
| - kubectl version --short --client | ||
| - chmod +x eks_cicd/prereqs.sh | ||
| - sh eks_cicd/prereqs.sh | ||
|
|
||
| pre_build: | ||
| commands: | ||
| - echo Logging in to Amazon EKS... | ||
| - aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $AWS_CLUSTER_NAME | ||
| - echo check config | ||
| - kubectl config view --minify | ||
| - echo check kubectl access | ||
| - kubectl get svc | ||
| - echo Logging in to Amazon ECR... | ||
| - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com | ||
| - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME | ||
| - docker pull $REPOSITORY_URI:$IMAGE_TAG | ||
|
|
||
|
|
||
| build: | ||
| commands: | ||
| - echo Build started on `date` | ||
| - echo Building the Docker image... | ||
| - docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG . | ||
| - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG | ||
|
|
||
| post_build: | ||
| commands: | ||
| - echo Build completed on `date` | ||
| - echo Pushing the Docker image... | ||
| - docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG | ||
| - echo Push the latest image to cluster | ||
| - kubectl apply -f eks_cicd/deployment.yaml | ||
| - kubectl rollout restart -f eks_cicd/deployment.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| echo "Inside cluster setup" | ||
| ls -l | ||
| #Create cluster if don't exist | ||
| aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name preview-server || eksctl create cluster -f cluster.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| apiVersion: eksctl.io/v1alpha5 | ||
| kind: ClusterConfig | ||
|
|
||
| metadata: | ||
| name: preview-server | ||
| region: us-west-2 | ||
|
|
||
| nodeGroups: | ||
| - name: ng-1-workers | ||
| labels: { role: workers } | ||
| instanceType: t2.large | ||
| desiredCapacity: 2 | ||
| privateNetworking: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: preview-server-app-development | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: preview-server-app | ||
| environment: testing | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: preview-server-app | ||
| environment: testing | ||
| spec: | ||
| containers: | ||
| - name: preview-server | ||
| image: 684910554524.dkr.ecr.us-west-2.amazonaws.com/ecrrepository-app:latest | ||
| resources: | ||
| requests: | ||
| cpu: "100m" | ||
| memory: "500Mi" | ||
| limits: | ||
| cpu: "200m" | ||
| memory: "1024Mi" | ||
| ports: | ||
| - containerPort: 80 | ||
| name: http | ||
| readinessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 80 | ||
| initialDelaySeconds: 60 | ||
| timeoutSeconds: 5 | ||
| livenessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 80 | ||
| initialDelaySeconds: 70 | ||
| timeoutSeconds: 10 | ||
| failureThreshold: 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| labels: | ||
| app.kubernetes.io/name: preview-server | ||
| app.kubernetes.io/instance: preview-server-instance | ||
| app.kubernetes.io/version: "1.0.0" | ||
| app.kubernetes.io/component: backend | ||
| app.kubernetes.io/managed-by: kubectl | ||
| name: preview-server | ||
| spec: | ||
| selector: | ||
| app: preview-server-app | ||
| type: LoadBalancer | ||
| ports: | ||
| - protocol: TCP | ||
| port: 80 | ||
| targetPort: 80 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way to not hardcode the account id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we will move these files to Cloud Formation and the account id will be dynamic then.