bird-lg-go/.circleci/config.yml
Lan Tian 007b66e036
Revert "general: remove build for all arch but amd64"
This reverts commit 1c3d9ec5948826fac1a6f87656291e24b7662fff.
2021-03-06 20:52:04 +08:00

81 lines
2.7 KiB
YAML

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/xddxdd/bird-lg-go
steps:
- checkout
- run: go get -v -t -d ./...
- run: go get -u github.com/kevinburke/go-bindata/...
- run: cd frontend && go generate
- run: go test -v ./...
deploy:
docker:
- image: circleci/golang:1.15
working_directory: /go/src/github.com/xddxdd/bird-lg-go
parameters:
image_arch:
type: string
program:
type: string
steps:
- checkout
- setup_remote_docker:
version: 19.03.13
- run:
name: Build Docker image
environment:
IMAGE_ARCH: << parameters.image_arch >>
PROGRAM: << parameters.program >>
BUILD_ID: << pipeline.number >>
command: |
if [ "$PROGRAM" = "frontend" ]; then
export IMAGE_NAME="bird-lg-go"
else
export IMAGE_NAME="bird-lgproxy-go"
fi
export IMAGE_ARCH_GO=$IMAGE_ARCH
if [ "$IMAGE_ARCH" = "i386" ]; then export IMAGE_ARCH_GO="386" ; fi
if [ "$IMAGE_ARCH" = "arm32v7" ]; then export IMAGE_ARCH_GO="arm" ; fi
if [ "$IMAGE_ARCH" = "arm64v8" ]; then export IMAGE_ARCH_GO="arm64"; fi
docker build \
--build-arg IMAGE_ARCH=$IMAGE_ARCH_GO \
-t $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH \
-f $PROGRAM/Dockerfile \
$PROGRAM
echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
# Tag image :{arch} and :{arch}-build{build number}
docker push $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH
docker tag $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH-circleci-build$BUILD_ID
docker push $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH-circleci-build$BUILD_ID
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 push $DOCKER_USERNAME/$IMAGE_NAME:latest
docker tag $DOCKER_USERNAME/$IMAGE_NAME:$IMAGE_ARCH $DOCKER_USERNAME/$IMAGE_NAME:circleci-build$BUILD_ID
docker push $DOCKER_USERNAME/$IMAGE_NAME:latest
fi