variables: DOCKER_REGION: "registry.cn-qingdao.aliyuncs.com" DOCKER_NAMESPACE: "lacus" DOCKER_USERNAME: "rainsun20170129" DOCKER_PASSWORD: "100200300Wdy*" APP_NAME: "blog" BUILD_IMAGE: "node:8-alpine" IMAGE_NAME: "$DOCKER_REGION/$DOCKER_NAMESPACE/$APP_NAME:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA" DOCKER_FILE_PATH: "./Dockerfile" stages: - install - compile - build - clear - deploy cache: key: ${CI_COMMIT_REF_SLUG} paths: - public/ - node_modules/ install: stage: install image: ${BUILD_IMAGE} tags: - dockerbase script: - ls -a - npm install -g cnpm --registry=https://registry.npm.taobao.org - cnpm install - ls -a rules: - changes: - package.json compile: stage: compile image: ${BUILD_IMAGE} tags: - dockerbase script: - ls -a - echo "开始打包Hexo博客" - hexo clean && hexo g - ls -a public/ - ls -a public/img 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} pveclear: stage: clear tags: - dockerbase only: - master script: - docker stop ${APP_NAME} - docker rm ${APP_NAME} allow_failure: true ali2clear: stage: clear tags: - ali2 only: - master script: - docker stop ${APP_NAME} - docker rm ${APP_NAME} allow_failure: true pvedeploy: stage: deploy tags: - dockerbase only: - master script: - ls -a - docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION} - docker pull ${IMAGE_NAME} - docker run -d --name ${APP_NAME} -p 5001:80 ${IMAGE_NAME} cache: policy: pull ali2deploy: 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 ${APP_NAME} -p 127.0.0.1:5001:80 ${IMAGE_NAME} cache: policy: pull