From ef2dd1949a413266c34868dcfccd63b5255ae41c Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Sat, 24 Aug 2019 19:14:30 +0530 Subject: [PATCH] build(docker): build docker image and push to hub (#414) * build(docker): build docker image and push to hub Signed-off-by: Ameya Shenoy * build(docker): trigger only on new release Signed-off-by: Ameya Shenoy --- .circleci/config.yml | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index acb8358..49c3c5f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,11 @@ -version: 2 +version: 2.1 + +executors: + docker-publisher: + environment: + IMAGE_NAME: bukuserver/bukuserver + docker: + - image: circleci/buildpack-deps:stretch test-template: &test-template working_directory: ~/Buku @@ -53,8 +60,39 @@ jobs: go get github.com/tcnksm/ghr ghr -t ${GITHUB_API_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace ${CIRCLE_TAG} ./dist/ + build-docker-image: + executor: docker-publisher + steps: + - checkout + - setup_remote_docker + - run: + name: Build Docker image + command: docker build -t $IMAGE_NAME:latest . + - run: + name: Archive Docker image + command: docker save -o image.tar $IMAGE_NAME + - persist_to_workspace: + root: . + paths: + - ./image.tar + + publish-on-docker-hub: + executor: docker-publisher + steps: + - attach_workspace: + at: /tmp/workspace + - setup_remote_docker + - run: + name: Load archived Docker image + command: docker load -i /tmp/workspace/image.tar + - run: + name: Publish Docker Image to Docker Hub + command: | + echo "${DOCKERHUB_PASS}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin + docker push ${IMAGE_NAME}:latest + workflows: - version: 2 + version: 2.1 test: jobs: &all-tests @@ -80,3 +118,21 @@ workflows: only: /^v.*/ branches: ignore: /.*/ + + publish-docker-image: + jobs: + - build-docker-image: + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ + - publish-on-docker-hub: + requires: + - build-docker-image + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ +