Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kpango committed Jan 26, 2019
1 parent 5aae68e commit 3c9af71
Showing 1 changed file with 189 additions and 0 deletions.
189 changes: 189 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
alias:
default: &default
working_directory: /go/src/github.com/yahoojapan/garm
docker:
- image: circleci/buildpack-deps:latest
environment:
REPO_NAME: "kpango"
IMAGE_NAME: "dotfiles"
GITHUB_API: "https://api.github.com/"
DOCKER_USER: "kpango"
setup_remote_docker: &setup_remote_docker
version: 18.06.0-ce
docker_layer_caching: true

version: 2
jobs:
build:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- checkout
- run:
name: check docker version
command: |
docker version
- run:
name: docker image build
command: |
# env DOCKER_BUILDKIT=1 docker build -t ${REPO_NAME}/${IMAGE_NAME}:latest .
docker build -t ${REPO_NAME}/${IMAGE_NAME}:latest .
- run:
name: save image
command: |
docker image save ${REPO_NAME}/${IMAGE_NAME}:latest > ./docker-image.tar
- persist_to_workspace:
root: .
paths:
- .
publish_nightly:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- attach_workspace:
at: .
- run:
name: load image from tar
command: |
docker load -i ./docker-image.tar
- run:
name: tag to latest
command: |
docker tag ${REPO_NAME}/${IMAGE_NAME}:latest ${REPO_NAME}/${IMAGE_NAME}:nightly
- run:
name: docker login
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- run:
name: push image to registory
command: |
docker push ${REPO_NAME}/${IMAGE_NAME}
publish:
<<: *default
steps:
- setup_remote_docker: *setup_remote_docker
- attach_workspace:
at: .
- run:
name: load image from tar
command: |
docker load -i ./docker-image.tar
- run:
name: tag to latest
command: |
docker tag ${REPO_NAME}/${IMAGE_NAME}:latest ${REPO_NAME}/${IMAGE_NAME}:$CIRCLE_TAG
- run:
name: docker login
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
- run:
name: push image to registory
command: |
docker push ${REPO_NAME}/${IMAGE_NAME}
versioning:
<<: *default
steps:
- checkout
- run:
name: check
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
LAST_COMMIT=`git log -1 --pretty=%B`
VERSION=`git describe --abbrev=0 --tags`
touch ./.tag
if [ ! -z "`git diff $VERSION`" -o -z "$VERSION" ]; then
VERSION=${VERSION:-'0.0.0'}
MAJOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
MINOR="${VERSION%%.*}"; VERSION="${VERSION#*.}"
PATCH="${VERSION%%.*}"; VERSION="${VERSION#*.}"
if echo $LAST_COMMIT | grep "\[\(major\|MAJOR\)\]" > /dev/null; then
MAJOR=$((MAJOR+1))
echo "$MAJOR.0.0" > ./.tag
elif echo $LAST_COMMIT | grep "\[\(minor\|MINOR\)\]" > /dev/null; then
MINOR=$((MINOR+1))
echo "$MAJOR.$MINOR.0" > ./.tag
elif echo $LAST_COMMIT | grep "\[\(patch\|PATCH\)\]" > /dev/null; then
PATCH=$((PATCH+1))
echo "$MAJOR.$MINOR.$PATCH" > ./.tag
fi
fi
- persist_to_workspace:
root: .
paths:
- .
push:
<<: *default
steps:
- attach_workspace:
at: .
- run:
name: push tag and check PR body
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
TAG=`cat ./.tag`
if [ ! -z "$TAG" ]; then
echo $TAG
git tag $TAG
git push git@github.com:${REPO_NAME}/${IMAGE_NAME} --tags
fi
- persist_to_workspace:
root: .
paths:
- .
gh_release:
<<: *default
steps:
- attach_workspace:
at: .
- run:
name: release
command: |
mkdir -p $HOME/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
TAG=`cat ./.tag`
if [ ! -z "$TAG" ]; then
echo "Create release: ${TAG}"
curl -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" \
-X POST \
-d "{\"tag_name\": \"${TAG}\"}" \
${GITHUB_API}repos/${REPO_NAME}/${IMAGE_NAME}/releases
fi
workflows:
version: 2
build:
jobs:
- build
- publish_nightly:
requires:
- build
filters:
branches:
only:
- master
- versioning:
filters:
branches:
only:
- master
- push:
requires:
- versioning
- gh_release:
requires:
- push
release:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /[0-9]+\.[0-9]+\.[0-9]+/
- publish:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /[0-9]+\.[0-9]+\.[0-9]+/

0 comments on commit 3c9af71

Please sign in to comment.