diff --git a/Dockerfile.windows b/Dockerfile.windows new file mode 100644 index 0000000..cb8bab2 --- /dev/null +++ b/Dockerfile.windows @@ -0,0 +1,40 @@ +ARG OS_RELEASE + +FROM mcr.microsoft.com/windows/servercore:${OS_RELEASE} + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"] + +RUN $url = 'https://cygwin.com/setup-x86_64.exe'; \ + Write-Host ('Downloading {0} ...' -f $url); \ + Invoke-WebRequest -Uri $url -OutFile 'C:/setup-x86_64.exe'; \ + \ + Write-Host 'Installing ...'; \ + New-Item -ItemType directory -Path 'C:/tmp'; \ + Start-Process "C:/setup-x86_64.exe" -NoNewWindow -Wait -PassThru -ArgumentList @('-q','-v','-n','-B','-R','C:/cygwin64','-l','C:/tmp','-s','http://ctm.crouchingtigerhiddenfruitbat.org/pub/cygwin/circa/64bit/2019/03/06/161558','-X','-P', 'default,curl,openssl'); \ + \ + Write-Host 'Removing ...'; \ + Remove-Item -Path 'C:/tmp' -Force -Recurse -ErrorAction Ignore; \ + \ + Write-Host 'Verifying install ...'; \ + Start-Process "C:/cygwin64/bin/cygcheck.exe" -NoNewWindow -Wait -PassThru -ArgumentList @('-c'); \ + \ + Write-Host 'Complete.'; + +RUN $ACL=Get-Acl -Path 'C:\'; \ + Set-Acl -Path 'C:\cygwin64\' -AclObject $ACL + +SHELL ["C:/cygwin64/bin/sh", "-l", "-c"] +WORKDIR C:/cygwin64/bin + +RUN 'curl -o /usr/bin/kubectl.exe -L https://storage.googleapis.com/kubernetes-release/release/v1.22.0/bin/windows/amd64/kubectl.exe' +RUN 'chmod +x /usr/bin/kubectl.exe' + +COPY cf-deploy-kubernetes.sh ../cf-deploy-kubernetes +COPY template.sh ../template.sh + +RUN 'sed -i "s/\r$//" C:/cygwin64/cf-deploy-kubernetes' +RUN 'sed -i "s/\r$//" C:/cygwin64/template.sh' + +LABEL owner=codefresh.io + +ENTRYPOINT ["C:/cygwin64/bin/sh", "-l", "-c"] \ No newline at end of file diff --git a/cf-deploy-kubernetes.sh b/cf-deploy-kubernetes.sh index 188bd0a..e6d80d7 100755 --- a/cf-deploy-kubernetes.sh +++ b/cf-deploy-kubernetes.sh @@ -8,7 +8,7 @@ fatal() { readonly KUBECTL_ACTION=${KUBECTL_ACTION:-apply} [[ $KUBECTL_ACTION =~ ^(apply|create|replace)$ ]] || fatal "KUBECTL_ACTION should be one of apply|create|replace " -deployment_file=${1:-deployment.yml} +deployment_file=${1:-C:/codefresh/volume/cf-generated/deployment.yml} : ${KUBERNETES_NAMESPACE:=default} : ${KUBERNETES_DEPLOYMENT_TIMEOUT:=120} @@ -38,16 +38,16 @@ else fi #check the cluster version and decide which version of kubectl to use: -SERVER_VERSION=$(kubectl version --short=true | grep -i server | cut -c18-20 | tr -d .) +SERVER_VERSION=$(kubectl version --short=true --context "${KUBECONTEXT}" | grep -i server | cut -c18-20 | tr -d .) -if (( "$SERVER_VERSION" <= "16" )); then mv /usr/local/bin/kubectl1.6 /usr/local/bin/kubectl; fi +if (( "$SERVER_VERSION" <= "16" )); then mv /usr/local/bin/kubectl1.6 /usr/local/bin/kubectl; fi 2>/dev/null [ ! -f "${deployment_file}" ] && echo "Couldn't find $deployment_file file at $(pwd)" && exit 1; DEPLOYMENT_FILE=${deployment_file}-$(date '+%y-%m-%d_%H-%M-%S').yml -$(dirname $0)/template.sh "$deployment_file" > "$DEPLOYMENT_FILE" || fatal "Failed to apply deployment template on $deployment_file" +/template.sh "$deployment_file" > "$DEPLOYMENT_FILE" || fatal "Failed to apply deployment template on $deployment_file" echo "---> Kubernetes objects to deploy in $deployment_file :" @@ -66,5 +66,5 @@ kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" $KUBECT if [ -n "$DEPLOYMENT_NAME" ]; then echo "---> Waiting for a successful deployment/${DEPLOYMENT_NAME} status to namespace ${KUBERNETES_NAMESPACE} ..." - timeout -s SIGTERM -t $KUBERNETES_DEPLOYMENT_TIMEOUT kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" rollout status deployment/"${DEPLOYMENT_NAME}" || fatal "Deployment Failed" + timeout -s SIGTERM $KUBERNETES_DEPLOYMENT_TIMEOUT kubectl --context "${KUBECONTEXT}" --namespace "${KUBERNETES_NAMESPACE}" rollout status deployment/"${DEPLOYMENT_NAME}" || fatal "Deployment Failed" fi