Skip to content

Commit c53b026

Browse files
committed
complete revamp of ci and README
1 parent 6451d57 commit c53b026

29 files changed

+840
-391
lines changed

.codeclimate.yml

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ plugins:
3535
# - <pattern>
3636
exclude_patterns:
3737
- "docs/"
38+
- "**/*_test.go"

.gitignore

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
# CONCOURSE
22
.credentials.yml
33

4+
# VSCODE
5+
.vscode/
6+
47
# GO
58
coverage.out
69

710
# macOS
811
.DS_Store
912

10-
# Ignore all binaries, but not build.sh
13+
# WINDOWS
14+
*.jpg:Zone.Identifier
15+
16+
# Ignore binaries
1117
**/bin/hello-go
1218

1319
# Ignore test coverage
1420
**/test/test_coverage.txt
1521

16-
# Ignore binary used for build
17-
**/build-push/hello-go
22+
# Ignore binary used for docker build
23+
**/build/hello-go
24+
25+
# SFTP VS CODE EXTENTION
26+
sftp.json

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Jeff DeCola
3+
Copyright (c) 2023 Jeff DeCola
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+81-107
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ Other Services
3636

3737
Table of Contents
3838

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)
4048

4149
Documentation and Reference
4250

@@ -48,167 +56,133 @@ Documentation and Reference
4856
_built with
4957
[concourse](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci-README.md)_
5058

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
5860

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,
6062

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+
```
6670

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
6872

69-
As a bonus, you can use Concourse CI to run the scripts,
73+
You will need the following go packages,
7074

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+
```
7379

74-
## EXAMPLES
80+
## SOFTWARE STACK
7581

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
7791

78-
### EXAMPLE 1
92+
## RUN
7993

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),
8196

8297
```bash
98+
cd hello-go-deploy-azure-vm-code
8399
go run main.go
84100
```
85101

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),
87104

88105
```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
93109
```
94110

111+
This binary will not be used during a docker build
112+
since it creates it's own.
113+
95114
## STEP 1 - TEST
96115

97-
Lets unit test the code,
116+
To create unit `_test` files,
98117

99118
```bash
100-
go test -cover ./... | tee /test/test_coverage.txt
119+
cd hello-go-deploy-azure-vm-code
120+
gotests -w -all main.go
101121
```
102122

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),
111125

112126
```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
114129
```
115130

116-
Obviously, replace `jeffdecola` with your DockerHub username.
131+
## STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)
117132

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
120136
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.
121140

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),
124145

125146
```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 .
129149
```
130150

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,
136152

137153
```bash
154+
docker images jeffdecola/hello-go-deploy-azure-vm
138155
docker run --name hello-go-deploy-azure-vm -dit jeffdecola/hello-go-deploy-azure-vm
139156
docker exec -i -t hello-go-deploy-azure-vm /bin/bash
140157
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
142159
```
143160

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-
148161
## STEP 3 - PUSH (TO DOCKERHUB)
149162

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,
153164

154165
```bash
155166
docker login
156167
```
157168

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),
159171

160172
```bash
161173
docker push jeffdecola/hello-go-deploy-azure-vm
162174
```
163175

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

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)
194181

195-
The concourse `resources type` are,
182+
_Coming soon._
196183

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
212185

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.

ci-README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# CONCOURSE CONTINUOUS INTEGRATION & DEPLOYMENT
2+
3+
I use concourse to automate,
4+
5+
* Use README for
6+
[GitHub Webpage](https://jeffdecola.github.io/hello-go-deploy-azure-vm/)
7+
* TEST code
8+
* BUILD docker image
9+
* PUSH to dockerhub
10+
* DEPLOY to azure vm
11+
* Alert me of the progress via repo status and slack
12+
13+
## PIPELINE
14+
15+
The concourse
16+
[pipeline.yml](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/pipeline.yml)
17+
shows the entire ci flow,
18+
19+
![IMAGE - hello-go-deploy-azure-vm concourse ci pipeline - IMAGE](docs/pics/hello-go-deploy-azure-vm-pipeline.jpg)
20+
21+
## JOBS, TASKS AND RESOURCE TYPES
22+
23+
Concourse Jobs and Tasks
24+
25+
* `job-readme-github-pages` runs task
26+
[task-readme-github-pages.yml](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/tasks/task-readme-github-pages.yml)
27+
that kicks off shell script
28+
[readme-github-pages.sh](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/scripts/readme-github-pages.sh)
29+
* `job-unit-tests` runs task
30+
[task-unit-tests.yml](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/tasks/task-unit-tests.yml)
31+
that kicks off shell script
32+
[unit-tests.sh](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/unit-tests.sh)
33+
* `job-build-push` runs task
34+
[task-build-push.yml](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/tasks/task-build-push.yml)
35+
that kicks off shell script
36+
[build-push.sh](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/build-push.sh)
37+
* `job-deploy` runs task
38+
[task-deploy.yml](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/blob/master/ci/tasks/task-deploy.yml)
39+
that kicks off shell script
40+
[deploy.sh](https://github.com/JeffDeCola/hello-go-deploy-azure-vm/tree/master/ci/scripts/deploy.sh)
41+
42+
Concourse Resources
43+
44+
* `hello-go-deploy-azure-vm` uses a resource type
45+
[docker image](https://hub.docker.com/r/concourse/git-resource/)
46+
to PULL a repo from github
47+
* `resource-dump-to-dockerhub` uses a resource type
48+
[docker image](https://hub.docker.com/r/concourse/docker-image-resource/)
49+
to PUSH a docker image to dockerhub
50+
* `resource-slack-alert` uses a resource type
51+
[docker image](https://hub.docker.com/r/cfcommunity/slack-notification-resource)
52+
that will notify slack on your progress
53+
* `resource-repo-status` uses a resource type
54+
[docker image](https://hub.docker.com/r/jeffdecola/github-status-resource-clone)
55+
that will update your git status for that particular commit

ci/destroy-pipeline.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# hello-go-deploy-azure-vm destroy-pipeline.sh
33

4-
fly -t ci destroy-pipeline --pipeline hello-go-deploy-azure-vm
4+
echo " "
5+
echo "Destroy pipeline on target jeffs-ci-target which is team jeffs-ci-team"
6+
fly --target jeffs-ci-target \
7+
destroy-pipeline \
8+
--pipeline hello-go-deploy-azure-vm
9+
echo " "

0 commit comments

Comments
 (0)