Permalink
Browse files

Build images with new Python cogctl binary

  • Loading branch information...
christophermaier committed Feb 16, 2017
1 parent 3b936f3 commit b9bf3f03cc8b05ff68d959d4a1f7b9595ff9a0b9
Showing with 66 additions and 76 deletions.
  1. +5 −8 .buildkite/pipeline.sh
  2. +3 −0 .dockerignore
  3. +2 −0 .gitignore
  4. +6 −13 Dockerfile
  5. +4 −1 Makefile
  6. +0 −54 scripts/docker-build
  7. +46 −0 scripts/get_cogctl.sh
View
@@ -52,9 +52,6 @@ cat <<EOF
EOF
done
# TEMPORARILY disabled while we sort out cogctl build issues
########################################################################
# "Real" Image build
#
@@ -79,13 +76,13 @@ done
# For now, we'll push this to `cog-testing`, instead of `cog`, even
# though it's a "real" image. Once we start actually promoting
# official images from CI, though, we can send it to `cog`.
# COG_IMAGE="operable/cog-testing:ci-build-${BUILDKITE_BUILD_NUMBER}-${BUILDKITE_COMMIT::8}"
COG_IMAGE="operable/cog-testing:ci-build-${BUILDKITE_BUILD_NUMBER}-${BUILDKITE_COMMIT::8}"
# cat <<EOF
cat <<EOF
# - wait
- wait
# - command: .buildkite/scripts/build_and_push_docker_image.sh $COG_IMAGE
# label: ":docker: Build Real Image"
- command: .buildkite/scripts/build_and_push_docker_image.sh $COG_IMAGE
label: ":docker: Build Real Image"
EOF
View
@@ -11,3 +11,6 @@ Mnesia*
cover
docker-compose.yml
.env
.git
.gitignore
.dockerignore
View
@@ -9,3 +9,5 @@ Mnesia.*
/cover
docker-compose.override.yml
.env
cogctl-for-docker-build
View
@@ -18,24 +18,17 @@ RUN addgroup -g $OPERABLE_GID operable && \
adduser -h /home/operable -D -u $OPERABLE_UID -G operable -s /bin/ash operable
# Create directories and upload cog source
RUN mkdir -p /home/operable/cog /home/operable/cogctl
WORKDIR /home/operable/cog
COPY . /home/operable/cog/
RUN chown -R operable /home/operable && \
rm -f /home/operable/.dockerignore
RUN chown -R operable /home/operable
# We do this all in one huge RUN command to get the smallest
# possible image.
USER root
RUN apk update -U && \
apk add expat-dev gcc g++ libstdc++ make && \
# build cog and cogctl \
su operable - -c /home/operable/cog/scripts/docker-build && \
# install cogctl and delete source directory \
cp /home/operable/cogctl/cogctl /usr/local/bin/cogctl && \
rm -rf /home/operable/cogctl && \
# cleanup dependencies
mix clean && mix deps.get && mix compile && \
apk del gcc g++ && \
rm -f /var/cache/apk/*
# This should be in place in the build environment already
COPY cogctl-for-docker-build /usr/local/bin/cogctl
USER operable
WORKDIR /home/operable/cog
View
@@ -11,7 +11,10 @@ reset-db:
mix ecto.reset --no-start
docker:
docker build --build-arg MIX_ENV=prod -t $(DOCKER_IMAGE) .
scripts/get_cogctl.sh
docker build \
--build-arg MIX_ENV=prod \
-t $(DOCKER_IMAGE) .
.PHONY: docker
View
@@ -1,54 +0,0 @@
#!/bin/sh -x
set -e
# install mix
mix local.hex --force
mix local.rebar --force
mix hex.info
# build cog
cd /home/operable/cog
# We do this so we know what branch to build for cogctl later on
COG_BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ -z "$COG_BRANCH" ]
then
echo "Looks like cog isn't a git repository! Do you have '.git' in the '.dockerignore' file? If so, remove it and try again."
exit 1
fi
# Get rid of .git now that we know the branch
rm -Rf .git
mix clean
mix deps.get
mix deps.compile
mix compile
# build cogctl
#
# First take a look at what branch / tag we're on in Cog
# If the same branch / tag exists in cogctl, we should use it.
# Otherwise, we use master
echo "cog is currently checked out at ${COG_BRANCH}"
COGCTL_REPO="https://github.com/operable/cogctl"
if git ls-remote --exit-code --heads $COGCTL_REPO $COG_BRANCH
then
COGCTL_BRANCH=$COG_BRANCH
echo "A '$COGCTL_BRANCH' branch exists for cogctl as well; building from that"
else
COGCTL_BRANCH="master"
echo "No '$COG_BRANCH' branch exists for cogctl; building from the '$COGCTL_BRANCH' instead"
fi
cd /home/operable/cogctl
git clone $COGCTL_REPO .
git checkout $COGCTL_BRANCH
# No need to keep this in the image
rm -Rf .git
mix deps.get
mix deps.compile
mix escript
View
@@ -0,0 +1,46 @@
#!/bin/bash
set -euo pipefail
# Get cogctl executable for incorporation into a Cog image
#
# Eventually, we'll have a proper artifact repository for our cogctl
# binaries, but until then, we can extract the binary out of their own
# Docker container. Since we can't do that from within the Cog image
# building process, we need to do that on the workstation from which
# the Cog image is being built. It can then be injected into the new
# Cog image.
# First, we need to determine which cogctl image we're going to
# use. If we've built a release of cogctl, there will be a container
# tagged using the Git tag of that release. Cog and cogctl will both
# share this tag. Thus, if Cog is being built from a tag, then we
# should pull down the corresponding cogctl image.
#
# If it is not being built from a tag, however, we should just pull
# down the current "master" tag from the cogctl repository.
#
# Since we only build Cog images on Alpine Linux at the moment, we
# always pull the Alpine image for cogctl.
#
# (Note: the following code is similar to code used for relay and
# cogctl builds.)
tag=`git describe --tags`
dash_count=`git describe --tags | grep -o - | wc -l | sed "s/ //g"`
if [ "$dash_count" == "0" ]
then
# We're directly on a tag
image="operable/cogctl:alpine-${tag}"
else
# We're not right on a tag, so just grab the master image
image="operable/cogctl:alpine-master"
fi
# Actually pull the image
docker pull "${image}"
# Extract the executable to the local filesystem. The name of the
# extracted file will be "cogctl-for-docker-build".
container_id=$(docker create "${image}")
docker cp "${container_id}:/usr/bin/cogctl" cogctl-for-docker-build
docker rm "${container_id}"

0 comments on commit b9bf3f0

Please sign in to comment.