大致架构:
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文章来源:https://www.toymoban.com/news/detail-545774.html
文章来源地址https://www.toymoban.com/news/detail-545774.html
到了这里,关于gitlab ci/cd+harbor+k8s实现一键部署(python项目)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!