Vagrant-based Virtualbox setup building packer images, go files, and docker containers.
Be sure to install Virtualbox and Vagrant before you begin. If you haven't setup your machine for development, you can use our setup script for OSX at https://github.com/cloudspace-devops/dev-machine-setup
- Clone this repo into a folder inside your workspace:
git clone [email protected]:cloudspace-devops/devops.git
- If you are going to be doing packer or go development, run the following in the root of your workspace directory:
git clone [email protected]:cloudspace-devops/packer-image-scripts.git
git clone [email protected]:cloudspace-devops/packer-shell-scripts.git
mkdir go; mkdir go/bin; mkdir go/pkg; mkdir go/src; mkdir go/src/github.com;
- If you are using a workspace other than /srv, update the $workspace variable inside the Vagrantfile to match your workspace location.
- Start the virtual machine by running
vagrant up
in the root of the project. - SSH into your virtual machine by running
vagrant ssh
, also in the root of the project.
To test your development environment, do the following:
- Get a test project:
go get github.com/cloudspace/microservice-url-lengthener-go
- Change directory into the project:
cd /srv/go/src/github.com/cloudspace/microservice-url-lengthener-go/
- Remove the old lengthener binary:
rm lengthener
- Build the go file without any dependencies:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-w -s' lengthener.go
- Verify the binary is completely static (should show “not a dynamic executable”):
ldd lengthener
- Build a a Docker image to run your binary:
docker build -t cloudspace/url-lengthener .
- Test the Docker image you created:
docker run -ti cloudspace/url-lengthener http://tinyurl.com/testurl
If all went well, this should return the lengthened url for the short url you passed in.