大致架构:
gitlab变量
使用 kaniko 构建 Docker 镜像
.gitlab-ci.yml
stages:
- test
- build
- deploy
variables:
DOCKERFILE: "Dockerfile2"
CONTAINER_IMAGE: "archeros/workspace/platform"
GIT_SSL_NO_VERIFY: "true"
before_script:
- echo "Start building ..."
after_script:
- echo "All job done"
test:
stage: test
script:
- echo "Unit testing ..."
.build_template: &build_definition
stage: build
image:
name: registry.harbor.com:441/mirror/gcr-io/kaniko-project/executor:debug
entrypoint: [""]
before_script:
- echo "$CI_REGISTRY"
- echo "$CI_REGISTRY_USER"
- echo "$CI_REGISTRY_PASSWORD"
- if [[ "$CI_REGISTRY_PORT" ]]; then REGISTRY_ADDRESS="$CI_REGISTRY:$CI_REGISTRY_PORT"; else REGISTRY_ADDRESS="$CI_REGISTRY"; fi
- echo "$CI_REGISTRY_IP $CI_REGISTRY" >> /etc/hosts
- echo "{\"auths\":{\"$REGISTRY_ADDRESS\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- echo "$CI_REGISTRY_CERTS" >> /kaniko/ssl/certs/ca-certificates.crt
- echo "$(ls -l)"
- echo "$(cat /etc/hosts)"
build_development:
<<: *build_definition
script:
- echo "$CI_PROJECT_DIR"
- echo "$CI_REGISTRY"
- echo "$REGISTRY_ADDRESS"
- echo "$CONTAINER_IMAGE"
- echo "$CI_COMMIT_SHORT_SHA"
- /kaniko/executor
--context $CI_PROJECT_DIR
--dockerfile $CI_PROJECT_DIR/$DOCKERFILE
--destination $REGISTRY_ADDRESS/$CONTAINER_IMAGE:$CI_COMMIT_SHORT_SHA
--destination $REGISTRY_ADDRESS/$CONTAINER_IMAGE:latest
only:
- test
except:
- tags
build_release:
<<: *build_definition
script:
- /kaniko/executor
--context $CI_PROJECT_DIR
--dockerfile $CI_PROJECT_DIR/$DOCKERFILE
--destination $REGISTRY_ADDRESS/$CONTAINER_IMAGE:$CI_COMMIT_TAG
--destination $REGISTRY_ADDRESS/$CONTAINER_IMAGE:latest
only:
- tags
deploy_development:
image:
name: registry.harbor.com:441/mirror/docker-hub/bitnami/kubectl:latest
entrypoint: [""]
stage: deploy
script:
- echo "Deploy to development kubernetes"
- if [[ "$CI_REGISTRY_PORT" ]]; then REGISTRY_ADDRESS="$CI_REGISTRY:$CI_REGISTRY_PORT"; else REGISTRY_ADDRESS="$CI_REGISTRY"; fi
- echo "$REGISTRY_ADDRESS"
- echo "$CONTAINER_IMAGE"
- echo "$CI_COMMIT_SHORT_SHA"
- kubectl set image deployment/workspace-platform workspace-platform=$REGISTRY_ADDRESS/$CONTAINER_IMAGE:$CI_COMMIT_SHORT_SHA
environment:
name: development
only:
- test
except:
- tags
如果仓库使用http