Skip to content

Test, build, push (to DockerHub) and deploy a long running "hello-world" Docker Image to Microsoft Azure Virtual Machines (VM).

License

Notifications You must be signed in to change notification settings

JeffDeCola/hello-go-deploy-azure-vm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HELLO GO DEPLOY AZURE VM

Tag Latest Go Reference Go Report Card codeclimate Maintainability codeclimate Issue Count Docker Pulls MIT License jeffdecola.com

*** THE DEPLOY IS UNDER CONSTRUCTION - CHECK BACK SOON *** 

Deploy a "hello-world" docker image to Microsoft Azure VM.

Other Services

Table of Contents

  • ???

Documentation and Reference

PREREQUISITES

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,

EXAMPLES

This repo may have a few examples. We will deploy example 1.

EXAMPLE 1

To run from the command line,

go run main.go

Every 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...

STEP 1 - TEST

Lets unit test the code,

go test -cover ./... | tee /test/test_coverage.txt

There 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.

STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)

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.go

In 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:latest

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.

STEP 3 - PUSH (TO DOCKERHUB)

Lets push your docker image to DockerHub.

If you are not logged in, you need to login to dockerhub,

docker login

Once logged in you can push to DockerHub

docker push jeffdecola/hello-go-deploy-azure-vm

Check 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.

STEP 4 - DEPLOY

tbd

TEST, BUILT, PUSH & DEPLOY USING CONCOURSE (OPTIONAL)

For fun, I use concourse to automate the above steps.

A pipeline file pipeline.yml shows the entire ci flow. Visually, it looks like,

IMAGE - hello-go-deploy-azure-vm concourse ci pipeline - IMAGE

The jobs and tasks are,

The concourse resources type are,

  • hello-go-deploy-azure-vm uses a resource type docker-image to PULL a repo from github.
  • resource-dump-to-dockerhub uses a resource type docker-image to PUSH a docker image to dockerhub.
  • resource-marathon users a resource type docker-image to DEPLOY the newly created docker image to marathon.
  • resource-slack-alert uses a resource type docker image that will notify slack on your progress.
  • resource-repo-status uses 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.

About

Test, build, push (to DockerHub) and deploy a long running "hello-world" Docker Image to Microsoft Azure Virtual Machines (VM).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published