Skip to content

Commit

Permalink
Merge pull request #2420 from amazeeio/kubectl-build-deploy-cleanup
Browse files Browse the repository at this point in the history
cleanup kubectl-build-deploy-dind:
  • Loading branch information
Toby Bellwood authored Dec 24, 2020
2 parents 878d17a + 66906d1 commit 2823f93
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 423 deletions.
3 changes: 0 additions & 3 deletions images/kubectl-build-deploy-dind/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ RUN rm -rf /root && ln -s /home /root
ENV LAGOON=kubectl-build-deploy-dind

RUN mkdir -p /kubectl-build-deploy/git
RUN mkdir -p /kubectl-build-deploy/tug
RUN mkdir -p /kubectl-build-deploy/lagoon

WORKDIR /kubectl-build-deploy/git

COPY docker-entrypoint.sh /lagoon/entrypoints/100-docker-entrypoint.sh
COPY build-deploy.sh /kubectl-build-deploy/build-deploy.sh
COPY build-deploy-docker-compose.sh /kubectl-build-deploy/build-deploy-docker-compose.sh
COPY tug.sh /kubectl-build-deploy/tug.sh

COPY tug /kubectl-build-deploy/tug
COPY scripts /kubectl-build-deploy/scripts

COPY helmcharts /kubectl-build-deploy/helmcharts
Expand Down
93 changes: 5 additions & 88 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ done
### BUILD IMAGES
##############################################

