Go 1.6 on Elastic Beanstalk

build: ./build.sh
#!/usr/bin/env bash# Fail immediately if any of the commands below fail.
set -x
# Display the existing Go info before we change it.
go version
echo GOROOT=$GOROOT
echo GOPATH=$GOPATH
# Install a newer version of Go.
GOGZ=go1.6.2.linux-amd64.tar.gz
curl -O "https://storage.googleapis.com/golang/$GOGZ"
tar -zxf $GOGZ
rm $GOGZ
export GOROOT=/usr/local/go
export GOPATH=$GOROOT/bin
rm -rf $GOROOT
mv go $GOROOT
export PATH=$GOPATH:$PATH
# Make sure we are now using the newer version.
go version
echo GOROOT=$GOROOT
echo GOPATH=$GOPATH
# Move the application into the correct package for $GOPATH.
DEST=$GOROOT/src/github.com/your/package
rm -rf $DEST
mkdir -p $DEST
cp -r * $DEST # NOTE: must be 'cp', not 'mv' here.
# Install/update dependencies.
go get -u gopkg.in/redis.v3
go get -u github.com/Sirupsen/logrus
go get -u gopkg.in/yaml.v2
# Build the server. Beanstalk will look for an 'application' executable.
cd $DEST
go build -o application
chmod +x application
mv application /usr/bin
  • GOGZ=go1.6.2.linux-amd64.tar.gz: This is the name of the download, simply change this to get a different version — but make sure you specify the linux distribution.
  • DEST=$GOROOT/src/github.com/your/package: You will need to move your source into the appropriate package folder.

--

--

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store