From 47160547042a3f07512abf51a709493142d372b4 Mon Sep 17 00:00:00 2001 From: Cyril Diagne Date: Wed, 23 Oct 2019 18:53:56 +0200 Subject: [PATCH] progress with aws & skaffold --- providers/aws/Dockerfile | 35 ++++++---- providers/aws/README.md | 11 ++-- providers/aws/app_dev.sh | 127 +++++++++++++++++++++++++++++++++++++ providers/aws/dev_start.sh | 5 -- providers/aws/dev_stop.sh | 5 -- providers/aws/setup.sh | 40 ++++++++++-- 6 files changed, 190 insertions(+), 33 deletions(-) create mode 100644 providers/aws/app_dev.sh delete mode 100755 providers/aws/dev_start.sh delete mode 100755 providers/aws/dev_stop.sh diff --git a/providers/aws/Dockerfile b/providers/aws/Dockerfile index b0d21f3..559df22 100644 --- a/providers/aws/Dockerfile +++ b/providers/aws/Dockerfile @@ -1,5 +1,13 @@ FROM alpine:3.10 +# Set dependencies versions. +ARG EKSCTL_VERSION=0.7.0 +ARG KUBECTL_VERSION=1.16.2 +ARG SKAFFOLD_VERSION=0.40.0 +ARG ISTIO_VERSION=1.3.3 +ARG HELM_VERSION=2.15.0 + +# Install base apps. RUN apk add --update-cache --no-cache \ bash \ build-base \ @@ -14,24 +22,30 @@ RUN apk add --update-cache --no-cache \ RUN pip install awscli # Install eksctl +ARG EKSCTL_HOST="https://github.com/weaveworks/eksctl/releases/download" RUN curl --silent \ - --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" \ + --location "${EKSCTL_HOST}/${EKSCTL_VERSION}/eksctl_$(uname -s)_amd64.tar.gz" \ | tar xz -C /tmp RUN mv /tmp/eksctl /usr/local/bin # Install kubectl -RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && \ - chmod +x ./kubectl && \ - mv ./kubectl /usr/local/bin/kubectl +ARG KUBECTL_HOST="https://storage.googleapis.com/kubernetes-release/release" +RUN curl -LO "${KUBECTL_HOST}/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" && \ + chmod +x ./kubectl && \ + mv ./kubectl /usr/local/bin/kubectl # Install Helm -RUN curl -L https://git.io/get_helm.sh | bash - -# Install Ksync. -RUN curl https://vapor-ware.github.io/gimme-that/gimme.sh | bash +RUN curl -L https://git.io/get_helm.sh | DESIRED_VERSION="v${HELM_VERSION}" bash # Download Istio CRDs -RUN curl -L https://git.io/getLatestIstio | sh - +RUN curl -L https://git.io/getLatestIstio | ISTIO_VERSION="${ISTIO_VERSION}" sh - + +# Install Skaffold. +ARG SKAFFOLD_HOST="https://storage.googleapis.com/skaffold/releases" +# RUN curl -Lo skaffold "${SKAFFOLD_HOST}/v${SKAFFOLD_VERSION}/skaffold-linux-amd64" && \ +RUN curl -Lo skaffold "https://storage.googleapis.com/artifacts.gpu-sh.appspot.com/releases/latest/skaffold-linux-amd64" && \ + chmod +x skaffold && \ + mv skaffold /usr/local/bin # Copy the provider's commands. COPY . /kuda_cmd @@ -39,10 +53,9 @@ ENV KUDA_CMD_DIR /kuda_cmd RUN chmod +x /kuda_cmd/*.sh RUN ln -s /kuda_cmd/app_deploy.sh /usr/local/bin/kuda_app_deploy && \ ln -s /kuda_cmd/app_delete.sh /usr/local/bin/kuda_app_delete && \ + ln -s /kuda_cmd/app_dev.sh /usr/local/bin/kuda_app_dev && \ ln -s /kuda_cmd/setup.sh /usr/local/bin/kuda_setup && \ ln -s /kuda_cmd/delete.sh /usr/local/bin/kuda_delete && \ - ln -s /kuda_cmd/dev_start.sh /usr/local/bin/kuda_dev_start && \ - ln -s /kuda_cmd/dev_stop.sh /usr/local/bin/kuda_dev_stop && \ ln -s /kuda_cmd/get.sh /usr/local/bin/kuda_get # Go to the app home. diff --git a/providers/aws/README.md b/providers/aws/README.md index 4b2aeb0..b259d19 100644 --- a/providers/aws/README.md +++ b/providers/aws/README.md @@ -1,6 +1,7 @@ ## Amazon Web Service Provider Hacky & bare implementation with shell scripts. +It uses [ECR](https://aws.amazon.com/ecr) to privately store the app images. # Status @@ -9,23 +10,23 @@ Hacky & bare implementation with shell scripts. | setup | ✔ | | delete | ✔ | | get | Not Started | +| app dev | WIP | | app deploy | WIP | | app delete | ✔ | -| dev start | Not Started | -| dev stop | Not Started | +| dev start | ✗ | +| dev stop | ✗ | -# Configuration +# Prerequisites -**Prerequisites:** - You must have subscribed to [EKS-optimize AMI with GPU support](https://aws.amazon.com/marketplace/pp/B07GRHFXGM) - You must have an increased limit of at least 1 instance of type p2.xlarge. You can make requests [here](http://aws.amazon.com/contact-us/ec2-request) - You must have an [aws configuration](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) on your local machine in `~/.aws/` with credentials that have authorization for: - cloudformation - ec2 + - ec2 autoscaling - eks - iam - api - - ec2 autoscaling - ecr - elb diff --git a/providers/aws/app_dev.sh b/providers/aws/app_dev.sh new file mode 100644 index 0000000..b8f05be --- /dev/null +++ b/providers/aws/app_dev.sh @@ -0,0 +1,127 @@ +#!/bin/bash + +set -e + +source $KUDA_CMD_DIR/.config.sh + +aws_account_id="$(aws sts get-caller-identity | jq -r .Account)" +ecr_domain="$aws_account_id.dkr.ecr.$KUDA_AWS_CLUSTER_REGION.amazonaws.com" + +app_name=$1 +app_registry="$ecr_domain/$app_name" +app_image="$app_registry:$app_version" +namespace="default" + +app_cache_name=$app_name-cache + +echo $app_image + +# Create Container Registry if it doesn't exists. +if [ -z "$(aws ecr describe-repositories --region $KUDA_AWS_CLUSTER_REGION | grep $app_name)" ]; then + aws ecr create-repository \ + --repository-name $app_name \ + --region $KUDA_AWS_CLUSTER_REGION +else + echo "Container Registry $app_registry already exists" +fi + +# Create the cache registry if it doesn't exists. +if [ -z "$(aws ecr describe-repositories --region $KUDA_AWS_CLUSTER_REGION | grep $app_cache_name)" ]; then + aws ecr create-repository \ + --repository-name $app_cache_name \ + --region $KUDA_AWS_CLUSTER_REGION +else + echo "Container Registry $app_registry-cache already exists" +fi + +# Retrieve cluster token. +aws eks update-kubeconfig \ + --name $KUDA_AWS_CLUSTER_NAME \ + --region $KUDA_AWS_CLUSTER_REGION + +# Login Container Registry. +# aws ecr get-login --region $KUDA_AWS_CLUSTER_REGION --no-include-email | bash + +#TODO: Build & Push image using Kaniko. + +# Write Knative service config. +# cat <.kuda-app.k8.yaml + +# cat < $tmp_config_file + kubectl create secret generic docker-kaniko-secret --from-file $tmp_config_file + rm $tmp_config_file +else + echo "docker-kaniko-secret already configured." +fi + # Install Cluster Autoscaler # echo "Installing cluster autoscaler" # kubectl apply -f /kuda_cmd/config/cluster-autoscaler.yaml -echo "Retrieving hostname:" -kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' +echo +echo "Hostname:" +kubectl -n istio-system get service istio-ingressgateway \ + -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' +echo echo echo "Cluster $KUDA_AWS_CLUSTER_NAME is ready!"