# we only need to build images for pullrequests and branches, but not during a TUG build
if [[ ( "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ) && ! $THIS_IS_TUG == "true" ]]; then
# we only need to build images for pullrequests and branches
if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then

BUILD_ARGS=()

Expand Down Expand Up @@ -414,18 +414,6 @@ if [[ ( "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ) && ! $TH

fi

# if $DEPLOY_TYPE is tug we just push the images to the defined docker registry and create a clone
# of ourselves and push it into `lagoon-tug` image which is then executed in the destination openshift
# If though this is the actual tug deployment in the destination openshift, we don't run this
if [[ $DEPLOY_TYPE == "tug" && ! $THIS_IS_TUG == "true" ]]; then
echo "TODO: lagoon-tug is not implemented yet in kubernetes"
exit 1
. /kubectl-build-deploy/tug/tug-build-push.sh

# exit here, we are done
exit
fi

##############################################
### RUN PRE-ROLLOUT tasks defined in .lagoon.yml
##############################################
Expand Down Expand Up @@ -1046,29 +1034,7 @@ yq write -i -- /kubectl-build-deploy/values.yaml 'configMapSha' $CONFIG_MAP_SHA
### PUSH IMAGES TO OPENSHIFT REGISTRY
##############################################

if [[ $THIS_IS_TUG == "true" ]]; then
# TODO: lagoon-tug is not implemented yet in kubernetes
echo "lagoon-tug is not implemented yet in kubernetes"
exit 1
# Allow to disable registry auth
if [ ! "${TUG_SKIP_REGISTRY_AUTH}" == "true" ]; then
# This adds the defined credentials to the serviceaccount/default so that the deployments can pull from the remote registry
if kubectl --insecure-skip-tls-verify -n ${NAMESPACE} get secret tug-registry 2> /dev/null; then
kubectl --insecure-skip-tls-verify -n ${NAMESPACE} delete secret tug-registry
fi

kubectl --insecure-skip-tls-verify -n ${NAMESPACE} secrets new-dockercfg tug-registry --docker-server="${TUG_REGISTRY}" --docker-username="${TUG_REGISTRY_USERNAME}" --docker-password="${TUG_REGISTRY_PASSWORD}" --docker-email="${TUG_REGISTRY_USERNAME}"
kubectl --insecure-skip-tls-verify -n ${NAMESPACE} secrets add serviceaccount/default secrets/tug-registry --for=pull
fi

# Import all remote Images into ImageStreams
readarray -t TUG_IMAGES < /kubectl-build-deploy/tug/images
for TUG_IMAGE in "${TUG_IMAGES[@]}"
do
kubectl --insecure-skip-tls-verify -n ${NAMESPACE} tag --source=docker "${TUG_REGISTRY}/${TUG_REGISTRY_REPOSITORY}/${TUG_IMAGE_PREFIX}${TUG_IMAGE}:${SAFE_BRANCH}" "${TUG_IMAGE}:latest"
done

elif [ "$BUILD_TYPE" == "pullrequest" ] || [ "$BUILD_TYPE" == "branch" ]; then
if [ "$BUILD_TYPE" == "pullrequest" ] || [ "$BUILD_TYPE" == "branch" ]; then

# All images that should be pulled are copied to the harbor registry
for IMAGE_NAME in "${!IMAGES_PULL[@]}"
Expand Down Expand Up @@ -1212,36 +1178,7 @@ do
yq write -i --tag '!!str' -- /kubectl-build-deploy/${SERVICE_NAME}-values.yaml 'inPodCronjobs' ''
fi

#OVERRIDE_TEMPLATE=$(cat $DOCKER_COMPOSE_YAML | shyaml get-value services.$COMPOSE_SERVICE.labels.lagoon\\.template false)
#ENVIRONMENT_OVERRIDE_TEMPLATE=$(cat .lagoon.yml | shyaml get-value environments.${BRANCH//./\\.}.templates.$SERVICE_NAME false)
#if [[ "${OVERRIDE_TEMPLATE}" == "false" && "${ENVIRONMENT_OVERRIDE_TEMPLATE}" == "false" ]]; then # No custom template defined in docker-compose or .lagoon.yml, using the given service ones
# Generate deployment if service type defines it
. /kubectl-build-deploy/scripts/exec-kubectl-resources-with-images.sh

# # Generate statefulset if service type defines it
# OPENSHIFT_STATEFULSET_TEMPLATE="/kubectl-build-deploy/openshift-templates/${SERVICE_TYPE}/statefulset.yml"
# if [ -f $OPENSHIFT_STATEFULSET_TEMPLATE ]; then
# OPENSHIFT_TEMPLATE=$OPENSHIFT_STATEFULSET_TEMPLATE
# . /kubectl-build-deploy/scripts/exec-kubernetes-resources-with-images.sh
# fi
# elif [[ "${ENVIRONMENT_OVERRIDE_TEMPLATE}" != "false" ]]; then # custom template defined for this service in .lagoon.yml, trying to use it

# OPENSHIFT_TEMPLATE=$ENVIRONMENT_OVERRIDE_TEMPLATE
# if [ ! -f $OPENSHIFT_TEMPLATE ]; then
# echo "defined template $OPENSHIFT_TEMPLATE for service $SERVICE_TYPE in .lagoon.yml not found"; exit 1;
# else
# . /kubectl-build-deploy/scripts/exec-kubernetes-resources-with-images.sh
# fi
# elif [[ "${OVERRIDE_TEMPLATE}" != "false" ]]; then # custom template defined for this service in docker-compose, trying to use it

# OPENSHIFT_TEMPLATE=$OVERRIDE_TEMPLATE
# if [ ! -f $OPENSHIFT_TEMPLATE ]; then
# echo "defined template $OPENSHIFT_TEMPLATE for service $SERVICE_TYPE in $DOCKER_COMPOSE_YAML not found"; exit 1;
# else
# . /kubectl-build-deploy/scripts/exec-kubernetes-resources-with-images.sh
# fi
#fi

. /kubectl-build-deploy/scripts/exec-kubectl-resources-with-images.sh

done

Expand Down Expand Up @@ -1282,27 +1219,7 @@ do
SERVICE_ROLLOUT_TYPE=$ENVIRONMENT_SERVICE_ROLLOUT_TYPE
fi

if [ $SERVICE_TYPE == "elasticsearch-cluster" ]; then

STATEFULSET="${SERVICE_NAME}"
. /kubectl-build-deploy/scripts/exec-monitor-statefulset.sh

elif [ $SERVICE_TYPE == "rabbitmq-cluster" ]; then

STATEFULSET="${SERVICE_NAME}"
. /kubectl-build-deploy/scripts/exec-monitor-statefulset.sh

elif [ $SERVICE_ROLLOUT_TYPE == "statefulset" ]; then

STATEFULSET="${SERVICE_NAME}"
. /kubectl-build-deploy/scripts/exec-monitor-statefulset.sh

elif [ $SERVICE_ROLLOUT_TYPE == "deamonset" ]; then

DAEMONSET="${SERVICE_NAME}"
. /kubectl-build-deploy/scripts/exec-monitor-deamonset.sh

elif [ $SERVICE_TYPE == "mariadb-dbaas" ]; then
if [ $SERVICE_TYPE == "mariadb-dbaas" ]; then

echo "nothing to monitor for $SERVICE_TYPE"

Expand Down
25 changes: 0 additions & 25 deletions images/kubectl-build-deploy-dind/build-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ if [ ! -z ${INTERNAL_REGISTRY_URL} ] && [ ! -z ${INTERNAL_REGISTRY_USERNAME} ] &
echo "docker login -u '${INTERNAL_REGISTRY_USERNAME}' -p '${INTERNAL_REGISTRY_PASSWORD}' ${INTERNAL_REGISTRY_URL}" | /bin/bash
kubectl create secret docker-registry lagoon-internal-registry-secret --docker-server=${INTERNAL_REGISTRY_URL} --docker-username=${INTERNAL_REGISTRY_USERNAME} --docker-password=${INTERNAL_REGISTRY_PASSWORD} --dry-run -o yaml | kubectl apply -f -
REGISTRY_SECRETS+=("lagoon-internal-registry-secret")
#docker login "-u '{$INTERNAL_REGISTRY_USERNAME}' -p '{$INTERNAL_REGISTRY_PASSWORD}' '{$INTERNAL_REGISTRY_URL}'"
REGISTRY=$INTERNAL_REGISTRY_URL # This will handle pointing Lagoon at the correct registry for non local builds
#REGISTRY_REPOSITORY=$NAMESPACE
# If we go with a different naming scheme, we can inject that here?
#else
# DOCKER_REGISTRY_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
# docker login -u=jenkins -p="${DOCKER_REGISTRY_TOKEN}" ${REGISTRY}
fi

##############################################
Expand Down Expand Up @@ -128,23 +122,4 @@ done

set -x

ADDITIONAL_YAMLS=($(cat .lagoon.yml | shyaml keys additional-yaml || echo ""))

for ADDITIONAL_YAML in "${ADDITIONAL_YAMLS[@]}"
do
ADDITIONAL_YAML_PATH=$(cat .lagoon.yml | shyaml get-value additional-yaml.$ADDITIONAL_YAML.path false)
if [ $ADDITIONAL_YAML_PATH == "false" ]; then
echo "No 'path' defined for additional yaml $ADDITIONAL_YAML"; exit 1;
fi

if [ ! -f $ADDITIONAL_YAML_PATH ]; then
echo "$ADDITIONAL_YAML_PATH for additional yaml $ADDITIONAL_YAML not found"; exit 1;
fi

ADDITIONAL_YAML_COMMAND=$(cat .lagoon.yml | shyaml get-value additional-yaml.$ADDITIONAL_YAML.command apply)
ADDITIONAL_YAML_IGNORE_ERROR=$(cat .lagoon.yml | shyaml get-value additional-yaml.$ADDITIONAL_YAML.ignore_error false)
ADDITIONAL_YAML_IGNORE_ERROR="${ADDITIONAL_YAML_IGNORE_ERROR,,}" # convert to lowercase, as shyaml returns "True" if the yaml is set to "true"
. /kubectl-build-deploy/scripts/exec-additional-yaml.sh
done

. /kubectl-build-deploy/build-deploy-docker-compose.sh
12 changes: 0 additions & 12 deletions images/kubectl-build-deploy-dind/scripts/exec-additional-yaml.sh

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

66 changes: 0 additions & 66 deletions images/kubectl-build-deploy-dind/scripts/exec-monitor-daemonset.sh

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2823f93

Please sign in to comment.