Skip to content

Commit

Permalink
major revamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff DeCola (TK1-PC Bash on Ubuntu on Windows) committed Dec 5, 2020
1 parent 619c027 commit f75e271
Show file tree
Hide file tree
Showing 35 changed files with 2,218 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# .codeclimate.yml

version: "2"
# prepare: Actions to perform before analysis begins
# fetch: Remote files to fetch (files are placed relative to the repo's root directory)
# url: url to fetch
# path: destination relative to repo's root directory

# checks: Configuration of maintainability checks
# <name>
# enabled: true|false
# config: check configuration

# plugins: Enable optional engines to run in addition to your analysis
# <name>
# enabled: true|false
# channel: alternate channel to use (stable is default)
# config: plugin configuration
plugins:
markdownlint:
enabled: true
shellcheck:
enabled: true
gofmt:
enabled: true
golint:
enabled: true
config:
min_confidence: 0.9
govet:
enabled: true

# exclude_patterns: Exclude files and/or directories from analysis
# - <pattern>
# - <pattern>
exclude_patterns:
- "docs/"
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CONCOURSE
.credentials.yml

# GO
coverage.out

# macOS
.DS_Store

# Ignore binaries
**/bin/crypto-wallet

# Ignore test coverage
**/test/test_coverage.txt

# Ignore binary used for docker build
**/build-push/crypto-wallet
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Jeff DeCola

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
233 changes: 233 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
# crypto-wallet-status

```text
*** THE REPO IS UNDER CONSTRUCTION - CHECK BACK SOON ***
```

