Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

πŸ“„ πŸ‡¬πŸ‡§ Build infrastructures in golang.

License

Notifications You must be signed in to change notification settings

gaocegege/infrastructure-in-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

infrastructure-in-golang

The goal of this project is to make the easiest, fastest, and most painless way of building your infrastructures with tools written in golang.

gogs
drone

TOC

Created by gh-md-toc

Technical Stack

  • Version Control System: Git
  • Source Code Management Tool: Gogs
  • Continuous Integration and Deployment Tool: Drone
  • Log Tracing Tool: OpenTracing

Setup

Pool Development Environment(Native + Docker)

In pool development environment, you don't have enough money to buy a server with public IP. You have to use some graceful hacks to build a devlopment environment.

$ source dev/env.sh && cd dev
$ docker-compose up

Gogs

# Get the IP from $(ifconfig).
GOGS_IP="docker0 IP"

Configuration in Gogs installation UI:

Database Settings

Host: mysql:3306
Password: gogsdafahao

Application General Settings

Domain: ${GOGS_IP}
SSH Port: 10022
HTTP Port: 10080
Application URL: http://${GOGS_IP}:10080/

URL: http://${GOGS_IP}:10080/

Drone

DRONE_IP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' dev_drone-server_1)

URL: http://${DRONE_IP}:8000/

Notice: Use the URL above, not http://localhost:8000/, not http://${GOGS_IP}:8000/. Because drone will create a webhook in gogs, and the URL used in the hook is this URL. We starts drone server in a docker container, so URL should be visited by gogs, and only http://${DRONE_IP}:8000/ meets the need. But if you are a rich man, public IP will solve this problem :)

OpenTracing

TODO

Rich Development Environment(Public IP + Docker)

You are not a poor man. You have money to buy a server with public IP, so things are easy to you.

# Get the IP from your cloud server vendor.
$ IP="Your Public IP"
$ source dev/env.sh && cd dev
$ docker-compose up

Gogs

Configuration in Gogs installation UI:

Database Settings

Host: mysql:3306
Password: gogsdafahao

Application General Settings

Domain: ${IP}
SSH Port: 10022
HTTP Port: 10080
Application URL: http://${IP}:10080/

URL: http://${IP}:10080/

Drone

URL: http://${IP}:8000/

OpenTracing

TODO

Awesome Development Environment(Docker Machine + Docker)

You know there is a tool docker-machine, which could give you a fixed internal IP. You could use it as a mock public IP. Then you could build a awesome development although you are a poor man.

$ cd dev/
# You need to install a hypervisor vendor such as virtualbox or kvm before you use docker machine.
$ docker-machine create --driver=<hypervisor vendor> awesome-dev
$ docker-machine ssh awesome-dev
# Get the IP of the machine via `docker-machine ls | grep awesome-dev`, usually 192.168.99.10X.
$ IP="Your awesome-dev machine IP"

Gogs

Configuration in Gogs installation UI:

Database Settings

Host: mysql:3306
Password: gogsdafahao

Application General Settings

Domain: ${IP}
SSH Port: 10022
HTTP Port: 10080
Application URL: http://${IP}:10080/

URL: http://${IP}:10080/

Drone

URL: http://${IP}:8000/

Poor Docker Swarm mode(Docker Machine + Docker Swarm Mode)

Again, you are a poor man but you want to use Docker Swarm mode to build your infrastructure in data center level, then you need docker-machine.

$ cd swarm-mode/
# You need to install a hypervisor vendor such as virtualbox or kvm before you use docker machine.
$ docker-machine create --driver=<hypervisor vendor> swarm-manager
$ docker-machine create --driver=<hypervisor vendor> swarm-worker-1
$ docker-machine ssh swarm-manager
# Get the IP of the machine via `docker-machine ls | grep swarm-manager`, usually 192.168.99.10X.
$ docker swarm init --advertise-addr <Manager IP>

Manager node will use port 2377 by default to communicate with worker nodes, then you need to configure the manager machine in virtualbox UI, to make sure port 2377 is exposed. You will get a bash statement if you successfully joins swarm as a manager, run the statement in worker machine:

$ docker-machine ssh swarm-worker-1
$ docker swarm join xxx <Manager IP>:2377

Congratulations, you have got a minor data center although you are poor :) Things goes easy now:

$ docker stack deploy --compose-file ./docker-compose.yml <a cool name>

Gogs

Configuration in Gogs installation UI:

Database Settings

Host: mysql:3306
Password: gogsdafahao

Application General Settings

Domain: ${Manager_IP}
SSH Port: 10022
HTTP Port: 10080
Application URL: http://${Manager_IP}:10080/

URL: http://${Manager_IP}:10080/

Drone

URL: http://${Manager_IP}:8000/

OpenTracing

TODO

Rich Docker Swarm mode(Docker Swarm Mode)

TODO(I have no money to do)

Docker Swarm Standalone(Docker Swarm)

TODO

Poor Kubernetes(minikube)

It is me.

First, you need to install the requirements for minikube..

Then minikube should be started:

$ cd kubernetes/
$ minikube start
$ MINIKUBE_IP=$(minikube ip)
$ kubectl create -f .

NOTICE: There are some performance bugs in this way: drone runs builds slowly. A simple "Hello, World" CI build spends drone 9mins. I don't know why now.

NAMESPACE NAME URL
default drone-server http://${MINIKUBE_IP}:30800
default gogs(ssh) http://${MINIKUBE_IP}:30022
default gogs(http) http://${MINIKUBE_IP}:30080
kube-system heapster http://${MINIKUBE_IP}:30082
kube-system kubernetes-dashboard http://${MINIKUBE_IP}:30000
kube-system monitoring-grafana http://${MINIKUBE_IP}:30088

Gogs

Configuration in Gogs installation UI:

Database Settings

Host: mysql:3306
Password: gogsdafahao

Application General Settings

Domain: ${MINIKUBE_IP}
SSH Port: 30022
HTTP Port: 30080
Application URL: http://${MINIKUBE_IP}:30080/

URL: http://${MINIKUBE_IP}:30080/

Drone

URL: http://${MINIKUBE_IP}:30800/

Remember to update the webhook, this URL isn't accepted by gogs, you should replace MINIKUBE_IP with drone-server in webhook settings.

Kubenetes Dashboard

URL: http://${MINIKUBE_IP}:30000/

Kubernetes Grafana

URL: http://${MINIKUBE_IP}:30088/

OpenTracing

TODO

About

πŸ“„ πŸ‡¬πŸ‡§ Build infrastructures in golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages