Skip to content

Commit

Permalink
ci: 更新CI支持构建tag镜像
Browse files Browse the repository at this point in the history
  • Loading branch information
1995chen committed Feb 26, 2022
1 parent db14ce7 commit d1f03ff
Showing 1 changed file with 68 additions and 19 deletions.
87 changes: 68 additions & 19 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -24,46 +27,92 @@ 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: |
docker build -f $(pwd)/build/Centos7-DNF/Dockerfile -t 1995chen/dnf:centos7-${CIRCLE_SHA1: 0: 7} $(pwd)
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: |
docker push 1995chen/dnf:centos6-${CIRCLE_SHA1: 0: 7}
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

0 comments on commit d1f03ff

Please sign in to comment.