Skip to content

Commit

Permalink
Merge 4681675 into ef00427
Browse files Browse the repository at this point in the history
  • Loading branch information
bandesz committed Oct 28, 2016
2 parents ef00427 + 4681675 commit 508b50b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,40 @@ prepare-docker-build-image: ## Prepare the Docker builder image

.PHONY: build-with-docker
build-with-docker: prepare-docker-build-image ## Build inside a Docker container
mkdir -p cache/pip-accel
@docker run -i --rm \
--name "${DOCKER_CONTAINER_PREFIX}-build" \
-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
su -c "make build" hostuser

.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 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 test
su -c "make test" hostuser

# 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 UID=$(shell id -u) \
-e GID=$(shell id -g) \
-e COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} \
-e CIRCLECI=1 \
-e CI_NAME=${CI_NAME} \
Expand All @@ -132,7 +139,7 @@ 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 coverage" hostuser

.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 hostgroup hostuser

exec "$@"

0 comments on commit 508b50b

Please sign in to comment.