Skip to content

Instantly share code, notes, and snippets.

@alexeyzimarev
Last active November 18, 2022 11:49
Show Gist options
  • Save alexeyzimarev/39b060a226a922c208564325e5cf21cf to your computer and use it in GitHub Desktop.
Save alexeyzimarev/39b060a226a922c208564325e5cf21cf to your computer and use it in GitHub Desktop.
variables:
KUBERNETES_VERSION: 1.18.4
HELM_VERSION: 2.16.9
ROLLOUT_RESOURCE_TYPE: deployment
DOTNET_SDK_VERSION: 3.1.301-alpine3.12
DOTNET_RUNTIME_VERSION: 3.1.5-alpine3.12
.deployment:
image: registry.ubiquitous.no/gitlab/auto-deploy-image:latest
allow_failure: false
script:
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy ensure_namespace
- auto-deploy create_secret
- auto-deploy deploy
- auto-deploy persist_environment_url
only:
refs:
- master
.version:
image: docker:git
script:
- set_version
artifacts:
paths:
- version.sh
.kanikocache:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- /kaniko/warmer --cache-dir=./cache --image=mcr.microsoft.com/dotnet/core/aspnet:$DOTNET_RUNTIME_VERSION --image=mcr.microsoft.com/dotnet/core/sdk:$DOTNET_SDK_VERSION
stage: prebuild
cache:
key: kaniko-cache
paths:
- ./cache/
.dockerbuild:
image:
name: gcr.io/kaniko-project/executor:debug-v0.18.0
entrypoint: [""]
script:
- use_version
- setup_docker
- build ${repo_root-.} $repo_image
only:
- branches
cache:
key: kaniko-cache
paths:
- ./cache/
artifacts:
paths:
- docker-image.sh
.auto_devops: &auto_devops |
# Auto DevOps variables and functions
[[ "$TRACE" ]] && set -x
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG
export CI_APPLICATION_TAG=$CI_COMMIT_SHA
export CI_CONTAINER_NAME=ci_job_build_${CI_JOB_ID}
export TILLER_NAMESPACE=$KUBE_NAMESPACE
# Extract "MAJOR.MINOR" from CI_SERVER_VERSION and generate "MAJOR-MINOR-stable" for Security Products
export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
function build() {
mkdir -p ./cache && mv ./cache $(pwd)
echo "{\"auths\":{" > /kaniko/.docker/config.json
echo "\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}" >> /kaniko/.docker/config.json
if [ -n "$CACHE_REGISTRY" ]; then
echo ",\"$CACHE_REGISTRY\":{\"username\":\"$CACHE_REGISTRY_USER\",\"password\":\"$CACHE_REGISTRY_PASSWORD\"}" >> /kaniko/.docker/config.json
fi
echo "}}" >> /kaniko/.docker/config.json
cat /kaniko/.docker/config.json
echo ""
repo_root=${1-.}
docker_repo=$CI_APPLICATION_REPOSITORY
if [ -n "$2" ]; then
docker_repo=$CI_REGISTRY/$CI_PROJECT_PATH/$CI_BUILD_REF_SLUG/$2
fi
echo "Building Dockerfile in $repo_root to $docker_repo"
if [ "$repo_root" == "." ]; then
dockerfilePath=$CI_PROJECT_DIR
else
dockerfilePath=$CI_PROJECT_DIR/$repo_root
fi
/kaniko/executor --cache=true \
--cache-dir=$(pwd)/cache \
--cache-repo=$CACHE_REGISTRY/$CI_PROJECT_PATH/cache \
--context $CI_PROJECT_DIR --dockerfile $dockerfilePath/Dockerfile \
--destination $docker_repo:$CI_APPLICATION_TAG \
--destination $docker_repo:latest \
--build-arg DOTNET_SDK_VERSION="$DOTNET_SDK_VERSION" \
--build-arg DOTNET_RUNTIME_VERSION="$DOTNET_RUNTIME_VERSION" \
|| /kaniko/executor \
--context $CI_PROJECT_DIR --dockerfile $dockerfilePath/Dockerfile \
--destination $docker_repo:$CI_APPLICATION_TAG \
--destination $docker_repo:latest
echo "export CI_APPLICATION_REPOSITORY=$docker_repo" > docker-image.sh
}
function setup_docker() {
if ! docker info &>/dev/null; then
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
fi
}
set_version() {
cd ${1-.}
echo "export APPLICATION_VERSION=\"$(git describe --tags | sed 's/-g[a-z0-9]\{7\}//')\"" > version.sh
}
use_version() {
[ -f version.sh ] && source ./version.sh
tag=${APPLICATION_VERSION/+/-}
export CI_APPLICATION_TAG=${tag:-$CI_APPLICATION_TAG}
}
before_script:
- *auto_devops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment