From 597d3b32b061d85e98a174fc4e06bb662188493a Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Fri, 23 Nov 2018 07:00:59 +0000 Subject: [PATCH] Publish Docker image --- .circleci/config.yml | 74 +++++++++++++++++++++----------------------- Dockerfile | 15 +++++---- Dockerfile.test | 7 ----- 3 files changed, 43 insertions(+), 53 deletions(-) delete mode 100644 Dockerfile.test diff --git a/.circleci/config.yml b/.circleci/config.yml index b5b6e63..a34e874 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,12 @@ version: 2 +workflows: + version: 2 + all: + jobs: + - build + - docker: + requires: + - build jobs: build: docker: @@ -6,48 +14,38 @@ jobs: working_directory: /go/src/github.com/raviqqe/liche steps: - checkout - - setup_remote_docker - - run: - name: Setup - command: | - apt -y update --fix-missing - apt -y install rake - apt -y install bundler rake - - run: - name: Dependencies - command: rake deps - - run: - name: Lint - command: rake lint - - run: - name: Unit Test - command: | - rake unit_test - curl -sSL https://codecov.io/bash | bash - - run: - name: Integration Test - command: rake integration_test - - run: - name: Build - command: rake build - - run: - name: Install - command: rake install + - run: | + apt -y update --fix-missing + apt -y install bundler rake + - run: rake deps + - run: rake lint + - run: rake build + - run: rake unit_test + - run: curl -sSL https://codecov.io/bash | bash + - run: rake integration_test + - run: rake install + - run: ./liche --version > version - persist_to_workspace: root: . - paths: [bin/liche, Dockerfile.test] - + paths: + - version docker: docker: - - image: docker:17.05.0-ce-git + - image: docker:17 steps: - - attach_workspace: { at: . } - setup_remote_docker - - run: docker build -f Dockerfile.test -t raviqqe/docker-liche:latest . + - checkout + - attach_workspace: + at: . + - run: | + name=$DOCKER_USER/liche + version=$(cat version) -workflows: - version: 2 - build: - jobs: - - build - - docker: { requires: [build] } + if [ $CIRCLE_BRANCH = master -a $version != $(docker run $name --version) ] + then + docker build -t $name . + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + docker push $name + docker tag $name $name:$version + docker push $name:$version + fi diff --git a/Dockerfile b/Dockerfile index 9ff7dfd..6343411 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ -FROM golang:latest -RUN CGO_ENABLED=0 GOOS=linux go get -u github.com/raviqqe/liche +FROM golang +COPY . /go/src/github.com/raviqqe/liche +WORKDIR /go/src/github.com/raviqqe/liche +RUN CGO_ENABLED=0 GOOS=linux go get . -FROM alpine:latest +FROM alpine RUN apk --no-cache add ca-certificates -WORKDIR /root/ -COPY --from=0 /go/bin/liche /go/bin/liche -ENV PATH "/go/bin:$PATH" -RUN liche --help -CMD liche +COPY --from=0 /go/bin/liche /liche +ENTRYPOINT ["/liche"] diff --git a/Dockerfile.test b/Dockerfile.test deleted file mode 100644 index f03dcee..0000000 --- a/Dockerfile.test +++ /dev/null @@ -1,7 +0,0 @@ -FROM alpine:latest -RUN apk --no-cache add ca-certificates -WORKDIR /root/ -ADD bin/liche /go/bin/liche -ENV PATH "/go/bin:$PATH" -RUN liche --help -CMD liche