Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zest create #53

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Zest is to assist with docker-driven workflow in both a local dev environment an

## Requirements
Zest requires `zest`, `_zester`, `docker`, and `docker-compose` (v1.12 or newer, see below)
to be installed in your PATH. The Docker daemon must be running.
to be installed in your PATH. The Docker daemon must be running.

You must have docker-compose >= 1.12 installed. It is included in Docker for Mac edge since 17.04.
The latest version of Docker for Mac stable (17.03) does not yet bundle this version.
Either use https://github.com/axiomzen/zest/commit/d6afabaa7100b56b326abab55fa11c4e4b71c4b1
or [update docker-compose](https://docs.docker.com/compose/install/).
The latest version of Docker for Mac stable (17.03) does not yet bundle this version.
Either use https://github.com/axiomzen/zest/commit/d6afabaa7100b56b326abab55fa11c4e4b71c4b1
or [update docker-compose](https://docs.docker.com/compose/install/).

## Installation
To install things system wide use `sudo make install`, which will attempt to copy the binaries and relevant configs into `/usr/local` as well as the users `~/.zest` directories.
Expand All @@ -34,6 +34,7 @@ Command | Result
--------|-------
init-service | Creates the prerequisite files for the current directory to be a zestable service
build | Runs the `Build()` script inside the build container
create | Runs both `build` and `bundle` on the selected container
enter | Launch an interactive shell inside the build container
test | Runs the `Test()` script inside the test container
bundle | Build the final container with the provided Dockerfile and tag with both version and latest
Expand All @@ -50,7 +51,7 @@ Command | Result
--------|--------
init-project | Creates the prerequisite files for the current directory to be a zestable project
integrate | Run integration tests on a project
run | Start the environment with docker-compose
run | Start the environment with docker-compose. Use flag `-s` or `--service SERVICENAME` to run an individual service along with its dependencies
stop | clean up the docker-compose environment
all | build, test, bundle all folders in the pwd that are services, then integrate

Expand Down
3 changes: 2 additions & 1 deletion example/Peelfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ run: example
integrate: integrater
project: example
compose: docker-compose.yml
compose-integrate: docker-compose.integrate.yml
compose-integrate: docker-compose.integrate.yml
compose-development: docker-compose.dev.yml
121 changes: 95 additions & 26 deletions zest
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ _zest_is_service() {
fi

# load the Zestfile
_debug "Loading Zestfile"
_debug "Loading Zestfile at ${1}/Zestfile"
source $1/Zestfile

# check for docker file override
Expand Down Expand Up @@ -154,11 +154,11 @@ _zest_run() {
_fatal "Not a zest project"
fi

RUN_SERVICE=`grep -E -i "^run: " Peelfile | awk '{print $2}'`
RUN_SERVICE="${SERVICE_PATH:-`grep -E -i "^run: " Peelfile | awk '{print $2}'`}"

if [[ "$RUN_SERVICE" == "" ]]; then
_fatal "run: not specified in Peelfile"
fi
_fatal "run: not specified in Peelfile nor in --service"
fi

_info "Running service $RUN_SERVICE"

Expand All @@ -174,7 +174,7 @@ _zest_stop() {
fi

_info "Stopping project"

docker-compose -f $COMPOSE_FILE $DOCKER_VERBOSE down --rmi local
}

Expand All @@ -185,16 +185,15 @@ _zest_cache_volumes() {

# handle legacy variables
if [[ ! -z $CACHE_DIR_SRC && ! -z $CACHE_DIR_DST ]]; then
# _debug "Including cache directory $CACHE_DIR_SRC => $CACHE_DIR_DST"
#_debug "Including cache directory $CACHE_DIR_SRC => $CACHE_DIR_DST"
cache_mounts+=("$CACHE_DIR_SRC:$CACHE_DIR_DST")
fi

# handle new array variables
if [[ ! -z $CACHE_DIR_SRCS && ! -z $CACHE_DIR_DSTS ]]; then
cache_dir_count=${#CACHE_DIR_SRCS[@]}
for ((i=0; i < $cache_dir_count; i++)); do
src=${CACHE_DIR_SRCS[$i]}
dst=${CACHE_DIR_DSTS[$i]}
src=${CACHE_DIR_SRCS[$i]} dst=${CACHE_DIR_DSTS[$i]}
# _debug "Including cache directory $src => $dst"
cache_mounts+=("$src:$dst")
done
Expand All @@ -209,13 +208,27 @@ _zest_cache_volumes() {
}

_zest_build() {
_debug "ABSOLUTE_PATH: $ABSOLUTE_PATH"
_debug "ABSOLUTE_DIR: $ABSOLUTE_DIR"
_debug "PATH: $(pwd)"

# Get the service name (folder name)
SERVICE=$(basename `pwd`)
_debug "Cache: $CACHE_DIR_SRCS"

SERVICE="${SERVICE_PATH:-$(basename `pwd`)}"

# First ensure we're a service
_debug "Checking service"
if ! _zest_is_service . ; then
_debug "Checking service ${SERVICE}"

SERVICE_PATH=$(find $(pwd) -type d -maxdepth 2 | grep ${SERVICE} | head -n 1)

if [[ "$SERVICE_PATH" == "" ]]; then
_debug "Service path is empty, setting to current path"
SERVICE_PATH=$(pwd)
fi

_debug "service_path: ${SERVICE_PATH}"

if ! _zest_is_service $SERVICE_PATH ; then
_fatal "$SERVICE is not a service"
fi

Expand Down Expand Up @@ -249,7 +262,7 @@ _zest_build() {
# Build in the container
_info "Building service $SERVICE_NAME in $BUILD_CONTAINER"

docker run --rm -v $(pwd):$MOUNT_DIR/$SERVICE -w $MOUNT_DIR/$SERVICE -v $ZESTER_PATH:/usr/bin/zester:ro $(_zest_cache_volumes) $BUILD_CONTAINER zester build --name $SERVICE_NAME
docker run --rm -v $SERVICE_PATH:$MOUNT_DIR/$SERVICE -w $MOUNT_DIR/$SERVICE -v $ZESTER_PATH:/usr/bin/zester:ro $(_zest_cache_volumes) $BUILD_CONTAINER zester build --name $SERVICE_NAME

if [[ $? -ne 0 ]]; then
_fatal "Build failed"
Expand All @@ -266,14 +279,48 @@ _zest_build() {
_info "Build success!"
}

_zest_create() {

SERVICE="${SERVICE_PATH:-$(basename `pwd`)}"

# First ensure we're a service
_debug "Checking service ${SERVICE}"

SERVICE_PATH=$(find $(pwd) -type d -maxdepth 2 | grep ${SERVICE} | head -n 1)

if [[ "$SERVICE_PATH" == "" ]]; then
_debug "Service path is empty, setting to current path"
SERVICE_PATH=$(pwd)
fi

_debug "service_path: ${SERVICE_PATH}"

if ! _zest_is_service $SERVICE_PATH ; then
_fatal "$SERVICE is not a service"
fi

bash -c "$ABSOLUTE_PATH build -s $SERVICE_PATH $GO_VERBOSE && $ABSOLUTE_PATH test -s $SERVICE_PATH $GO_VERBOSE && $ABSOLUTE_PATH bundle -s $SERVICE_PATH $GO_VERBOSE" || _fatal "Zest build failed"

_info "Create success!"
}

_zest_bundle() {

# Get the service name (folder name)
SERVICE=$(basename `pwd`)
SERVICE="${SERVICE_PATH:-$(basename `pwd`)}"

# First ensure we're a service
_debug "Checking service"
if ! _zest_is_service . ; then
_debug "Checking service ${SERVICE}"

SERVICE_PATH=$(find $(pwd) -type d -maxdepth 2 | grep ${SERVICE} | head -n 1)

if [[ "$SERVICE_PATH" == "" ]]; then
_debug "Service path is empty, setting to current path"
SERVICE_PATH=$(pwd)
fi

_debug "service_path: ${SERVICE_PATH}"

if ! _zest_is_service $SERVICE_PATH ; then
_fatal "$SERVICE is not a service"
fi

Expand Down Expand Up @@ -325,10 +372,12 @@ _zest_bundle() {

if [[ "$IMAGE_SERVER" == "" ]]; then
_debug "Not using image server"
docker build $BUILD_ARGS --build-arg REVISION=$REVISION_OVERRIDE -t $REPO/$SERVICE:$VERSION -t $REPO/$SERVICE:latest -f $DOCKERFILE .
_debug "-f $DOCKERFILE $SERVICE_PATH"
docker build $BUILD_ARGS --build-arg REVISION=$REVISION_OVERRIDE -t $REPO/$SERVICE:$VERSION -t $REPO/$SERVICE:latest -f $SERVICE_PATH/$DOCKERFILE $SERVICE_PATH
else
_debug "Using image server $IMAGE_SERVER"
docker build $BUILD_ARGS --build-arg REVISION=$REVISION_OVERRIDE -t $IMAGE_SERVER/$REPO/$SERVICE:$VERSION -t $IMAGE_SERVER/$REPO/$SERVICE:latest -f $DOCKERFILE .
docker build $BUILD_ARGS --build-arg REVISION=$REVISION_OVERRIDE -t $IMAGE_SERVER/$REPO/$SERVICE:$VERSION -t $IMAGE_SERVER/$REPO/$SERVICE:latest -f $SERVICE_PATH/$DOCKERFILE $SERVICE_PATH

fi

if [[ $? -ne 0 ]]; then
Expand Down Expand Up @@ -407,15 +456,25 @@ _zest_push() {

_zest_test() {

# Get the service name (folder name)
SERVICE=$(basename `pwd`)
SERVICE="${SERVICE_PATH:-$(basename `pwd`)}"

# First ensure we're a service
_debug "Checking service"
if ! _zest_is_service . ; then
_debug "Checking service ${SERVICE}"

SERVICE_PATH=$(find $(pwd) -type d -maxdepth 2 | grep ${SERVICE} | head -n 1)

if [[ "$SERVICE_PATH" == "" ]]; then
_debug "Service path is empty, setting to current path"
SERVICE_PATH=$(pwd)
fi

_debug "service_path: ${SERVICE_PATH}"

if ! _zest_is_service $SERVICE_PATH ; then
_fatal "$SERVICE is not a service"
fi


# Must have $TEST_CONTAINER or $BUILD_CONTAINER set
if [[ "$TEST_CONTAINER" == "" ]]; then
TEST_CONTAINER=$BUILD_CONTAINER
Expand All @@ -437,10 +496,10 @@ _zest_test() {
SERVICE_NAME=$SERVICE
_debug "SERVICE_NAME not set, using $SERVICE"
fi

# Build in the container
_info "Testing service $SERVICE in $TEST_CONTAINER"
docker run --rm -v $(pwd):$MOUNT_DIR/$SERVICE -w $MOUNT_DIR/$SERVICE -v $ZESTER_PATH:/usr/bin/zester:ro $(_zest_cache_volumes) $TEST_CONTAINER zester test --name $SERVICE_NAME
docker run --rm -v $SERVICE_PATH:$MOUNT_DIR/$SERVICE -w $MOUNT_DIR/$SERVICE -v $ZESTER_PATH:/usr/bin/zester:ro $(_zest_cache_volumes) $TEST_CONTAINER zester test --name $SERVICE_NAME

if [[ $? -ne 0 ]]; then
_fatal "Test failed"
Expand Down Expand Up @@ -627,7 +686,7 @@ _zest_all() {
_debug "Checking $dir"
if _zest_is_service $dir; then
_info "Zesting $dir"
bash -c "cd $dir; $ABSOLUTE_PATH build $GO_VERBOSE && $ABSOLUTE_PATH test $GO_VERBOSE && $ABSOLUTE_PATH bundle $GO_VERBOSE" || _fatal "Zest all failed"
bash -c "$ABSOLUTE_PATH build -s $dir $GO_VERBOSE && $ABSOLUTE_PATH test -s $dir $GO_VERBOSE && $ABSOLUTE_PATH bundle -s $dir $GO_VERBOSE" || _fatal "Zest all failed"
fi
done

Expand All @@ -654,6 +713,9 @@ case $1 in
test)
COMMAND="test"
;;
create)
COMMAND="create"
;;
version)
COMMAND="version"
;;
Expand Down Expand Up @@ -716,6 +778,7 @@ DEFAULT_VERSION=true
BUILD_ARGS=
DOCKER_VERBOSE=
GO_VERBOSE=
SERVICE_PATH=

while [[ $# -gt 0 ]]; do
case $1 in
Expand All @@ -730,6 +793,9 @@ while [[ $# -gt 0 ]]; do
-b|--build-args)
shift && BUILD_ARGS="$1"
;;
*)
shift && SERVICE_PATH="$1"
;;
esac
shift
done
Expand All @@ -742,6 +808,9 @@ case $COMMAND in
bundle)
_zest_bundle
;;
create)
_zest_create
;;
test)
_zest_test
;;
Expand Down