From d1f03ffd0ed73d1c279f852af5d12ceb1a2a99c2 Mon Sep 17 00:00:00 2001 From: Liang Chen Date: Sat, 26 Feb 2022 11:49:56 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=9B=B4=E6=96=B0CI=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9E=84=E5=BB=BAtag=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .circleci/config.yml | 87 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dea2665..3488b9d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,13 @@ version: 2.1 +executors: + docker-publisher: + docker: + - image: docker:19 + auth: + username: $DOCKER_USER + password: $DOCKER_PASS + jobs: checkout_code: docker: @@ -9,11 +17,6 @@ jobs: name: Avoid hosts unknown for github command: | mkdir -p ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config - - run: - name: List Files - command: | - pwd - ls -al - checkout - run: name: List Files @@ -24,27 +27,18 @@ jobs: root: /root paths: - project + build_image: - docker: - - image: docker:19 + executor: docker-publisher steps: - - setup_remote_docker: - version: 19.03.13 - attach_workspace: at: /root + - setup_remote_docker: + version: 19.03.13 - run: name: Docker Login command: | echo "$DOCKER_PASS" | docker login --username $DOCKER_USER --password-stdin - - run: - name: Avoid hosts unknown for github - command: | - mkdir -p ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config - - run: - name: List Files - command: | - pwd - ls -al - run: name: Build Image command: | @@ -52,6 +46,11 @@ jobs: docker build -f $(pwd)/build/Centos6-DNF/Dockerfile -t 1995chen/dnf:centos6-${CIRCLE_SHA1: 0: 7} $(pwd) docker tag 1995chen/dnf:centos7-${CIRCLE_SHA1: 0: 7} 1995chen/dnf:centos7-latest docker tag 1995chen/dnf:centos6-${CIRCLE_SHA1: 0: 7} 1995chen/dnf:centos6-latest + - run: + name: Archive Docker image + command: | + docker save -o base-centos6.tar 1995chen/dnf:centos6-${CIRCLE_SHA1: 0: 7} + docker save -o base-centos7.tar 1995chen/dnf:centos7-${CIRCLE_SHA1: 0: 7} - run: name: Push Image command: | @@ -59,11 +58,61 @@ jobs: docker push 1995chen/dnf:centos7-${CIRCLE_SHA1: 0: 7} docker push 1995chen/dnf:centos6-latest docker push 1995chen/dnf:centos7-latest + # 持久化root目录 + - persist_to_workspace: + root: /root + paths: + - project + + tag_release_image: + executor: docker-publisher + steps: + - attach_workspace: + at: /root + - setup_remote_docker: + version: 19.03.13 + - run: + name: Load archived Docker image + command: | + docker load -i base-centos6.tar + docker load -i base-centos7.tar + - run: + name: Tag & Push Image + command: | + echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin + docker tag 1995chen/dnf:centos6-${CIRCLE_SHA1: 0: 7} 1995chen/dnf:centos6-$CIRCLE_TAG + docker push 1995chen/dnf:centos6-$CIRCLE_TAG + docker tag 1995chen/dnf:centos7-${CIRCLE_SHA1: 0: 7} 1995chen/dnf:centos7-$CIRCLE_TAG + docker push 1995chen/dnf:centos7-$CIRCLE_TAG workflows: - build_dnf_image: + staging: jobs: - checkout_code - build_image: requires: - checkout_code + + production: + jobs: + - checkout_code: + # this yaml anchor is setting these values to "filters-production" + filters: &filters-production + branches: + ignore: /.*/ + tags: + only: /.*/ + - build_image: + requires: + - checkout_code + context: + - docker-hub-creds + filters: + <<: *filters-production + - tag_release_image: + requires: + - build_image + context: + - docker-hub-creds + filters: + <<: *filters-production