Skip to content

Commit

Permalink
docker image cron update
Browse files Browse the repository at this point in the history
This PR contains changes to travis and Makefile configs for periodical docker image update using travis ci cron jobs

Behavior
1) if TRAVIS_EVENT_TYPE is cron then
  a) try to get tag using `$( git describe --exact-match "$(git rev-parse HEAD)`
  b) if tag is not empty run make push-drivers
  c) in push-drivers: if TRAVIS_EVENT_TYPE is cron pull base bblfshd image instead of rebuilding it from the scratch
2) else build as always

Changes to docker tags:
- timestamp is added to the version tag, so the final image will look like bblfsh/bblfshd:v2.14.0-drivers-2019-10-04

Problems:
- afaik deploy will not be triggered on cron job because tags are not accessible with this event type travis-ci/travis-ci#8146 ... cannot check it on practice thus 1.a) workaround has been implemented as suggested travis-ci/travis-ci#8146 (comment)

closes #309

Signed-off-by: lwsanty <[email protected]>

change tag datetime to date only

Signed-off-by: lwsanty <[email protected]>
  • Loading branch information
lwsanty authored and dennwc committed Oct 8, 2019
1 parent bf7f45b commit 49ac0e4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ before_install:
- popd
- make dependencies

# there's a workaround here because there will be no tags in cron https://github.com/travis-ci/travis-ci/issues/8146
script:
- make test-coverage
- |
if [ "${TRAVIS_EVENT_TYPE}" = "cron" ]; then
if CRON_TAG="$( git describe --exact-match "$(git rev-parse HEAD)" 2>/dev/null )"; then
make push-drivers
fi
fi
after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GIT_COMMIT=$(shell git rev-parse HEAD | cut -c1-7)
GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "-dirty" || true)
DEV_PREFIX := dev
VERSION ?= $(DEV_PREFIX)-$(GIT_COMMIT)$(GIT_DIRTY)
TAG_DATE=$(shell date +%F)


# Go parameters
Expand All @@ -52,6 +53,10 @@ ifneq ($(origin TRAVIS_TAG), undefined)
VERSION := $(TRAVIS_TAG)
endif

ifneq ($(origin CRON_TAG), undefined)
VERSION := $(CRON_TAG)
endif

# Build
LDFLAGS = -X main.version=$(VERSION) -X main.build=$(BUILD)

Expand All @@ -62,6 +67,7 @@ DOCKER_RUN = $(DOCKER_CMD) run --rm
DOCKER_BUILD_IMAGE = bblfshd-build
DOCKER_TAG ?= $(DOCKER_CMD) tag
DOCKER_PUSH ?= $(DOCKER_CMD) push
DOCKER_PULL ?= $(DOCKER_CMD) pull

# escape_docker_tag escape colon char to allow use a docker tag as rule
define escape_docker_tag
Expand Down Expand Up @@ -125,8 +131,14 @@ build-fixture:
docker build -t $(DOCKER_IMAGE_FIXTURE) .


build-drivers: build
docker build -f Dockerfile.drivers --build-arg TAG="$(VERSION)" -t "$(call unescape_docker_tag,$(DOCKER_IMAGE_VERSIONED))-drivers" .
build-drivers:
ifeq ($(TRAVIS_EVENT_TYPE), cron)
$(DOCKER_PULL) $(DOCKER_IMAGE):$(VERSION)
else
make build
endif
echo $(DOCKER_IMAGE):$(VERSION)
docker build -f Dockerfile.drivers --build-arg TAG="$(VERSION)" -t "$(DOCKER_IMAGE):$(VERSION)-drivers-$(TAG_DATE)" .

clean:
rm -rf $(BUILD_PATH); \
Expand All @@ -153,9 +165,9 @@ push-drivers: build-drivers
$(DOCKER_CMD) login -u="$$DOCKER_USERNAME" -p="$$DOCKER_PASSWORD"; \
fi;

$(DOCKER_PUSH) "$(call unescape_docker_tag,$(DOCKER_IMAGE_VERSIONED))-drivers"
$(DOCKER_PUSH) "$(call unescape_docker_tag,$(DOCKER_IMAGE_VERSIONED))-drivers-$(TAG_DATE)"
@if [ "$$TRAVIS_TAG" != "" ]; then \
$(DOCKER_TAG) "$(call unescape_docker_tag,$(DOCKER_IMAGE_VERSIONED))-drivers" \
$(DOCKER_TAG) "$(call unescape_docker_tag,$(DOCKER_IMAGE_VERSIONED))-drivers-$(TAG_DATE)" \
$(call unescape_docker_tag,$(DOCKER_IMAGE)):latest-drivers; \
$(DOCKER_PUSH) $(call unescape_docker_tag,$(DOCKER_IMAGE):latest-drivers); \
fi;
Expand Down

0 comments on commit 49ac0e4

Please sign in to comment.