@@ -36,7 +36,15 @@ Other Services
36
36
37
37
Table of Contents
38
38
39
- * ???
39
+ * [ OVERVIEW] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#overview )
40
+ * [ PREREQUISITES] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#prerequisites )
41
+ * [ SOFTWARE STACK] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#software-stack )
42
+ * [ RUN] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#run )
43
+ * [ STEP 1 - TEST] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#step-1---test )
44
+ * [ STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#step-2---build-docker-image-via-dockerfile )
45
+ * [ STEP 3 - PUSH (TO DOCKERHUB)] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#step-3---push-to-dockerhub )
46
+ * [ STEP 4 - DEPLOY (TO AZURE VM)] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#step-4---deploy-to-azure-vm )
47
+ * [ CONTINUOUS INTEGRATION & DEPLOYMENT] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm#continuous-integration--deployment )
40
48
41
49
Documentation and Reference
42
50
@@ -48,167 +56,133 @@ Documentation and Reference
48
56
_ built with
49
57
[ concourse] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci-README.md ) _
50
58
51
- ## PREREQUISITES
52
-
53
- For this exercise I used go. Feel free to use a language of your choice,
54
-
55
- * [ go] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/development/languages/go-cheat-sheet )
56
-
57
- To build a docker image you will need docker on your machine,
59
+ ## OVERVIEW
58
60
59
- * [ docker ] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/orchestration/builds-deployment-containers/docker-cheat-sheet )
61
+ Every 2 seconds this App will print,
60
62
61
- To push a docker image you will need,
62
-
63
- * [ DockerHub account] ( https://hub.docker.com/ )
64
-
65
- To deploy to ` microsoft azure vm ` you will need,
63
+ ``` txt
64
+ INFO[0000] Let's Start this!
65
+ Hello everyone, count is: 1
66
+ Hello everyone, count is: 2
67
+ Hello everyone, count is: 3
68
+ etc...
69
+ ```
66
70
67
- * [ microsoft azure virtual machines (vm) ] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/service-architectures/infrastructure-as-a-service/microsoft-azure-virtual-machines-cheat-sheet )
71
+ ## PREREQUISITES
68
72
69
- As a bonus, you can use Concourse CI to run the scripts ,
73
+ You will need the following go packages ,
70
74
71
- * [ concourse] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/continuous-integration-continuous-deployment/concourse-cheat-sheet )
72
- (Optional)
75
+ ``` bash
76
+ go get -u -v github.com/sirupsen/logrus
77
+ go get -u -v github.com/cweill/gotests/...
78
+ ```
73
79
74
- ## EXAMPLES
80
+ ## SOFTWARE STACK
75
81
76
- This repo may have a few examples. We will deploy example 1.
82
+ * DEVELOPMENT
83
+ * [ go] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/development/languages/go-cheat-sheet )
84
+ * OPERATIONS
85
+ * [ concourse/fly] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations/continuous-integration-continuous-deployment/concourse-cheat-sheet )
86
+ (optional)
87
+ * [ docker] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations/orchestration/builds-deployment-containers/docker-cheat-sheet )
88
+ * SERVICES
89
+ * [ dockerhub] ( https://hub.docker.com/ )
90
+ * microsoft azure vm
77
91
78
- ### EXAMPLE 1
92
+ ## RUN
79
93
80
- To run from the command line,
94
+ To
95
+ [ run.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/hello-go-deploy-azure-vm-code/run.sh ) ,
81
96
82
97
``` bash
98
+ cd hello-go-deploy-azure-vm-code
83
99
go run main.go
84
100
```
85
101
86
- Every 2 seconds ` hello-go-deploy-azure-vm ` will print:
102
+ To
103
+ [ create-binary.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/hello-go-deploy-azure-vm-code/bin/create-binary.sh ) ,
87
104
88
105
``` bash
89
- Hello everyone, count is: 1
90
- Hello everyone, count is: 2
91
- Hello everyone, count is: 3
92
- etc...
106
+ cd hello-go-deploy-azure-vm-code/bin
107
+ go build -o hello-go ../main.go
108
+ ./hello-go
93
109
```
94
110
111
+ This binary will not be used during a docker build
112
+ since it creates it's own.
113
+
95
114
## STEP 1 - TEST
96
115
97
- Lets unit test the code ,
116
+ To create unit ` _test ` files ,
98
117
99
118
``` bash
100
- go test -cover ./... | tee /test/test_coverage.txt
119
+ cd hello-go-deploy-azure-vm-code
120
+ gotests -w -all main.go
101
121
```
102
122
103
- There is a ` unit-tests.sh ` script to run the unit tests.
104
- There is also a script in the /ci folder to run the unit tests
105
- in concourse.
106
-
107
- ## STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)
108
-
109
- We will be using a multi-stage build using a Dockerfile.
110
- The end result will be a very small docker image around 13MB.
123
+ To run
124
+ [ unit-tests.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/hello-go-deploy-azure-vm-code/test/unit-tests.sh ) ,
111
125
112
126
``` bash
113
- docker build -f build-push/Dockerfile -t jeffdecola/hello-go-deploy-azure-vm .
127
+ go test -cover ./... | tee test/test_coverage.txt
128
+ cat test/test_coverage.txt
114
129
```
115
130
116
- Obviously, replace ` jeffdecola ` with your DockerHub username.
131
+ ## STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)
117
132
118
- In stage 1, rather than copy a binary into a docker image (because
119
- that can cause issue), the Dockerfile will build the binary in the
133
+ This docker image is built in two stages.
134
+ In ** stage 1** , rather than copy a binary into a docker image (because
135
+ that can cause issues), the Dockerfile will build the binary in the
120
136
docker image.
137
+ In ** stage 2** , the Dockerfile will copy this binary
138
+ and place it into a smaller docker image based
139
+ on ` alpine ` , which is around 13MB.
121
140
122
- If you open the DockerFile you can see it will get the dependencies and
123
- build the binary in go,
141
+ To
142
+ [ build.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/hello-go-deploy-azure-vm-code/build/build.sh )
143
+ with a
144
+ [ Dockerfile] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/hello-go-deploy-azure-vm-code/build/Dockerfile ) ,
124
145
125
146
``` bash
126
- FROM golang:alpine AS builder
127
- RUN go get -d -v
128
- RUN go build -o /go/bin/hello-go-deploy-azure-vm main.go
147
+ cd hello-go-deploy-azure-vm-code/build
148
+ docker build -f Dockerfile -t jeffdecola/hello-go-deploy-azure-vm .
129
149
```
130
150
131
- In stage 2, the Dockerfile will copy the binary created in
132
- stage 1 and place into a smaller docker base image based
133
- on ` alpine ` , which is around 13MB.
134
-
135
- You can check and test your docker image,
151
+ You can check and test this docker image,
136
152
137
153
``` bash
154
+ docker images jeffdecola/hello-go-deploy-azure-vm
138
155
docker run --name hello-go-deploy-azure-vm -dit jeffdecola/hello-go-deploy-azure-vm
139
156
docker exec -i -t hello-go-deploy-azure-vm /bin/bash
140
157
docker logs hello-go-deploy-azure-vm
141
- docker images jeffdecola/ hello-go-deploy-azure-vm:latest
158
+ docker rm -f hello-go-deploy-azure-vm
142
159
```
143
160
144
- There is a ` build-push.sh ` script to build and push to DockerHub.
145
- There is also a script in the /ci folder to build and push
146
- in concourse.
147
-
148
161
## STEP 3 - PUSH (TO DOCKERHUB)
149
162
150
- Lets push your docker image to DockerHub.
151
-
152
- If you are not logged in, you need to login to dockerhub,
163
+ You must be logged in to DockerHub,
153
164
154
165
``` bash
155
166
docker login
156
167
```
157
168
158
- Once logged in you can push to DockerHub
169
+ To
170
+ [ push.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/hello-go-deploy-azure-vm-code/push/push.sh ) ,
159
171
160
172
``` bash
161
173
docker push jeffdecola/hello-go-deploy-azure-vm
162
174
```
163
175
164
- Check you image at DockerHub. My image is located
165
- [ https://hub.docker.com/r/jeffdecola/hello-go-deploy-azure-vm ] ( https://hub.docker.com/r/jeffdecola/hello-go-deploy-azure-vm ) .
166
-
167
- There is a ` build-push.sh ` script to build and push to DockerHub.
168
- There is also a script in the /ci folder to build and push
169
- in concourse.
170
-
171
- ## STEP 4 - DEPLOY
172
-
173
- tbd
174
-
175
- ## TEST, BUILT, PUSH & DEPLOY USING CONCOURSE (OPTIONAL)
176
-
177
- For fun, I use concourse to automate the above steps.
178
-
179
- A pipeline file [ pipeline.yml] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/pipeline.yml )
180
- shows the entire ci flow. Visually, it looks like,
181
-
182
- ![ IMAGE - hello-go-deploy-azure-vm concourse ci pipeline - IMAGE] ( docs/pics/hello-go-deploy-azure-vm-pipeline.jpg )
183
-
184
- The ` jobs ` and ` tasks ` are,
176
+ Check the
177
+ [ hello-go-deploy-azure-vm docker image] ( https://hub.docker.com/r/jeffdecola/hello-go-deploy-azure-vm )
178
+ at DockerHub.
185
179
186
- * ` job-readme-github-pages ` runs task
187
- [ readme-github-pages.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/readme-github-pages.sh ) .
188
- * ` job-unit-tests ` runs task
189
- [ unit-tests.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/unit-tests.sh ) .
190
- * ` job-build-push ` runs task
191
- [ build-push.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/build-push.sh ) .
192
- * ` job-deploy ` runs task
193
- [ deploy.sh] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/deploy.sh ) .
180
+ ## STEP 4 - DEPLOY (TO AZURE VM)
194
181
195
- The concourse ` resources type ` are,
182
+ _ Coming soon. _
196
183
197
- * ` hello-go-deploy-azure-vm ` uses a resource type
198
- [ docker-image] ( https://hub.docker.com/r/concourse/git-resource/ )
199
- to PULL a repo from github.
200
- * ` resource-dump-to-dockerhub ` uses a resource type
201
- [ docker-image] ( https://hub.docker.com/r/concourse/docker-image-resource/ )
202
- to PUSH a docker image to dockerhub.
203
- * ` resource-marathon ` users a resource type
204
- [ docker-image] ( https://hub.docker.com/r/ckaznocha/marathon-resource )
205
- to DEPLOY the newly created docker image to marathon.
206
- * ` resource-slack-alert ` uses a resource type
207
- [ docker image] ( https://hub.docker.com/r/cfcommunity/slack-notification-resource )
208
- that will notify slack on your progress.
209
- * ` resource-repo-status ` uses a resource type
210
- [ docker image] ( https://hub.docker.com/r/dpb587/github-status-resource )
211
- that will update your git status for that particular commit.
184
+ ## CONTINUOUS INTEGRATION & DEPLOYMENT
212
185
213
- For more information on using concourse for continuous integration,
214
- refer to my cheat sheet on [ concourse] ( https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/continuous-integration-continuous-deployment/concourse-cheat-sheet ) .
186
+ Refer to
187
+ [ ci-README.md] ( https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci-README.md )
188
+ on how I automated the above steps using concourse.
0 commit comments