...
 
Commits (2)
#!/usr/bin/env bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
export DEPLOY_ROOT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
source "$DEPLOY_ROOT_DIR/src/common.bash"
echo "Checking docker engine..."
ensure_docker_engine
docker rm -f "$CI_CONTAINER_NAME" &>/dev/null || true
echo "Building application..."
if [[ -f Dockerfile ]]; then
echo "Building Dockerfile-based application..."
# Build Dockerfile
docker build -t "$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG" .
else
# Build heroku-based application
echo "Building Heroku-based application using gliderlabs/herokuish docker image..."
docker run -i --name="$CI_CONTAINER_NAME" \
-v "$(pwd):/tmp/app:ro" \
-v "/cache/herokuish:/tmp/cache" \
gliderlabs/herokuish /bin/herokuish buildpack build
docker commit "$CI_CONTAINER_NAME" "$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG"
docker rm "$CI_CONTAINER_NAME" >/dev/null
echo ""
# Create a start command, start `web`
echo "Configuring $CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG docker image..."
docker create --expose 5000 --env PORT=5000 \
--name="$CI_CONTAINER_NAME" \
"$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG" \
/bin/herokuish procfile start web
docker commit "$CI_CONTAINER_NAME" "$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG"
docker rm "$CI_CONTAINER_NAME" >/dev/null
echo ""
fi
if [[ -n "$CI_BUILD_TOKEN" ]]; then
echo "Logging to GitLab Container Registry with CI credentials..."
docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
echo ""
fi
echo "Pushing to GitLab Container Registry..."
docker push "$CI_REGISTRY_IMAGE:$CI_REGISTRY_TAG"
echo ""
build:
stage: build
image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image/master:stable"
services:
- docker:stable-dind
script:
- |
if [[ -z "$CI_COMMIT_TAG" ]]; then
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG}
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA}
else
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE}
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG}
fi
- /build/build.sh
only:
- branches
- tags
This diff is collapsed.