[![Go Report Card](https://goreportcard.com/badge/github.com/JeffDeCola/crypto-wallet-status)](https://goreportcard.com/report/github.com/JeffDeCola/crypto-wallet-status)
[![GoDoc](https://godoc.org/github.com/JeffDeCola/crypto-wallet-status?status.svg)](https://godoc.org/github.com/JeffDeCola/crypto-wallet-status)
[![Maintainability](https://api.codeclimate.com/v1/badges/5ffc9029429ce278f688/maintainability)](https://codeclimate.com/github/JeffDeCola/crypto-wallet-status/maintainability)
[![Issue Count](https://codeclimate.com/github/JeffDeCola/crypto-wallet-status/badges/issue_count.svg)](https://codeclimate.com/github/JeffDeCola/crypto-wallet-status/issues)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://jeffdecola.mit-license.org)

_Check all your public cryptocurrency wallets via a webpage (iPhone App coming soon)._

Table of Contents,

* [PREREQUISITES](https://github.com/JeffDeCola/crypto-wallet-status#prerequisites)
* [GO PACKAGES](https://github.com/JeffDeCola/crypto-wallet-status#go-packages)
* [SOFTWARE STACK](https://github.com/JeffDeCola/crypto-wallet-status#software-stack)
* [RUN](https://github.com/JeffDeCola/crypto-wallet-status#run)
* [CREATE BINARY](https://github.com/JeffDeCola/crypto-wallet-status#create-binary)
* [OVERVIEW](https://github.com/JeffDeCola/crypto-wallet-status#overview)
* [STEP 1 - TEST](https://github.com/JeffDeCola/crypto-wallet-status#step-1---test)
* [STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)](https://github.com/JeffDeCola/crypto-wallet-status#step-2---build-docker-image-via-dockerfile)
* [STEP 3 - PUSH (TO DOCKERHUB)](https://github.com/JeffDeCola/crypto-wallet-status#step-3---push-to-dockerhub)
* [STEP 4 - DEPLOY (TO MARATHON)](https://github.com/JeffDeCola/crypto-wallet-status#step-4---deploy-to-marathon)
* [CONTINUOUS INTEGRATION & DEPLOYMENT](https://github.com/JeffDeCola/crypto-wallet-status#continuous-integration--deployment)

Documentation and references,

* The `crypto-wallet-status`
[Docker Image](https://hub.docker.com/r/jeffdecola/crypto-wallet-status)
on DockerHub

[GitHub Webpage](https://jeffdecola.github.io/crypto-wallet-status/)
_built with
[concourse ci](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci-README.md)_

## PREREQUISITES

I used the following language,

* [go](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/development/languages/go-cheat-sheet)

To build a docker image you will need docker on your machine,

* [docker](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/orchestration/builds-deployment-containers/docker-cheat-sheet)

To push a docker image you will need,

* [DockerHub account](https://hub.docker.com/)

To deploy to `mesos/marathon` you will need,

* [marathon](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/orchestration/cluster-managers-resource-management-scheduling/marathon-cheat-sheet)
* [mesos](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/orchestration/cluster-managers-resource-management-scheduling/mesos-cheat-sheet)

As a bonus, you can use Concourse CI,

* [concourse](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/continuous-integration-continuous-deployment/concourse-cheat-sheet)

## GO PACKAGES

You may need,

```bash
go get -u -v github.com/gorilla/mux
go get -u -v github.com/sirupsen/logrus
```

## SOFTWARE STACK

* **GUI**
_golang net/http package and ReactJS_
* **Routing & REST API framework**
_golang gorilla/mux package_
* **Backend**
_golang_
* **Database**
_N/A_

## RUN

The following steps are located in
[run.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/run.sh).

To run
[main.go](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/main.go)
from the command line,

```bash
cd code
go run main.go
```

Every 2 seconds it will print,

```bash
Hello everyone, count is: 1
Hello everyone, count is: 2
Hello everyone, count is: 3
etc...
```

## CREATE BINARY

If you want, you can create a binary, but this will not be used since
it is created during the docker image build.

The following steps are located in
[create-binary.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/bin/create-binary.sh).

```bash
cd code
go build -o bin/crypto-wallet main.go
cd bin
./crypto-wallet
```

## OVERVIEW

Here is an overview of what we're going to do,

![IMAGE - crypto-wallet-status-overview - IMAGE](docs/pics/crypto-wallet-status-overview.jpg)

## STEP 1 - TEST

The following steps are located in
[unit-tests.sh](https://github.com/JeffDeCola/crypto-wallet-status/tree/master/code/test/unit-tests.sh).

To unit test the code,

```bash
cd code
go test -cover ./... | tee test/test_coverage.txt
cat test/test_coverage.txt
```

To create `_test` files,

```bash
gotests -w -all main.go
```

## STEP 2 - BUILD (DOCKER IMAGE VIA DOCKERFILE)

The following steps are located in
[build.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/build-push/build.sh).

We will be using a multi-stage build using a
[Dockerfile](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/build-push/Dockerfile).
The end result will be a very small docker image around 13MB.

```bash
cd code
docker build -f build-push/Dockerfile -t jeffdecola/crypto-wallet-status .
```

You can check and test this docker image,

```bash
docker images jeffdecola/crypto-wallet-status:latest
docker run --name crypto-wallet-status -dit jeffdecola/crypto-wallet-status
docker exec -i -t crypto-wallet-status /bin/bash
docker logs crypto-wallet-status
```

### Stage 1

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,

```bash
FROM golang:alpine AS builder
RUN go get -d -v
RUN go build -o /go/bin/crypto-wallet-status main.go
```

### Stage 2

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.

## STEP 3 - PUSH (TO DOCKERHUB)

The following steps are located in
[push.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/build-push/push.sh).

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

```bash
docker login
```

Once logged in you can push to DockerHub,

```bash
docker push jeffdecola/crypto-wallet-status
```

Check the
[crypto-wallet-status](https://hub.docker.com/r/jeffdecola/crypto-wallet-status)
docker image at DockerHub.

## STEP 4 - DEPLOY (TO MARATHON)

The following steps are located in
[deploy.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/deploy-marathon/deploy.sh).

Pull the `crypto-wallet-status` docker image
from DockerHub and deploy to mesos/marathon.

This is actually very simple, you just PUT the
[app.json](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/code/deploy-marathon/app.json)
file to mesos/marathon. This .json file tells marathon what to do.

```bash
cd deploy-marathon
curl -X PUT http://192.168.20.117:8080/v2/apps/crypto-wallet-long-running \
-d @app.json \
-H "Content-type: application/json"
```

## CONTINUOUS INTEGRATION & DEPLOYMENT

Refer to
[ci-README.md](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci-README.md)
for how I automated the above process.
62 changes: 62 additions & 0 deletions ci-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# CONCOURSE CONTINUOUS INTEGRATION

I use concourse ci to,

* Copy and edit `README.md` to `/docs/_includes/README.md` for
[GitHub Webpage](https://jeffdecola.github.io/crypto-wallet-status/)
* TEST code
* BUILD docker image
* PUSH to dockerhub
* DEPLOY to marathon
* Alert me of the progress via repo status and slack

## PIPELINE

The concourse
[pipeline.yml](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/pipeline.yml)
shows the entire ci flow. Visually, it looks like,

![IMAGE - crypto-wallet-status concourse ci pipeline - IMAGE](docs/pics/crypto-wallet-status-pipeline.jpg)

## JOBS, TASKS AND RESOURCE TYPES

The concourse `jobs` and `tasks` are,

* `job-readme-github-pages` runs task
[task-readme-github-pages.yml](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/tasks/task-readme-github-pages.yml)
that kicks off shell script
[readme-github-pages.sh](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/scripts/readme-github-pages.sh)
* `job-unit-tests` runs task
[task-unit-tests.yml](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/tasks/task-unit-tests.yml)
that kicks off shell script
[unit-tests.sh](https://github.com/JeffDeCola/crypto-wallet-status/tree/master/ci/scripts/unit-tests.sh)
* `job-build-push` runs task
[task-build-push.yml](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/tasks/task-build-push.yml)
that kicks off shell script
[build-push.sh](https://github.com/JeffDeCola/crypto-wallet-status/tree/master/ci/scripts/build-push.sh)
* `job-deploy` runs task
[task-deploy.yml](https://github.com/JeffDeCola/crypto-wallet-status/blob/master/ci/tasks/task-deploy.yml)
that kicks off shell script
[deploy.sh](https://github.com/JeffDeCola/crypto-wallet-status/tree/master/ci/scripts/deploy.sh)

The concourse `resources types` are,

* `crypto-wallet-status` uses a resource type
[docker-image](https://hub.docker.com/r/concourse/git-resource/)
to PULL a repo from github
* `resource-dump-to-dockerhub` uses a resource type
[docker-image](https://hub.docker.com/r/concourse/docker-image-resource/)
to PUSH a docker image to dockerhub.
* `resource-marathon` users a resource type
[docker-image](https://hub.docker.com/r/ckaznocha/marathon-resource)
to DEPLOY the newly created docker image to marathon.
* `resource-slack-alert` uses a resource type
[docker image](https://hub.docker.com/r/cfcommunity/slack-notification-resource)
that will notify slack on your progress
* `resource-repo-status` uses a resource type
[docker image](https://hub.docker.com/r/dpb587/github-status-resource)
that will update your git status for that particular commit

For more information on using concourse for continuous integration,
refer to my
[concourse-cheat-sheet](https://github.com/JeffDeCola/my-cheat-sheets/tree/master/software/operations-tools/continuous-integration-continuous-deployment/concourse-cheat-sheet).
4 changes: 4 additions & 0 deletions ci/destroy-pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# crypto-wallet-status destroy-pipeline.sh

fly -t ci destroy-pipeline --pipeline crypto-wallet-status
Loading

0 comments on commit f75e271

Please sign in to comment.