diff --git a/.gitignore b/.gitignore index f8d52bc..f825aad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ genssl/server.csr genssl/server.key genssl/server.pem manifests/deis-minio-secretssl-final.yaml +mc/mc diff --git a/Makefile b/Makefile index b70454e..cc12693 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ export GO15VENDOREXPERIMENT=1 # Note that Minio currently uses CGO. -VERSION := 0.0.1-$(shell date "+%Y%m%d%H%M%S") +VERSION ?= 0.0.1-$(shell date "+%Y%m%d%H%M%S") LDFLAGS := "-s -X main.version=${VERSION}" BINDIR := ./rootfs/bin DEV_REGISTRY ?= $(docker-machine ip deis):5000 @@ -15,6 +15,8 @@ SVC := manifests/deis-${SHORT_NAME}-service.yaml ADMIN_SEC := manifests/deis-${SHORT_NAME}-secretAdmin.yaml USER_SEC := manifests/deis-${SHORT_NAME}-secretUser.yaml IMAGE := ${DEIS_REGISTRY}${SHORT_NAME}:${VERSION} +MC_IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/mc:${VERSION} +MC_INTEGRATION_IMAGE := ${DEIS_REGISTRY}${IMAGE_PREFIX}/mc-integration:${VERSION} all: build docker-build docker-push @@ -64,9 +66,24 @@ kube-clean: kube-mc: kubectl create -f manifests/deis-mc-pod.yaml -mc: - docker build -t ${DEIS_REGISTRY}/deis/minio-mc:latest mc - docker push ${DEIS_REGISTRY}/deis/minio-mc:latest - perl -pi -e "s|image: [a-z0-9.:]+\/|image: ${DEIS_REGISTRY}/|g" manifests/deis-mc-pod.yaml +kube-mc-integration: + kubectl create -f manifests/deis-mc-integration-pod.yaml + +build-mc: + docker run -e GO15VENDOREXPERIMENT=1 -e GOROOT=/usr/local/go --rm -v "${PWD}/mc":/pwd -w /pwd golang:1.5.2 ./install.sh + +docker-build-mc: + docker build -t ${MC_IMAGE} mc + +docker-push-mc: + docker push ${MC_IMAGE} + perl -pi -e "s|image: [a-z0-9.:]+\/|image: ${MC_IMAGE}/|g" manifests/deis-mc-pod.yaml + +docker-build-mc-integration: + docker build -t ${MC_INTEGRATION_IMAGE} mc + +docker-push-mc-integration: + docker push ${MC_INTEGRATION_IMAGE} + perl -pi -e "s|image: [a-z0-9.:]+\/|image: ${MC_INTEGRATION_IMAGE}/|g" manifests/deis-mc-integration-pod.yaml .PHONY: all build docker-compile kube-up kube-down deploy mc kube-mc diff --git a/manifests/deis-mc-integration-pod.yaml b/manifests/deis-mc-integration-pod.yaml new file mode 100644 index 0000000..c79e9cd --- /dev/null +++ b/manifests/deis-mc-integration-pod.yaml @@ -0,0 +1,26 @@ +# A debugging utility for testing Minio from within k8s. +apiVersion: v1 +kind: Pod +metadata: + name: deis-mc-integration + labels: + heritage: deis + version: v2-alpha +spec: + restartPolicy: Never + containers: + - name: mc + imagePullPolicy: Always + image: quay.io/deisci/mc-integration:v2-alpha + command: + - /bin/integration.sh + args: + - "mode memory limit 512MB" + volumeMounts: + - name: minio-user + mountPath: /var/run/secrets/deis/minio/user + readOnly: true + volumes: + - name: minio-user + secret: + secretName: minio-user diff --git a/manifests/deis-mc-pod.yaml b/manifests/deis-mc-pod.yaml index 21cd82b..476e73c 100644 --- a/manifests/deis-mc-pod.yaml +++ b/manifests/deis-mc-pod.yaml @@ -5,14 +5,22 @@ metadata: name: deis-mc labels: heritage: deis - version: 2015-sept + version: v2-alpha spec: restartPolicy: Never containers: - name: mc imagePullPolicy: Always - image: smothiki/minio:v2 + image: quay.io/deisci/mc:v2-alpha command: - mc args: - "mode memory limit 512MB" + volumeMounts: + - name: minio-user + mountPath: /var/run/secrets/deis/minio/user + readOnly: true + volumes: + - name: minio-user + secret: + secretName: minio-user diff --git a/mc/Dockerfile b/mc/Dockerfile index 3bf9cd3..a80d973 100644 --- a/mc/Dockerfile +++ b/mc/Dockerfile @@ -1,8 +1,10 @@ -FROM golang:1.5 - -WORKDIR /go/src/github.com/minio -RUN git clone https://github.com/minio/minio -WORKDIR /go/src/github.com/minio/minio -ENV GOPATH /go -ENV GOROOT /usr/local/go -RUN make install +FROM ubuntu-debootstrap:14.04 + +RUN apt-get update -y && apt-get install -y -q ca-certificates + +ADD mc /bin/mc + +ADD ./integration.sh /bin/integration.sh +RUN chmod +x /bin/integration.sh + +CMD mc diff --git a/mc/install.sh b/mc/install.sh new file mode 100755 index 0000000..d7319e9 --- /dev/null +++ b/mc/install.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# This script builds the minio mc client (https://github.com/minio/mc) inside a Docker container. It should be run inside a golang:1.5.2 container, with the following environment variables set. +# +# - GOROOT=/usr/local/go +# - GO15VENDOREXPERIMENT=1 +# +# It also expects the current directory (mc/) to be mounted at /pwd, and for /pwd to be the current working directory +# +# See the 'mc' build target in the Makefile (in the parent directory) for an example of how to use this script. + +mkdir -p $GOPATH/src/github.com/minio +cd $GOPATH/src/github.com/minio +curl -L -O -s https://github.com/minio/mc/archive/master.tar.gz && tar -xvzf master.tar.gz && rm master.tar.gz && mv mc-master mc +cd mc +make install +cp $GOPATH/bin/mc /pwd/mc diff --git a/mc/integration.sh b/mc/integration.sh new file mode 100755 index 0000000..ed962ef --- /dev/null +++ b/mc/integration.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# This script provides a simple integration test against the minio server (https://github.com/minio/minio). +# It uses the Minio 'mc' client (https://github.com/minio/mc) to do all its work. +# +# It's intended to be run inside a Docker container running an image built with the Dockerfile in this directory. +# The 'mc' target in the Makefile (in the parent directory) builds such an image. +# Finally, this script expects to run in a Kubernetes cluster with a Minio replication controller or pod running and a service called +# "deis-minio" running in front of running in front of it. +# +# You can launch this script by running 'make mc-integration' from the parent directory. +# +# TODO: probably rewrite this script in Go! + +SECRET_PREFIX="/var/run/secrets/deis/minio/user" +ACCESS_KEY_FILE="$SECRET_PREFIX/access-key-id" +ACCESS_SECRET_FILE="$SECRET_PREFIX/access-secret-key" + +if [ -z "$DEIS_MINIO_SERVICE_HOST" ]; then + echo "ERROR: no DEIS_MINIO_SERVICE_HOST env var " + exit 1 +elif [ -z "$DEIS_MINIO_SERVICE_PORT" ]; then + echo "ERROR: no DEIS_MINIO_SERVICE_PORT env var" + exit 1 +fi + +if ! [ -e $ACCESS_KEY_FILE ]; then + echo "ERROR: no access key file found at $ACCESS_KEY_FILE" + exit 1 +elif ! [ -e $ACCESS_SECRET_FILE ]; then + echo "ERROR: no access secret file found at $ACCESS_SECRET_FILE" + exit 1 +fi + +FULL_HOST="http://$DEIS_MINIO_SERVICE_HOST:$DEIS_MINIO_SERVICE_PORT" +BUCKET=mybucket +ACCESS_KEY=`cat $ACCESS_KEY_FILE` +ACCESS_SECRET=`cat $ACCESS_SECRET_FILE` +mc config host add $FULL_HOST $ACCESS_KEY $ACCESS_SECRET + +echo "mc mb $FULL_HOST/$BUCKET" +MB_OUT=$(mc mb $FULL_HOST/$BUCKET) +if [ $? -ne 0 ]; then + echo "FAIL: exit code $?" + exit 1 +elif [ -z "$MB_OUT" ]; then + echo "FAIL: no output" + exit 1 +fi +echo "$MB_OUT" + +echo "abc" > file.txt + +echo "mc cp file.txt $FULL_HOST/$BUCKET/file.txt" +CP_OUT=$(mc cp file.txt $FULL_HOST/$BUCKET/file.txt) +if [ $? -ne 0 ]; then + echo "FAIL: exit code $?" + exit 1 +elif [ -z "$CP_OUT" ]; then + echo "FAIL: no output" + exit 1 +fi + +FILE=$(mc cat $FULL_HOST/$BUCKET/file.txt) +if [ $? -ne 0 ]; then + echo "FAIL: exit code $?" + exit 1 +elif [ -z "$FILE" ]; + echo "FAIL: no output" + exit 1 +fi