From ee7cc1675bb489e41110a2c513558f38418dbaeb Mon Sep 17 00:00:00 2001 From: Yuhui Xu Date: Wed, 13 Jan 2021 23:37:32 +0800 Subject: [PATCH 1/2] Add .circleci/config.yml --- .circleci/config.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..fbdabba --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,11 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.15 + + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + steps: + - checkout + - run: go get -v -t -d ./... + - run: go test -v ./... From 9f934ca53cfa8d02cd1f253a05b35bc8c9f76aa8 Mon Sep 17 00:00:00 2001 From: Yuhui Xu Date: Wed, 13 Jan 2021 23:58:44 +0800 Subject: [PATCH 2/2] Updated config.yml --- .circleci/config.yml | 59 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fbdabba..8d1af1b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,11 +1,66 @@ -version: 2 +version: 2.1 + +workflows: + docker: + jobs: + - build + - deploy: + context: + - docker + requires: + - build + matrix: + parameters: + program: [frontend, proxy] + image_arch: [i386, amd64, arm32v7, arm64v8, ppc64le, s390x] + filters: + branches: + only: master + jobs: build: docker: - image: circleci/golang:1.15 - working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} steps: - checkout - run: go get -v -t -d ./... - run: go test -v ./... + deploy: + docker: + - image: circleci/golang:1.15 + working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}} + parameters: + image_arch: + type: string + program: + type: string + steps: + - checkout + - run: + name: Build Docker image + environment: + IMAGE_ARCH: << parameters.image_arch >> + PROGRAM: << parameters.program >> + command: | + if [ "$PROGRAM" = "frontend" ]; then + export IMAGE_NAME="bird-lg-go" + else + export IMAGE_NAME="bird-lgproxy-go" + fi + + docker build \ + --build-arg IMAGE_ARCH=$IMAGE_ARCH \ + -t $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH \ + -f $PROGRAM/Dockerfile \ + $PROGRAM + + # Tag image :{arch} and :{arch}-build{build number} + docker tag $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH-build$CIRCLE_BUILD_NUM + if [ "$IMAGE_ARCH" = "amd64" ]; then + # Tag as latest for amd64 images + docker tag $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH $DOCKER_USERNAME/$IMAGE_NAME:latest + docker tag $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH $DOCKER_USERNAME/$IMAGE_NAME:build$CIRCLE_BUILD_NUM + fi + + docker push $DOCKER_USERNAME/$IMAGE_NAME \ No newline at end of file