canary_fe/.gitlab-ci.yml
2020-12-28 20:37:39 +08:00

105 lines
2.2 KiB
YAML

variables:
DOCKER_REGION: "registry.cn-qingdao.aliyuncs.com"
DOCKER_NAMESPACE: "lacus"
DOCKER_USERNAME: "rainsun20170129"
DOCKER_PASSWORD: "100200300Wdy*"
APP_NAME: "canary_fe"
IMAGE_NAME: "$DOCKER_REGION/$DOCKER_NAMESPACE/$APP_NAME:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA"
DOCKER_FILE_PATH: "./Dockerfile"
stages:
- build
- test
- clear
- deploy
- clear_test
build:
stage: build
image: docker:latest
services:
- name: docker:dind
tags:
- dockerbase
script:
- ls -a
- docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION}
- docker build -t ${IMAGE_NAME} -f ${DOCKER_FILE_PATH} .
- docker push ${IMAGE_NAME}
- docker rmi ${IMAGE_NAME}
test:
stage: test
tags:
- dockerbase
script:
- ls -a
- docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION}
- docker pull ${IMAGE_NAME}
- docker run -d --name ${APP_NAME} -p 8080:80 ${IMAGE_NAME}
cache:
policy: pull
clear_master:
stage: clear
tags:
- ali2
only:
- master
script:
- docker stop pan_${APP_NAME}
- docker rm pan_${APP_NAME}
allow_failure: true
when: manual
deploy_master:
stage: deploy
tags:
- ali2
only:
- master
script:
- ls -a
- docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION}
- docker pull ${IMAGE_NAME}
- docker run -d --name pan_${APP_NAME} -p 127.0.0.1:5005:80 ${IMAGE_NAME}
cache:
policy: pull
when: manual
clear_outside:
stage: clear
tags:
- ali2
only:
- outside
script:
- docker stop ${APP_NAME}
- docker rm ${APP_NAME}
allow_failure: true
when: manual
deploy_outside:
stage: deploy
tags:
- ali2
only:
- outside
script:
- ls -a
- docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION}
- docker pull ${IMAGE_NAME}
- docker run -d --name ${APP_NAME} -p 127.0.0.1:5004:80 ${IMAGE_NAME}
cache:
policy: pull
when: manual
clear_test:
stage: clear_test
tags:
- dockerbase
script:
- docker stop ${APP_NAME}
- docker rm ${APP_NAME}
allow_failure: true
when: manual