Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active August 18, 2021 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/b5006b663bcd3de49f13faba2ef3aa53 to your computer and use it in GitHub Desktop.
Save michaellwest/b5006b663bcd3de49f13faba2ef3aa53 to your computer and use it in GitHub Desktop.
Example using GitLab to build a custom .net 5.0 SDK image using kaniko. We use kaniko to build the container in runtime this makes it so the building doesn’t require access to the docker daemon. This allows to utilize the normal runners and don’t have to enable privileged mode in docker.
stages:
- build:dotnet
default:
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
.job_template:
script: &script_definition
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor -c $CI_PROJECT_DIR -f $DOCKER_FILE -d $CI_REGISTRY_IMAGE:$CI_JOB_NAME --build-arg USERNAME=$TFS_USERNAME --build-arg PASSWORD=$TFS_PASSWORD
rules: &rules_definition
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
# Job Templates
.build_and_deploy_dotnet: &build_and_deploy_dotnet
stage: build:dotnet
script: *script_definition
rules: *rules_definition
# Builds
dotnet-5:
<<: *build_and_deploy_dotnet
variables:
DOCKER_FILE: $CI_PROJECT_DIR/src/dotnet/Dockerfile.dotnet-sdk5.0
# escape=`
FROM mcr.microsoft.com/dotnet/sdk:5.0
COPY deploy.ps1 /deploy.ps1
COPY remote.ps1 /remote.ps1
COPY replace.ps1 /replace.ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment