Skip to content

Commit

Permalink
Merge 2aef2db into 318e8fd
Browse files Browse the repository at this point in the history
  • Loading branch information
bandesz committed Oct 31, 2016
2 parents 318e8fd + 2aef2db commit c34a382
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
44 changes: 20 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,18 @@ prepare-docker-build-image: ## Prepare the Docker builder image
mkdir -p ${PIP_ACCEL_CACHE}
make -C docker build-build-image

.PHONY: build-with-docker
build-with-docker: prepare-docker-build-image ## Build inside a Docker container
# FIXME: CIRCLECI=1 is an ugly hack because the coveralls-python library sends the PR link only this way
define run_test_container
mkdir -p cache/pip-accel
@docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-build" \
--name "${DOCKER_CONTAINER_PREFIX}-${1}" \
-v `pwd`:/var/project \
-v ${PIP_ACCEL_CACHE}:/var/project/cache/pip-accel \
-e UID=$(shell id -u) \
-e GID=$(shell id -g) \
-e GIT_COMMIT=${GIT_COMMIT} \
-e BUILD_NUMBER=${BUILD_NUMBER} \
-e BUILD_URL=${BUILD_URL} \
${DOCKER_BUILDER_IMAGE_NAME} \
make build

.PHONY: test-with-docker
test-with-docker: prepare-docker-build-image ## Run tests inside a Docker container
@docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-test" \
-v `pwd`:/var/project \
-e GIT_COMMIT=${GIT_COMMIT} \
-e BUILD_NUMBER=${BUILD_NUMBER} \
-e BUILD_URL=${BUILD_URL} \
${DOCKER_BUILDER_IMAGE_NAME} \
make test

# FIXME: CIRCLECI=1 is an ugly hack because the coveralls-python library sends the PR link only this way
.PHONY: coverage-with-docker
coverage-with-docker: prepare-docker-build-image ## Generates coverage report inside a Docker container
@docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-coverage" \
-v `pwd`:/var/project \
-e COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} \
-e CIRCLECI=1 \
-e CI_NAME=${CI_NAME} \
Expand All @@ -132,7 +115,20 @@ coverage-with-docker: prepare-docker-build-image ## Generates coverage report in
-e CI_BRANCH=${GIT_BRANCH} \
-e CI_PULL_REQUEST=${CI_PULL_REQUEST} \
${DOCKER_BUILDER_IMAGE_NAME} \
make coverage
su -c "make ${1}" hostuser
endef

.PHONY: build-with-docker
build-with-docker: prepare-docker-build-image ## Build inside a Docker container
$(call run_test_container,build)

.PHONY: test-with-docker
test-with-docker: prepare-docker-build-image ## Run tests inside a Docker container
$(call run_test_container,test)

.PHONY: coverage-with-docker
coverage-with-docker: prepare-docker-build-image ## Generates coverage report inside a Docker container
$(call run_test_container,coverage)

.PHONY: clean-docker-containers
clean-docker-containers: ## Clean up any remaining docker containers
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile-build
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ RUN \
awscli

WORKDIR /var/project

COPY entrypoint.sh /usr/local/bin/docker-entrypoint

ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
28 changes: 28 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -eo pipefail

if [ -z "$UID" ] || [ "$UID" = "0" ]; then
echo "UID must be specified as a positive integer"
exit 1
fi

if [ -z "$GID" ] || [ "$GID" = "0" ]; then
echo "GID must be specified as positive integer"
exit 1
fi

USER=$(id -un $UID 2>/dev/null || echo "hostuser")
GROUP=$(getent group $GID | cut -d: -f1 || echo "hostgroup")

if [ "$USER" = "hostuser" ]; then
useradd -u $UID -s /bin/bash -m $USER
fi

if [ "$GROUP" = "hostgroup" ]; then
groupadd -g $GID $GROUP
fi

usermod -g $GROUP $USER

exec "$@"

0 comments on commit c34a382

Please sign in to comment.