Skip to content

Commit

Permalink
Update docker build image scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald committed Jul 28, 2020
1 parent 2b990be commit ec76613
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 30 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ COPY . gecko

WORKDIR $GOPATH/src/github.com/ava-labs/gecko
RUN ./scripts/build.sh

RUN ln -sv $GOPATH/src/github.com/ava-labs/gecko/ /gecko
2 changes: 2 additions & 0 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func (m *manager) ForceCreateChain(chainParams ChainParameters) {
}

chain, err := m.buildChain(chainParams)
m.chains[chainParams.ID.Key()] = chain.Handler

if err != nil {
m.log.Error("Error while creating new chain: %s", err)
return
Expand Down
11 changes: 0 additions & 11 deletions scripts/Dockerfile.deploy

This file was deleted.

27 changes: 8 additions & 19 deletions scripts/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@ set -o errexit
set -o nounset
set -o pipefail


SRC_DIR="$(dirname "${BASH_SOURCE[0]}")"
export GOPATH="$SRC_DIR/.build_image_gopath"
WORKPREFIX="$GOPATH/src/github.com/ava-labs/"
DOCKER="${DOCKER:-docker}"
keep_existing=0
while getopts 'k' opt
do
case $opt in
(k) keep_existing=1;;
esac
done
if [[ "$keep_existing" != 1 ]]; then
rm -rf "$WORKPREFIX"
fi

if [[ ! -d "$WORKPREFIX" ]]; then
mkdir -p "$WORKPREFIX"
git config --global credential.helper cache
git clone https://github.com/ava-labs/gecko.git "$WORKPREFIX/gecko"

if [[ $# -eq 0 ]]; then
"$SRC_DIR/build_local_image.sh"
elif [[ $# -eq 2 ]]; then
"$SRC_DIR/build_image_from_remote.sh" $@
else
echo "Build image requires either no arguments to build from local source or two arguments to build from a remote branch"
fi
GECKO_COMMIT="$(git --git-dir="$WORKPREFIX/gecko/.git" rev-parse --short HEAD)"
"${DOCKER}" build -t "gecko-$GECKO_COMMIT" "$SRC_DIR" -f "$SRC_DIR/Dockerfile.deploy"
44 changes: 44 additions & 0 deletions scripts/build_image_from_remote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail


SRC_DIR="$(dirname "${BASH_SOURCE[0]}")"
BASE_DIR="$SRC_DIR/.."

# Two arguments specify the remote and branch to use
REMOTE=$1
BRANCH=$2


echo "Building docker image from branch: $BRANCH at remote: $REMOTE"

export GOPATH="$SRC_DIR/.build_image_gopath"
WORKPREFIX="$GOPATH/src/github.com/ava-labs"
DOCKER="${DOCKER:-docker}"
keep_existing=0
while getopts 'k' opt
do
case $opt in
(k) keep_existing=1;;
esac
done
if [[ "$keep_existing" != 1 ]]; then
rm -rf "$WORKPREFIX"
fi

# Clone the remote and checkout the specified branch to build the Docker image from
GECKO_CLONE="$WORKPREFIX/gecko"

if [[ ! -d "$WORKPREFIX" ]]; then
mkdir -p "$WORKPREFIX"
git config --global credential.helper cache
git clone "$REMOTE" "$GECKO_CLONE"
git --git-dir="$GECKO_CLONE/.git" checkout "$BRANCH"
fi

GECKO_COMMIT="$(git --git-dir="$GECKO_CLONE/.git" rev-parse --short HEAD)"

"${DOCKER}" build -t "gecko-$GECKO_COMMIT" "$GECKO_CLONE" -f "$GECKO_CLONE/Dockerfile"
15 changes: 15 additions & 0 deletions scripts/build_local_image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

# Build image from current local source
SRC_DIR="$(dirname "${BASH_SOURCE[0]}")"
BASE_DIR="$SRC_DIR/.."

# WARNING: this will use the most recent commit even if there are un-committed changes present
COMMIT_HASH="$(git --git-dir="$BASE_DIR/.git" rev-parse --short HEAD)"
echo "Building Docker image based off of local repo at commit $COMMIT_HASH"

docker build -t "gecko-$COMMIT_HASH" "$BASE_DIR" -f "$BASE_DIR/Dockerfile"

0 comments on commit ec76613

Please sign in to comment.