*** THE DEPLOY IS UNDER CONSTRUCTION - CHECK BACK SOON *** hello-go-deploy-azure-vm will test, build, push (to DockerHub) and deploy a long running "hello-world" Docker Image to Microsoft Azure VM.
I also have other repos showing different deployments,
- PaaS
- CaaS
- IaaS
The hello-go-deploy-azure-vm Docker Image on DockerHub.
The hello-go-deploy-azure-vm GitHub Webpage.
For this exercise I used go. Feel free to use a language of your choice,
To build a docker image you will need docker on your machine,
To push a docker image you will need,
To deploy to microsoft azure vm you will need,
As a bonus, you can use Concourse CI to run the scripts,
- concourse (Optional)
This repo may have a few examples. We will deploy example 1.
To run from the command line,
go run main.goEvery 2 seconds hello-go-deploy-azure-vm will print:
Hello everyone, count is: 1 Hello everyone, count is: 2 Hello everyone, count is: 3 etc...Lets unit test the code,
go test -cover ./... | tee /test/test_coverage.txtThere is a unit-tests.sh script to run the unit tests. There is also a script in the /ci folder to run the unit tests in concourse.
We will be using a multi-stage build using a Dockerfile. The end result will be a very small docker image around 13MB.
docker build -f build-push/Dockerfile -t jeffdecola/hello-go-deploy-azure-vm .Obviously, replace jeffdecola with your DockerHub username.
In stage 1, rather than copy a binary into a docker image (because that can cause issue), the Dockerfile will build the binary in the docker image.
If you open the DockerFile you can see it will get the dependencies and build the binary in go,
FROM golang:alpine AS builder RUN go get -d -v RUN go build -o /go/bin/hello-go-deploy-azure-vm main.goIn stage 2, the Dockerfile will copy the binary created in stage 1 and place into a smaller docker base image based on alpine, which is around 13MB.
You can check and test your docker image,
docker run --name hello-go-deploy-azure-vm -dit jeffdecola/hello-go-deploy-azure-vm docker exec -i -t hello-go-deploy-azure-vm /bin/bash docker logs hello-go-deploy-azure-vm docker images jeffdecola/hello-go-deploy-azure-vm:latestThere is a build-push.sh script to build and push to DockerHub. There is also a script in the /ci folder to build and push in concourse.
Lets push your docker image to DockerHub.
If you are not logged in, you need to login to dockerhub,
docker loginOnce logged in you can push to DockerHub
docker push jeffdecola/hello-go-deploy-azure-vmCheck you image at DockerHub. My image is located https://hub.docker.com/r/jeffdecola/hello-go-deploy-azure-vm.
There is a build-push.sh script to build and push to DockerHub. There is also a script in the /ci folder to build and push in concourse.
tbd
For fun, I use concourse to automate the above steps.
A pipeline file pipeline.yml shows the entire ci flow. Visually, it looks like,
The jobs and tasks are,
job-readme-github-pagesruns task readme-github-pages.sh.job-unit-testsruns task unit-tests.sh.job-build-pushruns task build-push.sh.job-deployruns task deploy.sh.
The concourse resources type are,
hello-go-deploy-azure-vmuses a resource type docker-image to PULL a repo from github.resource-dump-to-dockerhubuses a resource type docker-image to PUSH a docker image to dockerhub.resource-marathonusers a resource type docker-image to DEPLOY the newly created docker image to marathon.resource-slack-alertuses a resource type docker image that will notify slack on your progress.resource-repo-statususes a resource type docker image that will update your git status for that particular commit.
For more information on using concourse for continuous integration, refer to my cheat sheet on concourse.
