Skip to content

Instantly share code, notes, and snippets.

@XavM
Created October 18, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XavM/65dbf7cc582bd1b8768f335f608098fd to your computer and use it in GitHub Desktop.
Save XavM/65dbf7cc582bd1b8768f335f608098fd to your computer and use it in GitHub Desktop.
Build zbo-goimporter from scratch using Docker

Build zbo-goimporter from scratch (using Docker)

Run a fresh build CT

CT_ID=$(docker run -itd centos /bin/bash)

Enter CT

docker exec -it "${CT_ID}" /bin/bash

Install and setup GOLANG

cd ~
curl -LO https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz \
  && tar -C /usr/local -xzf go1.7.linux-amd64.tar.gz \
  && rm -rf go1.7.linux-amd64.tar.gz \
  && export PATH=$PATH:/usr/local/go/bin

Create your GOLANG build workspace

export GOPATH=$HOME/work
mkdir -p $GOPATH/src/github.com/zebestof/ 

Get sources and dependencies

git version || yum install git -y \
  && git clone 'https://zbo-ad@github.com/zebestof/zbo-goimporter.git' $GOPATH/src/github.com/zebestof/zbo-goimporter

cd $GOPATH \
  && go get gopkg.in/couchbaselabs/gocb.v1 \
  && go get github.com/aws/aws-sdk-go

Build zbo-goimporter

cd $GOPATH
#env GOOS=linux GOARCH=amd64 ## <- Cross compile only to target production OS and ARCH
go install github.com/zebestof/zbo-goimporter

Get mandatory conf file

cp src/github.com/zebestof/zbo-goimporter/config-production.json ./bin/

Run zbo-goimporter

export ZBO_DMP_GO_PROD="1"
cd $GOPATH/bin/
./zbo-goimporter -dmp=cabestan

[optional] Make a release out of your build

RELEASE_VERSION="v1.0.0" \
  && mkdir -p $GOPATH/release \
  && rm -rf $GOPATH/release/* \
  && cp $GOPATH/bin/zbo-goimporter $GOPATH/release/ \
  && cp $GOPATH/src/github.com/zebestof/zbo-goimporter/config-production.json $GOPATH/release/ \
  && tar zcvf $GOPATH/release-${RELEASE_VERSION}.tar.gz -C $GOPATH/release/ . \
  && rm -rf $GOPATH/release \
  && ll $GOPATH/release-${RELEASE_VERSION}.tar.gz

[optional] Create and Upload the release to gitHub

RELEASE_VERSION="v1.0.0" \
  && gitHub_USER="xavm" \
  && jq --version 2>&1>/dev/null || {
    yum install epel-release -y \
    && yum install jq -y; } \
  && RELEASE_SPECS=$(curl -sSu "${gitHub_USER}" -X POST "https://api.github.com/repos/zebestof/zbo-goimporter/releases" -d '{
    "tag_name": "'${RELEASE_VERSION}'",
    "target_commitish": "master",
    "name": "'${RELEASE_VERSION}'",
    "body": "'${RELEASE_VERSION}'",
    "draft": false,
    "prerelease": false
  }') \
  && RELEASE_UPLOAD_URL=$(echo "${RELEASE_SPECS}"| jq -r '.upload_url' | cut -d"{" -f 1) \
  && RELEASE_ID=$(echo "${RELEASE_SPECS}"| jq -r '.id')
curl -sSu "${gitHub_USER}" \
     -H "Content-Type: application/gzip" \
     -X POST "${RELEASE_UPLOAD_URL}?name=release-${RELEASE_VERSION}.tar.gz" \
     --data-binary @$GOPATH/release-${RELEASE_VERSION}.tar.gz    

[optional] Commit your docker GOLANG build env (and skip every steps before "Build zbo-goimporter" next time)

COMMIT_OUT=$(docker commit "${CT_ID}")
IMAGE_ID="${COMMIT_OUT##*:}"

[optional] Create a new build, skipping every steps before "Build zbo-goimporter"

docker run -it $IMAGE_ID /bin/bash
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/work  
cd $GOPATH/src/github.com/zebestof/zbo-goimporter
git pull 
cd $GOPATH
go install github.com/zebestof/zbo-goimporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment